Added multiple problems per screen. Added highlighted drawing code for selected problem.
This commit is contained in:
parent
39fa40eaad
commit
5ab9e9c5f3
14
Problem.cpp
14
Problem.cpp
@ -1,6 +1,7 @@
|
|||||||
#include "Problem.h"
|
#include "Problem.h"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
bool Problem::seeded = false;
|
bool Problem::seeded = false;
|
||||||
|
|
||||||
@ -13,6 +14,7 @@ Problem::Problem(PROBLEM_TYPE type, unsigned short max_digits, unsigned win_x, u
|
|||||||
{
|
{
|
||||||
// srand(time());
|
// srand(time());
|
||||||
srand(0);
|
srand(0);
|
||||||
|
setlocale(LC_NUMERIC, ""); // apostrophe to enable thousands separator in printf statements.
|
||||||
seeded = true;
|
seeded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,23 +36,25 @@ void Problem::Draw(bool selected)
|
|||||||
|
|
||||||
// Draw the window:
|
// Draw the window:
|
||||||
if(selected)
|
if(selected)
|
||||||
box(win, 0, 0);
|
box(win, '?', '?');
|
||||||
else
|
else
|
||||||
box(win, 0, 0); // 0, 0 gives default characters for the vertical and horizontal lines
|
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, 4, "%'6d", number_top);
|
||||||
mvwprintw(win, 2, 2, "%5d", number_bottom);
|
mvwprintw(win, 3, 4, "%'6d", number_bottom);
|
||||||
switch(problem_type)
|
switch(problem_type)
|
||||||
{
|
{
|
||||||
case EASY_ADDITION:
|
case EASY_ADDITION:
|
||||||
case HARD_ADDITION:
|
case HARD_ADDITION:
|
||||||
mvwprintw(win, 2, 1, "+");
|
mvwprintw(win, 3, 2, "+");
|
||||||
break;
|
break;
|
||||||
case EASY_SUBTRACTION:
|
case EASY_SUBTRACTION:
|
||||||
case HARD_SUBTRACTION:
|
case HARD_SUBTRACTION:
|
||||||
mvwprintw(win, 2, 1, "-");
|
mvwprintw(win, 3, 2, "-");
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
mvwprintw(win, 4, 2, "========");
|
||||||
|
mvwprintw(win, 5, 9, "");
|
||||||
wrefresh(win);
|
wrefresh(win);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
49
main.cpp
49
main.cpp
@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
#include "Problem.h"
|
#include "Problem.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#define PROMPT " > "
|
#define PROMPT " > "
|
||||||
|
|
||||||
char MainMenu()
|
char MainMenu()
|
||||||
@ -53,29 +55,42 @@ int main(int argc, char *argv[])
|
|||||||
else
|
else
|
||||||
continue; // restart loop
|
continue; // restart loop
|
||||||
|
|
||||||
Problem *test = nullptr;
|
clear();
|
||||||
if(addition != subtraction)
|
wrefresh(stdscr);
|
||||||
|
|
||||||
|
std::vector<Problem*> problems;
|
||||||
|
for(auto y = 1; y < LINES - 10; y += 9)
|
||||||
{
|
{
|
||||||
if(addition)
|
for(auto x = 2; x < COLS - 16; x += 15)
|
||||||
test = new Problem(EASY_ADDITION, 3, 3, 12);
|
{
|
||||||
if(subtraction)
|
Problem *test = nullptr;
|
||||||
test = new Problem(EASY_SUBTRACTION, 3, 3, 12);
|
if(addition != subtraction)
|
||||||
}
|
{
|
||||||
if(addition && subtraction)
|
if(addition)
|
||||||
{
|
test = new Problem(EASY_ADDITION, 3, x, y);
|
||||||
if(rand() % 2)
|
if(subtraction)
|
||||||
test = new Problem(HARD_ADDITION, 5, 3, 12);
|
test = new Problem(EASY_SUBTRACTION, 3, x, y);
|
||||||
else
|
}
|
||||||
test = new Problem(HARD_SUBTRACTION, 5, 3, 12);
|
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)
|
for(auto *problem : problems)
|
||||||
test->Draw(true);
|
if(problem)
|
||||||
|
problem->Draw(false);
|
||||||
|
|
||||||
getch();
|
getch();
|
||||||
|
|
||||||
if(test)
|
for(auto *problem : problems)
|
||||||
delete test;
|
if(problem)
|
||||||
|
delete problem;
|
||||||
}
|
}
|
||||||
|
|
||||||
endwin();
|
endwin();
|
||||||
|
Loading…
Reference in New Issue
Block a user