Advertisement
Rafpast

MainMenu

Jul 2nd, 2022
1,137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.88 KB | None | 0 0
  1. void  Menu::mainSelection(int& state, string firstOption, string secondOption)
  2. {
  3.     string name;
  4.     int option = 1;
  5.     char choice = 'w';
  6.  
  7.     if (state == 0)
  8.     {
  9.         title();
  10.     }
  11.  
  12.     showOptions(option, firstOption, secondOption);
  13.     bool condition = true, insideCondition = true, showCondition = true;
  14.  
  15.     while (condition)
  16.     {
  17.         if (listen.isEmpty())
  18.         {
  19.             listen.charInput(choice);
  20.  
  21.             if (static_cast <int>(choice) == -32)
  22.             {
  23.                 if (state == 0)
  24.                 {
  25.                     title();
  26.                 }
  27.  
  28.                 arrowSupport(option, firstOption, secondOption);
  29.             }
  30.             else
  31.             {
  32.                 switch (choice)
  33.                 {
  34.                 case 'w':
  35.                 case 'W':
  36.                     option--;
  37.  
  38.                     if (state == 0)
  39.                     {
  40.                         title();
  41.                     }
  42.                     else if (state == 4)
  43.                     {
  44.                         choice = showCondition ? 'w' : 27;
  45.                     }
  46.  
  47.                     showOptions(option, firstOption, secondOption);
  48.  
  49.                     break;
  50.                 case 's':
  51.                 case 'S':
  52.                     option++;
  53.  
  54.                     if (state == 0)
  55.                     {
  56.                         title();
  57.                     }
  58.                     else if (state == 4)
  59.                     {
  60.                         choice = showCondition ? 's' : 27;
  61.                     }
  62.  
  63.  
  64.                     showOptions(option, firstOption, secondOption);
  65.  
  66.                     break;
  67.                 case ' ':
  68.                     if (option == 1)
  69.                     {
  70.                         condition = false;
  71.                         say.clearScreen();
  72.  
  73.                         if (state == 1)
  74.                         {
  75.                             mapSelection();
  76.                         }
  77.                         else if (state == 2)
  78.                         {
  79.                             levels.game("map1.txt");
  80.                             mapEnd();
  81.                         }
  82.                         else if (state == 3)
  83.                         {
  84.                             showResults("Name:", "Full name results:", false, numberName.mapAccess(), fullName.mapAccess());
  85.                         }
  86.                         else if (state == 4)
  87.                         {
  88.                             if (insideCondition)
  89.                             {
  90.                                 say.communique("Enter your name:  ");
  91.                                 listen.stringInput(name);
  92.                                 addScore(true, name, levels.getScore());
  93.                                 insideCondition = false;
  94.                                 say.clearScreen();
  95.                             }
  96.  
  97.                             say.communique("Your name is: " + name);
  98.                             say.communique("Your result is: " + std::to_string(levels.getScore()));
  99.                             fullName.saveScoreToFile(fullName.mapAccess(), "String");
  100.                        
  101.                         }
  102.  
  103.                         showOptions(option, firstOption, secondOption);
  104.                     }
  105.                     else if (option == 2)
  106.                     {
  107.                         say.clearScreen();
  108.  
  109.                         if (state == 0)
  110.                         {                      
  111.                             exit(0);
  112.                         }
  113.                         else if (state == 1)
  114.                         {
  115.                             showScore();
  116.                         }
  117.                         else if (state == 2)
  118.                         {
  119.                             levels.game("map2.txt");
  120.                             mapEnd();
  121.                         }
  122.                         else if (state == 3)
  123.                         {
  124.                             showResults("Id:", "Number results:", true, numberName.mapAccess(), fullName.mapAccess());
  125.                         }
  126.                         else if (state == 4)
  127.                         {
  128.                             if (insideCondition)
  129.                             {
  130.                                 name = std::to_string(numberName.size() + 1);
  131.                                 addScore(false, name, levels.getScore());
  132.                                 insideCondition = false;
  133.                             }
  134.  
  135.                             say.clearScreen();
  136.                             say.communique("Your number is: " + name);
  137.                             say.communique("Your result is: " + std::to_string(levels.getScore()));
  138.                             numberName.saveScoreToFile(numberName.mapAccess(), "Int");
  139.                         }
  140.  
  141.                         showOptions(option, firstOption, secondOption);
  142.                        
  143.                     }
  144.  
  145.                     showCondition = false;
  146.  
  147.                     break;
  148.                 case 27:
  149.                    
  150.                     if (state == 1)
  151.                     {
  152.                         say.clearScreen();
  153.                         state = 0;
  154.                         startScreen();
  155.                     }
  156.                     else if (state == 2 || state == 3 || state == 4)
  157.                     {
  158.                         say.clearScreen();
  159.                         mainMenu();
  160.                     }
  161.  
  162.                     break;
  163.                 default:
  164.                     break;
  165.                 }
  166.             }
  167.         }
  168.     }
  169.     say.clearScreen();
  170. }
  171.  
  172. void Menu::startScreen()
  173. {
  174.     int option = 0;
  175.     mainSelection(option, "Start Game", "Close Game");
  176. }
  177.  
  178. void Menu::mainMenu()
  179. {
  180.     int option = 1;
  181.     mainSelection(option, "Chose Map", "Show Score");
  182. }
  183.  
  184. void Menu::mapSelection()
  185. {
  186.     int option = 2;
  187.     mainSelection(option, "First Map", "Second Map");
  188. }
  189.  
  190. void Menu::showScore()
  191. {
  192.     int option = 3;
  193.     mainSelection(option, "Show number results", "Show full name results");
  194. }
  195.  
  196. void Menu::mapEnd()
  197. {
  198.     int option = 4;
  199.     mainSelection(option, "Enter name", "Wait for number");
  200. }
  201.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement