// TODO(dev): use 'halfdelay()' to parse input for pi menu choice 'secret.' // NOTE(dev): Gonna need this: // mvwprintw(win, y, x, string); /* Move to (y, x) relative to window */ // /* co-ordinates and then print */ #include #include "Problem.h" #include #define PROMPT " > " char MainMenu() { clear(); printw("\n"); printw(" Welcome to Math Practice.\n"); printw(" Please choose from the following menu:\n"); printw(" 1. Addition\n"); printw(" 2. Subtraction\n"); printw(" 3. Both / Mixed\n"); printw(" q. Quit\n"); printw("\n"); printw(PROMPT); refresh(); return getch(); } int main(int argc, char *argv[]) { initscr(); noecho(); // don't show user input cbreak(); // handle user input immediately (i.e. don't wait for the user to press enter) keypad(stdscr, true); // enable the numpad, F1-F12 keys, arrow keys, etc. while(true) { // game boolean flags: bool addition = false; bool subtraction = false; // Main Menu: char menu_action = MainMenu(); if(menu_action == 'q') break; else if(menu_action == '1') addition = true; else if(menu_action == '2') subtraction = true; else if(menu_action == '3') addition = subtraction = true; else continue; // restart loop clear(); wrefresh(stdscr); std::vector problems; for(auto y = 1; y < LINES - 10; y += 9) { 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); } } for(auto *problem : problems) if(problem) problem->Draw(false); getch(); for(auto *problem : problems) if(problem) delete problem; } endwin(); return 0; }