mirror of
https://github.com/krislamo/Trololo
synced 2024-11-10 00:30:35 +00:00
Function MainMenu_survey() fixed logically
Debugging showed that MainMenu_survey() in the core.cpp file under scrns had issues. They are fixed and can be verified by uncommenting lines with //debugline at the end. Rendering for the MainMenu is not yet implemented.
This commit is contained in:
parent
27773ae391
commit
58c3b4e4f2
45
core.cpp
45
core.cpp
@ -250,21 +250,24 @@ namespace scrns
|
||||
int MainMenu_survey()
|
||||
{
|
||||
// Return values
|
||||
// 0 -- User wants to quit
|
||||
// 1 -- User wants option 1
|
||||
// 2 -- User wants option 2
|
||||
// -1 -- No input
|
||||
// 1 -- User wants option 1 (start new game)
|
||||
// 2 -- User wants to quit
|
||||
|
||||
SDL_Event event;
|
||||
int current, menu_option;
|
||||
|
||||
int menu_option, current;
|
||||
menu_option = current = 1;
|
||||
|
||||
bool option_wanted = false;
|
||||
|
||||
current = menu_option = 1;
|
||||
|
||||
while(!option_wanted)
|
||||
{
|
||||
while(SDL_PollEvent(&event))
|
||||
{
|
||||
|
||||
if(event.type == SDL_QUIT)
|
||||
return 0;
|
||||
return 2;
|
||||
|
||||
else if(event.type == SDL_KEYDOWN)
|
||||
{
|
||||
@ -274,7 +277,7 @@ namespace scrns
|
||||
if(menu_option < 2) // Less than the max amount of options
|
||||
menu_option++;
|
||||
|
||||
cout << "Down Key, menu_option: " << menu_option << endl;
|
||||
//cout << "INPUT ::: DOWN KEY, menu_option: " << menu_option << "; current: " << current << endl; // debugline
|
||||
}
|
||||
|
||||
else if(event.key.keysym.sym == 273) // up arrow key
|
||||
@ -282,7 +285,7 @@ namespace scrns
|
||||
if(menu_option > 1)
|
||||
menu_option--;
|
||||
|
||||
cout << "Up Key, menu_option: " << menu_option << endl; // debugline
|
||||
//cout << "INPUT ::: UP KEY, menu_option: " << menu_option << "; current: " << current << endl; // debugline
|
||||
}
|
||||
|
||||
else if(event.key.keysym.sym == 13) // enter key
|
||||
@ -293,28 +296,26 @@ namespace scrns
|
||||
|
||||
if(menu_option != current)
|
||||
{
|
||||
current = menu_option;
|
||||
|
||||
switch(menu_option)
|
||||
{
|
||||
case 1:
|
||||
cout << "Case 1 ::: Menu should change to: " << menu_option << endl; // debugline
|
||||
//cout << "Case 1 ::: Menu should change. menu_option: " << menu_option << "; current: " << current << endl; // debugline
|
||||
break;
|
||||
case 2:
|
||||
cout << "Case 2 ::: Menu should change to: " << menu_option << endl; // debugline
|
||||
//cout << "Case 2 ::: Menu should change. menu_option: " << menu_option << "; current: " << current << endl; // debugline
|
||||
break;
|
||||
default:
|
||||
cout << "Error: MainMenu_survey didn't update correctly." << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
current = menu_option;
|
||||
}
|
||||
|
||||
else if(option_wanted)
|
||||
return menu_option;
|
||||
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
19
main.cpp
19
main.cpp
@ -5,18 +5,27 @@ using namespace std;
|
||||
int main(int argc, char* args[])
|
||||
{
|
||||
SDL_Surface *screen;
|
||||
int menu_option = -1;
|
||||
|
||||
// Display main menu
|
||||
screen = scrns::MainMenu();
|
||||
|
||||
while(menu_option == -1)
|
||||
{
|
||||
// Main menu option return
|
||||
int menu_option;
|
||||
|
||||
menu_option = scrns::MainMenu_survey();
|
||||
|
||||
if(menu_option == 1)
|
||||
switch(menu_option)
|
||||
{
|
||||
case 1:
|
||||
// User wants to start a new game
|
||||
cout << "Starting new game..." << endl;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
// User wants to exit the game
|
||||
break;
|
||||
default:
|
||||
cout << "Fatal Error: Main Menu option given was unknown." << endl;
|
||||
|
||||
}
|
||||
|
||||
SDL_FreeSurface(screen);
|
||||
|
Loading…
Reference in New Issue
Block a user