diff --git a/Problem.cpp b/Problem.cpp index b652bd6..e6c9d13 100644 --- a/Problem.cpp +++ b/Problem.cpp @@ -1,6 +1,7 @@ #include "Problem.h" #include +#include bool Problem::seeded = false; @@ -13,6 +14,7 @@ Problem::Problem(PROBLEM_TYPE type, unsigned short max_digits, unsigned win_x, u { // srand(time()); srand(0); + setlocale(LC_NUMERIC, ""); // apostrophe to enable thousands separator in printf statements. seeded = true; } @@ -34,23 +36,25 @@ void Problem::Draw(bool selected) // Draw the window: if(selected) - box(win, 0, 0); + box(win, '?', '?'); else box(win, 0, 0); // 0, 0 gives default characters for the vertical and horizontal lines - mvwprintw(win, 1, 2, "%5d", number_top); - mvwprintw(win, 2, 2, "%5d", number_bottom); + mvwprintw(win, 2, 4, "%'6d", number_top); + mvwprintw(win, 3, 4, "%'6d", number_bottom); switch(problem_type) { case EASY_ADDITION: case HARD_ADDITION: - mvwprintw(win, 2, 1, "+"); + mvwprintw(win, 3, 2, "+"); break; case EASY_SUBTRACTION: case HARD_SUBTRACTION: - mvwprintw(win, 2, 1, "-"); + mvwprintw(win, 3, 2, "-"); break; }; + mvwprintw(win, 4, 2, "========"); + mvwprintw(win, 5, 9, ""); wrefresh(win); } diff --git a/main.cpp b/main.cpp index 302a6f1..af65c4c 100644 --- a/main.cpp +++ b/main.cpp @@ -8,6 +8,8 @@ #include "Problem.h" +#include + #define PROMPT " > " char MainMenu() @@ -53,29 +55,42 @@ int main(int argc, char *argv[]) else continue; // restart loop - Problem *test = nullptr; - if(addition != subtraction) + clear(); + wrefresh(stdscr); + + std::vector problems; + for(auto y = 1; y < LINES - 10; y += 9) { - if(addition) - test = new Problem(EASY_ADDITION, 3, 3, 12); - if(subtraction) - test = new Problem(EASY_SUBTRACTION, 3, 3, 12); - } - if(addition && subtraction) - { - if(rand() % 2) - test = new Problem(HARD_ADDITION, 5, 3, 12); - else - test = new Problem(HARD_SUBTRACTION, 5, 3, 12); + for(auto x = 2; x < COLS - 16; x += 15) + { + Problem *test = nullptr; + if(addition != subtraction) + { + if(addition) + test = new Problem(EASY_ADDITION, 3, x, y); + if(subtraction) + test = new Problem(EASY_SUBTRACTION, 3, x, y); + } + if(addition && subtraction) + { + if(rand() % 2) + test = new Problem(HARD_ADDITION, 5, x, y); + else + test = new Problem(HARD_SUBTRACTION, 5, x, y); + } + problems.push_back(test); + } } - if(test) - test->Draw(true); + for(auto *problem : problems) + if(problem) + problem->Draw(false); getch(); - if(test) - delete test; + for(auto *problem : problems) + if(problem) + delete problem; } endwin();