Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Menu::showOptions( int& option, string option1, string option2)
- {
- if(option1 != "Start Game" || option2 != "Close Game")
- {
- say.clearScreen();
- }
- option = (option > 2) ? (option - 2) : ((option < 1) ? option + 2 : option);
- if (option == 1)
- {
- say.communique(" >> " + option1 + " << ");
- say.communique(" " + option2 + " ");
- }
- else if (option == 2)
- {
- say.communique(" " + option1 + " ");
- say.communique(" >> " + option2 + " << ");
- }
- }
- void Menu::arrowSupport(int& option, string option1, string option2)
- {
- char choice = ' ';
- listen.charInput(choice);
- switch (choice)
- {
- case 72:
- case 80:
- option = (choice == 72) ? --option : ((choice == 80) ? ++option : option);
- showOptions(option, option1, option2);
- default:
- break;
- }
- }
- /**
- * @param int& state: 0 - startScreen(), 1 - mainMenu(), 2 - mapSelection(), 3 - showScore(), 4 - mapEnd()
- */
- void Menu::mainSelection(int& state, string firstOption, string secondOption)
- {
- string name;
- int option = 1;
- char choice = 'w';
- if (state == 0)
- {
- title();
- }
- showOptions(option, firstOption, secondOption);
- bool condition = true, insideCondition = true, showCondition = true;
- while (condition)
- {
- if (listen.isEmpty())
- {
- listen.charInput(choice);
- if (static_cast <int>(choice) == -32)
- {
- if (state == 0)
- {
- title();
- }
- arrowSupport(option, firstOption, secondOption);
- }
- else
- {
- switch (choice)
- {
- case 'w':
- case 'W':
- option--;
- if (state == 0)
- {
- title();
- }
- else if (state == 4)
- {
- choice = showCondition ? 'w' : 27;
- }
- showOptions(option, firstOption, secondOption);
- break;
- case 's':
- case 'S':
- option++;
- if (state == 0)
- {
- title();
- }
- else if (state == 4)
- {
- choice = showCondition ? 's' : 27;
- }
- showOptions(option, firstOption, secondOption);
- break;
- case ' ':
- if (option == 1)
- {
- condition = false;
- say.clearScreen();
- if (state == 1)
- {
- mapSelection();
- }
- else if (state == 2)
- {
- levels.game("map1.txt");
- mapEnd();
- }
- else if (state == 3)
- {
- showResults("Id:", "Number results:", true, numberName.mapAccess(), fullName.mapAccess());
- }
- else if (state == 4)
- {
- if (insideCondition)
- {
- say.communique("Enter your name: ");
- listen.stringInput(name);
- addScore(true, name, levels.getScore());
- insideCondition = false;
- say.clearScreen();
- }
- say.communique("Your name is: " + name);
- say.communique("Your result is: " + std::to_string(levels.getScore()));
- //fullName.saveScoreToFile(fullName.mapAccess(), "String");
- }
- showOptions(option, firstOption, secondOption);
- }
- else if (option == 2)
- {
- say.clearScreen();
- if (state == 0)
- {
- exit(0);
- }
- else if (state == 1)
- {
- showScore();
- }
- else if (state == 2)
- {
- levels.game("map2.txt");
- mapEnd();
- }
- else if (state == 3)
- {
- showResults("Name:", "Full name results:", false, numberName.mapAccess(), fullName.mapAccess());
- }
- else if (state == 4)
- {
- if (insideCondition)
- {
- name = std::to_string(numberName.size() + 1);
- addScore(false, name, levels.getScore());
- insideCondition = false;
- }
- say.clearScreen();
- say.communique("Your number is: " + name);
- say.communique("Your result is: " + std::to_string(levels.getScore()));
- //numberName.saveScoreToFile(numberName.mapAccess(), "Int");
- }
- showOptions(option, firstOption, secondOption);
- }
- showCondition = false;
- break;
- case 27:
- if (state == 1)
- {
- say.clearScreen();
- startScreen();
- }
- else if (state == 2 || state == 3 || state == 4)
- {
- say.clearScreen();
- mainMenu();
- }
- break;
- default:
- break;
- }
- }
- }
- }
- say.clearScreen();
- }
- void Menu::startScreen()
- {
- int option = 0;
- mainSelection(option, "Start Game", "Close Game");
- }
- void Menu::mainMenu()
- {
- int option = 1;
- mainSelection(option, "Chose Map", "Show Score");
- }
- void Menu::mapSelection()
- {
- int option = 2;
- mainSelection(option, "First Map", "Second Map");
- }
- void Menu::showScore()
- {
- int option = 3;
- mainSelection(option, "Show number results", "Show full name results");
- }
- void Menu::mapEnd()
- {
- int option = 4;
- mainSelection(option, "Enter name", "Wait for number");
- }
- void Menu::showResults(string name, string resultsName, bool whichOne, map<int, int> intMap, map<string, int> stringMap)
- {
- string whatItShows;
- if (!numberName.mapAccess().empty())
- {
- say.communique("\n " + resultsName + "\n");
- if (whichOne)
- {
- for (const auto& [key, value] : intMap)
- {
- whatItShows = " " + name + std::to_string(key);
- whatItShows += " Value: " + std::to_string(value) + "\n";
- say.communique(whatItShows);
- }
- }
- else
- {
- for (const auto& [key, value] : stringMap)
- {
- whatItShows = " " + name + key;
- whatItShows += " Value: " + std::to_string(value) + "\n";
- say.communique(whatItShows);
- }
- }
- }
- say.stop(1);
- }
- void Menu::addScore(bool which, string name, int value)
- {
- if (which)
- {
- fullName.add(name, value);
- }
- else
- {
- numberName.add(numberName.size() + 1, value);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment