2019-03-31 18:40:37 -04:00
|
|
|
// 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 <ncurses.h>
|
|
|
|
|
|
|
|
#include "Problem.h"
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
Problem *test = nullptr;
|
2019-04-01 09:08:41 -04:00
|
|
|
if(addition != subtraction)
|
|
|
|
{
|
|
|
|
if(addition)
|
|
|
|
test = new Problem(EASY_ADDITION, 3, 3, 12);
|
|
|
|
if(subtraction)
|
|
|
|
test = new Problem(EASY_SUBTRACTION, 3, 3, 12);
|
|
|
|
}
|
|
|
|
if(addition && subtraction)
|
2019-03-31 18:40:37 -04:00
|
|
|
{
|
|
|
|
if(rand() % 2)
|
|
|
|
test = new Problem(HARD_ADDITION, 5, 3, 12);
|
|
|
|
else
|
|
|
|
test = new Problem(HARD_SUBTRACTION, 5, 3, 12);
|
|
|
|
}
|
|
|
|
|
2019-04-01 09:08:41 -04:00
|
|
|
if(test)
|
|
|
|
test->Draw(true);
|
|
|
|
|
2019-03-31 18:40:37 -04:00
|
|
|
getch();
|
|
|
|
|
|
|
|
if(test)
|
|
|
|
delete test;
|
|
|
|
}
|
|
|
|
|
|
|
|
endwin();
|
|
|
|
return 0;
|
|
|
|
}
|