Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Menu::showOptions( int& option, string option1, string option2)
- {
- if (option > 2) {
- option = option - 2;
- }
- else if (option < 1)
- {
- option = option + 2;
- }
- 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:
- --option;
- say.clearScreen();
- showOptions(option, option1, option2);
- break;
- case 80:
- ++option;
- say.clearScreen();
- showOptions(option, option1, option2);
- break;
- default:
- break;
- }
- }
- void Menu::startScreen()
- {
- int option = 1;
- bool condition = true;
- char choice = ' ', choice2 = ' ';
- string firstOption = "Start Game", secondOption = "Close Game";
- title();
- showOptions(option, firstOption, secondOption);
- while (condition)
- {
- if (listen.isEmpty())
- {
- listen.charInput(choice);
- if (static_cast <int>(choice) == -32)
- {
- listen.charInput(choice2);
- switch (choice2)
- {
- case 72:
- --option;
- say.clearScreen();
- title();
- showOptions(option, firstOption, secondOption);
- break;
- case 80:
- ++option;
- say.clearScreen();
- title();
- showOptions(option, firstOption, secondOption);
- break;
- default:
- break;
- }
- }
- else
- {
- switch (choice)
- {
- case 'w':
- option--;
- say.clearScreen();
- title();
- showOptions(option, firstOption, secondOption);
- break;
- case 's':
- option++;
- say.clearScreen();
- title();
- showOptions(option, firstOption, secondOption);
- break;
- case' ':
- if (option == 1)
- {
- if (!numberName.isVoid())
- {
- numberName.readScoreFromFile("Int");
- }
- if (!fullName.isVoid())
- {
- fullName.readScoreFromFile("String");
- }
- condition = false;
- } else if (option == 2)
- {
- say.clearScreen();
- exit(0);
- }
- break;
- default:
- break;
- }
- }
- }
- }
- say.clearScreen();
- }
- void Menu::mainMenu()
- {
- char choice = ' ';
- bool condition = true;
- int option = 1, whichMap = 0;
- string firstOption = "Chose Map", secondOption = "Show Score";
- showOptions(option, firstOption, secondOption);
- while (condition)
- {
- if (listen.isEmpty())
- {
- listen.charInput(choice);
- if (static_cast <int>(choice) == -32)
- {
- arrowSupport(option, firstOption, secondOption);
- }
- else
- {
- switch (choice)
- {
- case 'w':
- option--;
- say.clearScreen();
- showOptions(option, firstOption, secondOption);
- break;
- case 's':
- option++;
- say.clearScreen();
- showOptions(option, firstOption, secondOption);
- break;
- case ' ':
- if (option == 1)
- {
- say.clearScreen();
- mapSelection(whichMap);
- condition = false;
- }
- else if (option == 2)
- {
- showScore();
- showOptions(option, firstOption, secondOption);
- }
- break;
- case 27:
- say.clearScreen();
- startScreen();
- break;
- default:
- break;
- }
- }
- }
- }
- say.clearScreen();
- }
- void Menu::mapSelection(int& option)
- {
- string firstOption = "First Map", secondOption = "Second Map";
- bool condition = true;
- char choice = ' ';
- showOptions(option, firstOption, secondOption);
- while (condition)
- {
- if (listen.isEmpty())
- {
- listen.charInput(choice);
- if (static_cast <int>(choice) == -32)
- {
- arrowSupport(option, firstOption, secondOption);
- }
- else
- {
- switch (choice)
- {
- case 'w':
- option--;
- say.clearScreen();
- showOptions(option, firstOption, secondOption);
- break;
- case 's':
- option++;
- say.clearScreen();
- showOptions(option, firstOption, secondOption);
- break;
- case ' ':
- if (option == 1)
- {
- levels.game("map1.txt");
- }
- else if (option == 2)
- {
- levels.game("map2.txt");
- }
- mapEnd();
- showOptions(option, firstOption, secondOption);
- break;
- case 27:
- say.clearScreen();
- condition = false;
- mainMenu();
- break;
- default:
- break;
- }
- }
- }
- }
- say.clearScreen();
- }
- void Menu::showScore()
- {
- int option = 1;
- char choice = ' ';
- bool condition = true;
- string firstOption = "Show number results", secondOption = "Show full name results";
- showOptions(option, firstOption, secondOption);
- while (condition)
- {
- if (listen.isEmpty())
- {
- listen.charInput(choice);
- if (static_cast <int>(choice) == -32)
- {
- arrowSupport(option, firstOption, secondOption);
- }
- else
- {
- switch (choice)
- {
- case 'w':
- option--;
- say.clearScreen();
- showOptions(option, firstOption, secondOption);
- break;
- case 's':
- option++;
- say.clearScreen();
- showOptions(option, firstOption, secondOption);
- break;
- case ' ':
- if (option == 1)
- {
- showResults("Id:", "Number results:", true, numberName.mapAccess(), fullName.mapAccess());
- }
- else if (option == 2)
- {
- showResults("Name:", "Full name results:", false, numberName.mapAccess(), fullName.mapAccess());
- }
- break;
- case 27:
- condition = false;
- say.clearScreen();
- mainMenu();
- break;
- default:
- break;
- }
- }
- }
- }
- say.clearScreen();
- }
- void Menu::mapEnd()
- {
- char whichOne = ' ';
- bool condition = true;
- string outcome = "You made " + levels.getScore();
- outcome += " moves. ";
- say.communique("outcome");
- while (condition)
- {
- say.clearScreen();
- say.communique("Would you like to be remembered by name(1) or number(2)? ");
- listen.charInput(whichOne);
- if (whichOne == '1')
- {
- string name;
- say.clearScreen();
- say.communique("Enter your name: ");
- listen.stringInput(name);
- addScore(true, name, levels.getScore());
- say.communique("Your result is: " + std::to_string(levels.getScore()));
- fullName.saveScoreToFile(fullName.mapAccess(), "String");
- say.stop(2);
- condition = false;
- }
- else if (whichOne == '2')
- {
- string name = std::to_string(numberName.size() + 1);
- say.clearScreen();
- say.communique("Your number will be generated: ");
- addScore(false, name, levels.getScore());
- say.communique("Your number is: " + name);
- say.communique("Your result is: " + std::to_string(levels.getScore()));
- numberName.saveScoreToFile(numberName.mapAccess(), "Int");
- say.stop(2);
- condition = false;
- }
- else
- {
- say.communique("Wrong choise, try again.");
- say.stop(1);
- }
- }
- say.clearScreen();
- }
- 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(" " + 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);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement