This commit is contained in:
David Vereb 2019-04-04 06:51:04 -05:00
parent 0d10729b37
commit 2d0e74d0de
2 changed files with 22 additions and 14 deletions

View File

@ -40,9 +40,9 @@ void Problem::Draw(bool selected, const INPUT_STYLE &input_style)
// Draw the window:
if(selected)
box(win, 0, 0); // 0, 0 gives default characters for the vertical and horizontal lines
// else
// box(win, ' ', ' ');
box(win, '*', '*'); // 0, 0 gives default characters for the vertical and horizontal lines
else
wborder(win, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
mvwprintw(win, 2, 4, "%'6d", number_top);
mvwprintw(win, 3, 4, "%'6d", number_bottom);
@ -58,7 +58,10 @@ void Problem::Draw(bool selected, const INPUT_STYLE &input_style)
break;
};
mvwprintw(win, 4, 2, "========");
mvwprintw(win, 5, 4, "%'6d", Input());
if(Input() > 999999)
mvwprintw(win, 5, 3, " FAILED");
else if(Input() != 0)
mvwprintw(win, 5, 3, "%'7d", Input());
// Place the cursor in the correct position!
int length = input.length() + ((input.length() - 1) / 3); // add commas, too!
@ -166,6 +169,8 @@ int Problem::Input() const
void Problem::Input(const INPUT_STYLE input_style, char character)
{
if(input.length() > 6)
return;
// TODO(dev): ASSERT
if(character < '0' || character > '9')
exit(-1);

View File

@ -86,7 +86,7 @@ int main(int argc, char *argv[])
if(current_problem->Correct())
++selected;
current_problem->Draw(true, input_style); // refresh with new input
current_problem->Draw(current_problem == *selected, input_style); // refresh with new input
}
for(auto *problem : problems)
@ -100,16 +100,19 @@ int main(int argc, char *argv[])
char MainMenu()
{
int middle_h = COLS / 2;
int middle_v = LINES / 2;
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);
mvprintw(middle_v - 5, middle_h - 20, "\n");
mvprintw(middle_v - 4, middle_h - 20, " Welcome to Math Practice.\n");
mvprintw(middle_v - 3, middle_h - 20, " Please choose from the following menu:\n");
mvprintw(middle_v - 2, middle_h - 20, " 1. Addition\n");
mvprintw(middle_v - 1, middle_h - 20, " 2. Subtraction\n");
mvprintw(middle_v + 0, middle_h - 20, " 3. Both / Mixed\n");
mvprintw(middle_v + 1, middle_h - 20, " q. Quit\n");
mvprintw(middle_v + 2, middle_h - 20, "\n");
mvprintw(middle_v + 3, middle_h - 20, PROMPT);
refresh();
return getch();