Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main()
- {
- Menu* menu = &Menu::getInstance();
- if (menu != NULL)
- {
- menu->startScreen();
- menu->mainMenu();
- }
- delete menu;
- return 0;
- }
- Menu::Menu()
- {
- if (!numberName.isVoid())
- {
- numberName.readScoreFromFile("Int");
- }
- if (!fullName.isVoid())
- {
- fullName.readScoreFromFile("String");
- }
- }
- void Menu::title()
- {
- say.clearScreen();
- say.changeColor(6);
- say.communique(" _______ __________ __ __ __________ _______ ___ _ ");
- say.communique(" | ____| | ____ | | | / / | ____ | | _ | /\\ | \\ | | ");
- say.communique(" | | | | | | | |_/ / | | | | | | | | / \\ | |\\ \\ | | ");
- say.communique(" | |____ | | | | | / | | | | | |__| | / /\\ \\ | | \\ \\ | | ");
- say.communique(" |____ | | | | | | | | | | | | _ _ | / /__\\ \\ | | \\ \\ | | ");
- say.communique(" | | | | | | | _ \\ | | | | | | | | / /____\\ \\ | | \\ \\ | | ");
- say.communique(" _____| | | |____| | | | \\ \\ | |____| | | |__ | | / / \\ \\ | | \\ \\| | ");
- say.communique("|________| |__________| |__| \\__\\ |__________| |_______| /_/ \\_\\ |_| \\___| ");
- say.communique("\n");
- say.changeColor(15);
- }
- 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;
- }
- }
- 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 ? choice : 27;
- }
- showOptions(option, firstOption, secondOption);
- break;
- case 's':
- case 'S':
- option++;
- if (state == 0)
- {
- title();
- }
- else if (state == 4)
- {
- choice = showCondition ? choice : 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("Name:", "Full name results:", false, 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: " + to_string(levels.getScore()));
- fullName.saveScoreToFile(fullName.mapAccess(), "String");
- say.stop(2);
- }
- 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("Id:", "Number results:", true, numberName.mapAccess(), fullName.mapAccess());
- }
- else if (state == 4)
- {
- if (insideCondition)
- {
- name = 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: " + to_string(levels.getScore()));
- numberName.saveScoreToFile(numberName.mapAccess(), "Int");
- say.stop(2);
- }
- showOptions(option, firstOption, secondOption);
- }
- showCondition = false;
- break;
- case 27:
- if (state == 1)
- {
- say.clearScreen();
- state = 0;
- startScreen();
- }
- else if (state == 2 || state == 3 || state == 4)
- {
- say.clearScreen();
- mainMenu();
- }
- break;
- default:
- break;
- }
- }
- }
- }
- }
- 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 full name results", "Show number 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;
- char choice = ' ';
- if (!numberName.mapAccess().empty())
- {
- say.communique("\n " + resultsName + "\n");
- if (whichOne)
- {
- for (const auto& [key, value] : intMap)
- {
- whatItShows = " " + name + to_string(key);
- whatItShows += " Value: " + to_string(value) + "\n";
- say.communique(whatItShows);
- }
- }
- else
- {
- for (const auto& [key, value] : stringMap)
- {
- whatItShows = " " + name + key;
- whatItShows += " Value: " + to_string(value) + "\n";
- say.communique(whatItShows);
- }
- }
- }
- listen.charInput(choice);
- if (listen.isEmpty())
- {
- }
- }
- void Menu::addScore(bool which, string name, int value)
- {
- if (which)
- {
- fullName.add(name, value);
- }
- else
- {
- numberName.add(numberName.size() + 1, value);
- }
- }
- class Menu
- {
- private:
- Menu();
- output say;
- input listen;
- level levels;
- results<int> numberName{"int"};
- results<string> fullName{"string"};
- public:
- void arrowSupport(int& option, string option1, string option2);
- void showOptions(int& option, string option1, string option2);
- void mainSelection(int& state, string firstOption, string secondOption);
- void showResults(string name, string resultsName, bool whichOne, map<int, int> intMap, map<string, int> stringMap);
- void addScore(bool which, string name, int value);
- void mapSelection();
- void startScreen();
- void showScore();
- void mainMenu();
- void mapEnd();
- void title();
- static Menu& getInstance()
- {
- static Menu instance;
- return instance;
- }
- Menu(Menu const&) = delete;
- void operator=(Menu const&) = delete;
- };
Advertisement
RAW Paste Data
Copied
Advertisement