Fixed number generation bugs. Added simple draw code that needs to be styled, yet.
This commit is contained in:
		
							
								
								
									
										46
									
								
								Problem.cpp
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								Problem.cpp
									
									
									
									
									
								
							@@ -29,13 +29,37 @@ Problem::~Problem()
 | 
			
		||||
 | 
			
		||||
void Problem::Draw(bool selected)
 | 
			
		||||
{
 | 
			
		||||
	
 | 
			
		||||
	if(!win)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	// Draw the window:
 | 
			
		||||
	if(selected)
 | 
			
		||||
		box(win, 0, 0);
 | 
			
		||||
	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);
 | 
			
		||||
	switch(problem_type)
 | 
			
		||||
	{
 | 
			
		||||
	case EASY_ADDITION:
 | 
			
		||||
	case HARD_ADDITION:
 | 
			
		||||
		mvwprintw(win, 2, 1, "+");
 | 
			
		||||
		break;
 | 
			
		||||
	case EASY_SUBTRACTION:
 | 
			
		||||
	case HARD_SUBTRACTION:
 | 
			
		||||
		mvwprintw(win, 2, 1, "-");
 | 
			
		||||
		break;
 | 
			
		||||
	};
 | 
			
		||||
	wrefresh(win);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Problem::GenerateNumbers(PROBLEM_TYPE type, unsigned short max_digits)
 | 
			
		||||
{
 | 
			
		||||
	// Determine how many digits long these numbers should be:
 | 
			
		||||
	unsigned short digits = rand() % (max_digits - 1) + 1; // at least one digit
 | 
			
		||||
	unsigned short digits = rand() % (max_digits) + 1; // at least one digit
 | 
			
		||||
	number_top = 0;
 | 
			
		||||
	number_bottom = 0;
 | 
			
		||||
 | 
			
		||||
	switch(problem_type)
 | 
			
		||||
	{
 | 
			
		||||
@@ -44,7 +68,11 @@ void Problem::GenerateNumbers(PROBLEM_TYPE type, unsigned short max_digits)
 | 
			
		||||
		for(auto digit = 0; digit < digits; ++digit)
 | 
			
		||||
		{
 | 
			
		||||
			unsigned short temp_number_top = rand() % 10;
 | 
			
		||||
			unsigned short temp_number_bottom = rand() % (10 - number_top);
 | 
			
		||||
			unsigned short temp_number_bottom;
 | 
			
		||||
			if(temp_number_top == 9)
 | 
			
		||||
				temp_number_bottom = 0;
 | 
			
		||||
			else
 | 
			
		||||
				temp_number_bottom = rand() % (10 - temp_number_top);
 | 
			
		||||
 | 
			
		||||
			// Place into correct digit posititon:
 | 
			
		||||
			number_top += temp_number_top * (pow(10, digit));
 | 
			
		||||
@@ -90,7 +118,12 @@ void Problem::GenerateNumbers(PROBLEM_TYPE type, unsigned short max_digits)
 | 
			
		||||
		}
 | 
			
		||||
		// NOTE(dev): don't allow negative numbers:
 | 
			
		||||
		if(number_bottom > number_top)
 | 
			
		||||
			number_bottom %= number_top;
 | 
			
		||||
		{
 | 
			
		||||
			if(number_top)
 | 
			
		||||
				number_bottom %= number_top;
 | 
			
		||||
			else
 | 
			
		||||
				number_bottom = 0; // lol, 0 - 0 is hard?
 | 
			
		||||
		}
 | 
			
		||||
		break;
 | 
			
		||||
	};
 | 
			
		||||
}
 | 
			
		||||
@@ -114,9 +147,4 @@ void Problem::GenerateWindow(unsigned win_x, unsigned win_y)
 | 
			
		||||
	win = newwin(height, width, win_y, win_x);
 | 
			
		||||
	if(!win)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	// Draw the window:
 | 
			
		||||
	box(win, 0, 0); // 0, 0 gives default characters for the vertical and horizontal lines
 | 
			
		||||
	mvwprintw(win, 1, 1, "TEST");
 | 
			
		||||
	wrefresh(win);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										16
									
								
								main.cpp
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								main.cpp
									
									
									
									
									
								
							@@ -54,11 +54,14 @@ int main(int argc, char *argv[])
 | 
			
		||||
			continue; // restart loop
 | 
			
		||||
 | 
			
		||||
		Problem *test = nullptr;
 | 
			
		||||
		if(addition)
 | 
			
		||||
			test = new Problem(EASY_ADDITION, 3, 3, 12);
 | 
			
		||||
		if(subtraction)
 | 
			
		||||
			test = new Problem(EASY_SUBTRACTION, 3, 3, 12);
 | 
			
		||||
		if(addition && subtraction)
 | 
			
		||||
		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)
 | 
			
		||||
		{
 | 
			
		||||
			if(rand() % 2)
 | 
			
		||||
				test = new Problem(HARD_ADDITION, 5, 3, 12);
 | 
			
		||||
@@ -66,6 +69,9 @@ int main(int argc, char *argv[])
 | 
			
		||||
				test = new Problem(HARD_SUBTRACTION, 5, 3, 12);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if(test)
 | 
			
		||||
			test->Draw(true);
 | 
			
		||||
 | 
			
		||||
		getch();
 | 
			
		||||
 | 
			
		||||
		if(test)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user