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()
|
int MainMenu_survey()
|
||||||
{
|
{
|
||||||
// Return values
|
// Return values
|
||||||
// 0 -- User wants to quit
|
// 1 -- User wants option 1 (start new game)
|
||||||
// 1 -- User wants option 1
|
// 2 -- User wants to quit
|
||||||
// 2 -- User wants option 2
|
|
||||||
// -1 -- No input
|
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
int current, menu_option;
|
|
||||||
|
int menu_option, current;
|
||||||
|
menu_option = current = 1;
|
||||||
|
|
||||||
bool option_wanted = false;
|
bool option_wanted = false;
|
||||||
|
|
||||||
current = menu_option = 1;
|
|
||||||
|
|
||||||
|
while(!option_wanted)
|
||||||
|
{
|
||||||
while(SDL_PollEvent(&event))
|
while(SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
|
|
||||||
if(event.type == SDL_QUIT)
|
if(event.type == SDL_QUIT)
|
||||||
return 0;
|
return 2;
|
||||||
|
|
||||||
else if(event.type == SDL_KEYDOWN)
|
else if(event.type == SDL_KEYDOWN)
|
||||||
{
|
{
|
||||||
@ -274,7 +277,7 @@ namespace scrns
|
|||||||
if(menu_option < 2) // Less than the max amount of options
|
if(menu_option < 2) // Less than the max amount of options
|
||||||
menu_option++;
|
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
|
else if(event.key.keysym.sym == 273) // up arrow key
|
||||||
@ -282,7 +285,7 @@ namespace scrns
|
|||||||
if(menu_option > 1)
|
if(menu_option > 1)
|
||||||
menu_option--;
|
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
|
else if(event.key.keysym.sym == 13) // enter key
|
||||||
@ -293,28 +296,26 @@ namespace scrns
|
|||||||
|
|
||||||
if(menu_option != current)
|
if(menu_option != current)
|
||||||
{
|
{
|
||||||
|
current = menu_option;
|
||||||
|
|
||||||
switch(menu_option)
|
switch(menu_option)
|
||||||
{
|
{
|
||||||
case 1:
|
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:
|
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 menu_option;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
19
main.cpp
19
main.cpp
@ -5,18 +5,27 @@ using namespace std;
|
|||||||
int main(int argc, char* args[])
|
int main(int argc, char* args[])
|
||||||
{
|
{
|
||||||
SDL_Surface *screen;
|
SDL_Surface *screen;
|
||||||
int menu_option = -1;
|
|
||||||
|
|
||||||
|
// Display main menu
|
||||||
screen = scrns::MainMenu();
|
screen = scrns::MainMenu();
|
||||||
|
|
||||||
while(menu_option == -1)
|
// Main menu option return
|
||||||
{
|
int menu_option;
|
||||||
|
|
||||||
menu_option = scrns::MainMenu_survey();
|
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;
|
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);
|
SDL_FreeSurface(screen);
|
||||||
|
Loading…
Reference in New Issue
Block a user