Advertisement
Rafpast

Menu3

Jul 3rd, 2022
1,019
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.97 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 == 0)
  74.                         {
  75.                             option = 1;
  76.                             firstOption = "Chose Map";
  77.                             secondOption = "Show Score";
  78.                         }
  79.                         else if (state == 1)
  80.                         {
  81.                             option = 2;
  82.                             say.clearScreen();
  83.                             firstOption = "First Map";
  84.                             secondOption = "Second Map";
  85.                         }
  86.                         else if (state == 2)
  87.                         {
  88.                             option = 4;
  89.                             levels.game("map1.txt");
  90.                             firstOption = "Enter name";
  91.                             secondOption = "Wait for number";
  92.                         }
  93.                         else if (state == 3)
  94.                         {
  95.                             showResults("Name:", "Full name results:", false, numberName.mapAccess(), fullName.mapAccess());
  96.                         }
  97.                         else if (state == 4)
  98.                         {
  99.                             if (insideCondition)
  100.                             {
  101.                                 say.communique("Enter your name:  ");
  102.                                 listen.stringInput(name);
  103.                                 addScore(true, name, levels.getScore());
  104.                                 insideCondition = false;
  105.                                 say.clearScreen();
  106.                             }
  107.  
  108.                             say.communique("Your name is: " + name);
  109.                             say.communique("Your result is: " + std::to_string(levels.getScore()));
  110.                             fullName.saveScoreToFile(fullName.mapAccess(), "String");
  111.                        
  112.                         }
  113.  
  114.                         showOptions(option, firstOption, secondOption);
  115.                     }
  116.                     else if (option == 2)
  117.                     {
  118.                         say.clearScreen();
  119.  
  120.                         if (state == 0)
  121.                         {                      
  122.                             exit(0);
  123.                         }
  124.                         else if (state == 1)
  125.                         {
  126.                             option = 3;
  127.                             firstOption = "Show number results";
  128.                             secondOption = "Show full name results";
  129.                         }
  130.                         else if (state == 2)
  131.                         {
  132.                             option = 4;
  133.                             levels.game("map2.txt");
  134.                             firstOption = "Enter name";
  135.                             secondOption = "Wait for number";
  136.                         }
  137.                         else if (state == 3)
  138.                         {
  139.                             showResults("Id:", "Number results:", true, numberName.mapAccess(), fullName.mapAccess());
  140.                         }
  141.                         else if (state == 4)
  142.                         {
  143.                             if (insideCondition)
  144.                             {
  145.                                 name = std::to_string(numberName.size() + 1);
  146.                                 addScore(false, name, levels.getScore());
  147.                                 insideCondition = false;
  148.                             }
  149.  
  150.                             say.clearScreen();
  151.                             say.communique("Your number is: " + name);
  152.                             say.communique("Your result is: " + std::to_string(levels.getScore()));
  153.                             numberName.saveScoreToFile(numberName.mapAccess(), "Int");
  154.                         }
  155.  
  156.                         showOptions(option, firstOption, secondOption);
  157.                        
  158.                     }
  159.  
  160.                     showCondition = false;
  161.  
  162.                     break;
  163.                 case 27:
  164.                    
  165.                     if (state == 1)
  166.                     {
  167.                         state = 0;
  168.                         option = 0;
  169.                         say.clearScreen();
  170.                         firstOption = "Start Game";
  171.                         secondOption = "Close Game";
  172.                     }
  173.                     else if (state == 2 || state == 3 || state == 4)
  174.                     {
  175.                         state = 1;
  176.                         option = 1;
  177.                         say.clearScreen();
  178.                         firstOption = "Chose Map";
  179.                         secondOption = "Show Score";
  180.                     }
  181.  
  182.                     break;
  183.                 default:
  184.                     break;
  185.                 }
  186.             }
  187.         }
  188.     }
  189.     say.clearScreen();
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement