Added multiple problems per screen. Added highlighted drawing code for selected problem.
This commit is contained in:
		
							
								
								
									
										14
									
								
								Problem.cpp
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								Problem.cpp
									
									
									
									
									
								
							@@ -1,6 +1,7 @@
 | 
			
		||||
#include "Problem.h"
 | 
			
		||||
 | 
			
		||||
#include <cmath>
 | 
			
		||||
#include <locale.h>
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										49
									
								
								main.cpp
									
									
									
									
									
								
							
							
						
						
									
										49
									
								
								main.cpp
									
									
									
									
									
								
							@@ -8,6 +8,8 @@
 | 
			
		||||
 | 
			
		||||
#include "Problem.h"
 | 
			
		||||
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#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<Problem*> 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();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user