SHARE
TWEET

Untitled

a guest Jan 15th, 2020 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream> //library used to access functions such as cin and cout
  2. #include <time.h> //srand, which is used in order to find a random immortal peg
  3. #include <graphics.h>
  4. #include <windows.h>
  5. #include <stdlib.h>
  6. #include <winbgim.h>
  7.  
  8.  
  9. using namespace std;
  10.  
  11.  
  12. const int NUMCOLUMNS = 5; //the number of columns
  13. const int NUMROWS = 5;  //the number of rows
  14.  
  15.  
  16.  
  17. //This subprogram fills the board initially
  18. void MakeGrid(char Board[NUMROWS][NUMCOLUMNS] /*inout*/,
  19.   char& pegSpace, bool& startNewGame /*inout*/)
  20. {
  21.   if (startNewGame == true) //if a new game is started
  22.   {
  23.     char Peg = 'O'; // O is used as a peg
  24.     for (int xCoord = 5; xCoord > 0; xCoord--) //filling the X coordinates
  25.       //from row 5 (at the top) to row 1 (at the bottom)
  26.     {
  27.       for (int yCoord = 1; yCoord < 6; yCoord++) //filling the Y coordinates
  28.         //from column 1 (left) to column 5 (right)
  29.       {
  30.         Board[xCoord][yCoord] = Peg; //both the X and Y coordinates in the for
  31.         //loops will store a peg (O)
  32.       }
  33.     }
  34.     Board[3][3] = pegSpace;
  35.     //except the location 3,3 (centre) has a space
  36.   }
  37. }
  38.  
  39.  
  40.  
  41. //This subprogram shows the board once it is made
  42. void ShowGrid(char Board[NUMROWS][NUMCOLUMNS]/*inout*/, char pegSpace /*in*/,
  43.   int pegsRemaining /*in*/, int& highscore /*inout*/)
  44. {
  45.   cout << "\n" << endl;
  46.   cout << "              Solitaire " << endl;
  47.   cout << "\n     Highscore: " << highscore;
  48.   cout << "          Pegs Remaining: " << pegsRemaining;
  49.   cout << "\n\n\n\n";
  50.   for (int xCoord = 5; xCoord > 0; xCoord--) //for loop displays the board
  51.   {
  52.     if (xCoord == 5) //if loop displays a Y next to 5, or spaces instead
  53.       //next to numbers instead
  54.     {
  55.       cout << "         Y  " << xCoord << " | "; //displays a Y, #
  56.     }
  57.     else
  58.     {
  59.       cout << "            " << xCoord << " | "; //or displays spaces, #
  60.  
  61.     }
  62.     for (int yCoord = 1; yCoord < 6; yCoord++)
  63.     {
  64.       cout << Board[yCoord][xCoord] << "   ";
  65.     } //end of Y Coordinate
  66.     if (xCoord != 1)
  67.     {
  68.       cout << "\n                           \n";
  69.     }
  70.   }//end of X Coordinate
  71.   cout << "\n              --------------------\n";
  72.   cout << "                1   2   3   4   5   \n";
  73.   cout << "\n                                X   \n";
  74. }
  75.  
  76.  
  77.  
  78. //This subprogram takes the user's input of the X and Y coordinates and
  79. //the direction the player wishes to move, works out the peg to be removed
  80. //and if the move is valid. If the user has selected the immortal peg, the
  81. //moves of its new position are worked out.
  82. void CalculateMoves(int& playerCoordinateX /*inout*/,
  83.   int& newSpaceX /*inout*/,
  84.   char directionToMove /*in*/, char Board[NUMROWS][NUMCOLUMNS]/*inout*/,
  85.   int& playerCoordinateY /*inout*/, int& newSpaceY/*inout*/,
  86.   int& immortalX /*inout*/, int& immortalY /*inout*/)
  87. {
  88.   if (directionToMove == 'n' || directionToMove == 'N')
  89.   {
  90.     //if the user inputted direction is N
  91.  
  92.   //---------------- X -----------------
  93.  
  94.     if (playerCoordinateX == immortalX)
  95.     {
  96.       immortalX = immortalX;
  97.     }
  98.     //the immortal peg's X coordinates are not changed, if the user has
  99.     //selected it
  100.  
  101.     newSpaceX = playerCoordinateX;
  102.     playerCoordinateX = playerCoordinateX;
  103.     //no changes are made to the coordinates
  104.  
  105.   //---------------- Y -----------------
  106.  
  107.     if (playerCoordinateY == immortalY)
  108.     {
  109.       immortalY = immortalY + 2;
  110.     }
  111.     //the immortal peg's Y coordinate is moved two spaces up
  112.     //if the user has selected it
  113.  
  114.     newSpaceY = playerCoordinateY + 1;
  115.     //the peg to be deleted in one space up from the inputted peg
  116.     playerCoordinateY = playerCoordinateY + 2;
  117.     //the new peg coordinate is two spaces up from the inputted peg
  118.   }
  119.   else if (directionToMove == 'e' || directionToMove == 'E')
  120.   {
  121.     //if the user inputted direction is E
  122.  
  123.   //---------------- X -----------------
  124.  
  125.     if (playerCoordinateX == immortalX)
  126.     {
  127.       immortalX = immortalX + 2;
  128.     }
  129.     //the immortal peg's X coordinate is moved two spaces right
  130.     //if the user has selected it
  131.  
  132.     newSpaceX = playerCoordinateX + 1;
  133.     //the deleted peg is one space more than the inputted peg
  134.     playerCoordinateX = playerCoordinateX + 2;
  135.     //the new coordinate is two spaces more than the inputted peg
  136.  
  137.   //---------------- Y -----------------
  138.  
  139.     if (playerCoordinateY == immortalY)
  140.     {
  141.       immortalY = immortalY;
  142.     }
  143.     //the immortal peg's Y coordinate is not changed, if the user has
  144.     //selected it
  145.  
  146.     newSpaceY = playerCoordinateY;
  147.     playerCoordinateY = playerCoordinateY;
  148.     //no changes are made to the peg
  149.  
  150.   }
  151.   else if (directionToMove == 'w' || directionToMove == 'W')
  152.   {
  153.     //if the user inputted direction is W
  154.  
  155.   //---------------- X -----------------
  156.  
  157.     if (playerCoordinateX == immortalX)
  158.     {
  159.       immortalX = immortalX - 2;
  160.     }
  161.     //the immortal peg's X coordinate is moved two spaces left
  162.     //if the user has selected it
  163.  
  164.     newSpaceX = playerCoordinateX - 1;
  165.     //the deleted peg is one space less than the inputted peg
  166.     playerCoordinateX = playerCoordinateX - 2;
  167.     //the new coordinate is two spaces less than the inputted peg
  168.  
  169.   //---------------- Y -----------------
  170.  
  171.     if (playerCoordinateY == immortalY)
  172.     {
  173.       immortalY = immortalY;
  174.     }
  175.     //the immortal peg's Y coordiante is not changed, if the user has
  176.     //selected it
  177.  
  178.     newSpaceY = playerCoordinateY;
  179.     playerCoordinateY = playerCoordinateY;
  180.     //no changes are made to the peg
  181.   }
  182.   else if (directionToMove == 's' || directionToMove == 'S')
  183.   {
  184.     //if the user inputted direction is S
  185.  
  186.   //---------------- X -----------------
  187.  
  188.     if (playerCoordinateX == immortalX)
  189.     {
  190.       immortalX = immortalX;
  191.     }
  192.     //the immortal peg's X coordinate is not changed, if the user has
  193.     //selected it
  194.  
  195.     newSpaceX = playerCoordinateX;
  196.     playerCoordinateX = playerCoordinateX;
  197.     //no changes are made to the pegs
  198.  
  199.   //---------------- Y -----------------
  200.  
  201.     if (playerCoordinateY == immortalY)
  202.     {
  203.       immortalY = immortalY - 2;
  204.     }
  205.     //the immortal peg's Y coordinate is moved two spaces down,
  206.     //if the user has selected it
  207.  
  208.     newSpaceY = playerCoordinateY - 1;
  209.     //the peg to be deleted is one space down from the peg inputted
  210.     playerCoordinateY = playerCoordinateY - 2;
  211.     //the new peg location is two spaces down from the peg inputted
  212.   }
  213. }
  214.  
  215.  
  216.  
  217. //This subprogram validates user moves
  218. void MoveValidation(char Board[NUMROWS][NUMCOLUMNS] /*inout*/,
  219.   int playerCoordinateX /*in*/,
  220.   int playerCoordinateY /*in*/, int newSpaceX /*in*/,
  221.   int newSpaceY /*in*/, bool& makeAMove /*inout*/,
  222.   bool& validMove /*inout*/,
  223.   int lastMoveX/*in*/, int lastMoveY/*in*/)
  224. {
  225.   if (Board[lastMoveX][lastMoveY] == ' ')
  226.   {
  227.     //if the last move (i.e. the original user coordinates) is
  228.     //a space:
  229.     cout << "~~~ Error 0 - there is no peg to start with" << endl;
  230.     //output error 0 as there is no peg to start with
  231.     makeAMove = true; //return the user to the move making stage
  232.     validMove = false;  //set to invalid move
  233.   }
  234.   else if (Board[newSpaceX][newSpaceY] != 'O')
  235.   {
  236.     //if the peg that is to be deleted is not a peg (is a space instead):
  237.     cout << "~~~ Error 1 - there is no peg to jump over" << endl;
  238.     //output error 1 as there is no peg to jump over
  239.     makeAMove = true; //returns user to move making stage
  240.     validMove = false;  //set to invalid move
  241.   }
  242.   else if (playerCoordinateX < 0 || playerCoordinateX > 5
  243.     || playerCoordinateY < 0 || playerCoordinateY > 5
  244.     || newSpaceX < 0 || newSpaceX > 5 ||
  245.     newSpaceY < 0 || newSpaceY > 5)
  246.   {
  247.     //if the new coordinates or deleted peg coordinates are not within
  248.     //the range of 1 to 5 (the original coordinates are dealt with in
  249.     //the main subprogram):
  250.     cout << "~~~ Error 2 - a peg will move off the board" << endl;
  251.     //output error 2 as a peg would move off the board and the array
  252.     //would break
  253.     makeAMove = true; //returns user to move making stage
  254.     validMove = false;  //set to invalid move
  255.   }
  256.   else if (Board[playerCoordinateX][playerCoordinateY] == 'O')
  257.   {
  258.     //if the new coordinates already have an O (a peg) in:
  259.     cout << "~~~ Error 3 - a peg already occupies this space!" << endl;
  260.     //output error 3 as a peg already exists in the selected location
  261.     makeAMove = true; //returns user to move making stage
  262.     validMove = false;  //set to invalid move
  263.   }
  264. }
  265.  
  266.  
  267.  
  268. //This subprogram updates the user inputted moves on the board after
  269. //the program has validated the user's moves
  270. void UpdateMoves(char Board[NUMROWS][NUMCOLUMNS], int& playerCoordinateX,
  271.   int& playerCoordinateY, int& newSpaceX,
  272.   int& newSpaceY, int& lastMoveX, int& lastMoveY,
  273.   bool& validMove,  int& immortalX,
  274.   int& immortalY)
  275. {
  276.   Board[playerCoordinateX][playerCoordinateY] = 'O';
  277.  
  278.   Board[newSpaceX][newSpaceY] = ' ';
  279.  
  280.   Board[lastMoveX][lastMoveY] = ' ';
  281.   Board[immortalX][immortalY] = 'O';
  282.  
  283. }
  284.  
  285.  
  286.  
  287.  
  288. void DisplayHighscores(int& currentScore, int& highscore) /*both inout*/
  289. {
  290. }
  291.  
  292.  
  293.  
  294.  
  295. void DisplayRules()
  296. {
  297.  
  298. }
  299.  
  300.  
  301.  
  302. //This subprogram is the very first run and asks the player whether they need
  303. //to see the rules or not
  304. void IntroductionToGame(bool& gameActive, bool& startNewGame, bool& makeAMove)
  305.   //all parameters are inout
  306. {
  307.   bool validChar = false; //used to determine inputted character
  308.   char userInput = '\0'; //the letter that the user inputs
  309.   cout << "Welcome to Peg Solitaire!" << endl; //prints out line
  310.   cout << "To start the game input"; //prints out line
  311.   cout << " (A): "; //prints out next to input
  312.   cin >> userInput; //user inputs choice
  313.  
  314. if (userInput == 'a' || userInput == 'A')
  315.   { //if the user inputs N or n
  316.     validChar = true;
  317.   }else {cout << "Please input 'A' to start the Game";}
  318.   while (validChar == false)
  319.   {
  320.     cout << "Please input 'A' to start the Game";
  321.     cout << "\n";
  322.  
  323.     cin >> userInput;
  324. if (userInput == 'a' || userInput == 'A')
  325. {
  326.     validChar==true;
  327.     break;
  328. }
  329.   }
  330. }
  331.  
  332.  
  333.  
  334. //This subprogram contains the game
  335. void PlayTheGame(char Board[NUMROWS][NUMCOLUMNS], char pegSpace,
  336.   bool& startNewGame, int& pegsRemaining, bool& validMove,
  337.   bool& gameActive, int& playerCoordinateX,
  338.   int& playerCoordinateY, int& lastMoveX, int& lastMoveY,
  339.   bool& makeAMove, int& newSpaceX, int& newSpaceY,
  340.   char& inputKey, char& directionToMove, int& currentScore,
  341.   int& highscore, int& moveCounter, int& immortalX,
  342.   int& immortalY)
  343.   //all are 'inout' except pegSpace
  344. {
  345.   while (gameActive == true)
  346.   { //while the game is being played
  347.     MakeGrid(Board, pegSpace, startNewGame); //the board is generated
  348.     ShowGrid(Board, pegSpace, pegsRemaining, highscore);
  349.     //the board and UI is
  350.     //shown
  351.     while (makeAMove == true)
  352.     { //while the player is making a move
  353.       validMove = true; //valid move reset to true
  354.       cout << "\nWhat move would you like to make?" << endl;
  355.       //asks user to input a move
  356.       cout << "X: ";
  357.       cin >> playerCoordinateX; //X coordinate is inputted first
  358.       while (!cin >> playerCoordinateX)
  359.       { //if the input is invalid - e.g. a letter is inputted
  360.         cin.clear();  //the input stream is cleared
  361.         cin.ignore(999, '\n'); //all input is discarded
  362.         cout << "Please enter a valid X coordinate: " << endl;
  363.         cin >> playerCoordinateX; //a valid input must be used
  364.       }
  365.       cout << endl; //a new line is started
  366.       if (playerCoordinateX < 0 || playerCoordinateX > 5)
  367.       { //if coordinates are not between 1 and 5, then error is printed out
  368.         cout << "Error 2 - X Coordinate is off the board"; //error message
  369.                                                            //is displayed and
  370.         cout << endl;                                      //a new line printed
  371.         cout << "Please enter a valid coordinate: ";
  372.         cin >> playerCoordinateX; //user asked to re-enter X coordinate
  373.         while (!cin >> playerCoordinateX)
  374.         { //if the input is invalid - e.g. a letter is inputted
  375.           cin.clear();  //the input stream is cleared
  376.           cin.ignore(999, '\n'); //all input is discarded
  377.           cout << "Please enter a valid X coordinate: " << endl;
  378.           cin >> playerCoordinateX; //a valid input must be used
  379.         }
  380.       }
  381.       cout << "Y: ";
  382.       cin >> playerCoordinateY; //the user then inputs the Y coordinate
  383.       while (!cin >> playerCoordinateY)
  384.       { //if the input is invalid - e.g. a letter is inputted
  385.         cin.clear();  //the input stream is cleared
  386.         cin.ignore(999, '\n'); //all input is discarded
  387.         cout << "Please enter a valid Y coordinate: " << endl;
  388.         cin >> playerCoordinateY; //a valid input must be used
  389.       }
  390.       cout << endl; //a new line is printed
  391.       if (playerCoordinateY < 0 || playerCoordinateY > 5)
  392.       { //if coordinates are not between 1 and 5, then error is printed out
  393.         cout << "Error 2 - Y Coordinate is off the board"; //error message is
  394.                                                            //printed out
  395.         cout << "\nPlease enter a valid coordinate: ";
  396.         cin >> playerCoordinateY; //user asked to re-enter the Y coordinate
  397.         while (!cin >> playerCoordinateY)
  398.         { //if the input is invalid - e.g. a letter is inputted
  399.           cin.clear();  //the input stream is cleared
  400.           cin.ignore(999, '\n'); //all input is discarded
  401.           cout << "Please enter a valid X coordinate: " << endl;
  402.           cin >> playerCoordinateX; //a valid input must be used
  403.         }
  404.         cout << endl; //prints out new line
  405.       }
  406.  
  407.       if (playerCoordinateX == 0 && playerCoordinateY == 0)
  408.       { //if 0,0 is input, the game is stopped
  409.         cout << "The game will be stopped... are you sure?" << endl;
  410.         cout << "Y/N: "; //user asked to confirm exit
  411.         cin >> inputKey; //user inputs Y or N to stop game
  412.         if (inputKey == 'y' || inputKey == 'Y')
  413.         { //if y or Y is input and game is stopped
  414.           gameActive = false; //game loop ends
  415.           startNewGame = false; //resets new game variable
  416.           makeAMove = false;  //move making ends
  417.  
  418.           //Final Score Calculator
  419.           if (pegsRemaining > 8)
  420.           { //if 9 or more pegs remain, score is 0
  421.             currentScore = 0;
  422.           }
  423.           else if (pegsRemaining == 8)
  424.           { //if 8 pegs remain, score is 10
  425.             currentScore = 10;
  426.           }
  427.           else if (pegsRemaining == 7)
  428.           { //if 7 pegs remain, score is 20
  429.             currentScore = 20;
  430.           }
  431.           else if (pegsRemaining == 6)
  432.           { //if 6 pegs remain, score is 30
  433.             currentScore = 30;
  434.           }
  435.           else if (pegsRemaining == 5)
  436.           { //if 5 pegs remain, score is 40
  437.             currentScore = 40;
  438.           }
  439.           else if (pegsRemaining == 4)
  440.           { //if 4 pegs remain, score is 50
  441.             currentScore = 50;
  442.           }
  443.           else if (pegsRemaining == 3)
  444.           { //if 3 pegs remain, score is 60
  445.             currentScore = 60;
  446.           }
  447.           else if (pegsRemaining == 2)
  448.           { //if 2 pegs remain, score is 70
  449.             currentScore = 70;
  450.           }
  451.           else if (pegsRemaining == 1)
  452.           { //if 1 peg remains, score is 80
  453.             currentScore = 80;
  454.           }
  455.           if (Board[3][3] == 'O' && pegsRemaining == 1)
  456.           { //if one peg is the centre hole (3,3) remains, score is
  457.             //80 with a 20 point bonus (totalling 100)
  458.             currentScore = currentScore + 20;
  459.             cout << "Congratulations, you performed the expert finish";
  460.             cout << " and receive an extra 20 points!" << endl;
  461.  
  462.  
  463.           }
  464.  
  465.           cout << "\nYour final score is: " << currentScore << "!" << endl;
  466.  
  467.           if (currentScore > highscore)
  468.           {
  469.  
  470.             highscore = currentScore;
  471.             cout << "Congratulations! You've set a new high ";
  472.         cout << "score!" << endl;
  473.             //congratulatory message is printed
  474.           }
  475.           cout << "You made " << moveCounter << " moves!\n\n";
  476.  
  477.           break;
  478.         }
  479.         else if (inputKey == 'n' || inputKey == 'N')
  480.         {
  481.           cout << "Please change your coordinates -" << endl;
  482.         cout << "X: ";
  483.           cin >> playerCoordinateX;
  484.         cout << endl;
  485.           cout << "Y: ";
  486.         cin >> playerCoordinateY;
  487.           cout << endl;
  488.         }
  489.         else
  490.         {
  491.           cout << "Please input Y or N:" << endl;
  492.         cin >> inputKey;
  493.         }
  494.       }
  495.  
  496.       if (playerCoordinateX == immortalX && playerCoordinateY == immortalY)
  497.       {
  498.     cout << "\nYou have selected the immortal peg!" << endl;
  499.         cout << "This peg can jump over others, but if jumped over, will ";
  500.         cout << "not be removed from the board" << endl;
  501.  
  502.       }
  503.  
  504.       {
  505.          cout << "In which direction: N, E, S or W?" << endl;
  506.           cin >> directionToMove;
  507.             cout << endl;
  508.         if (directionToMove == 'n' || directionToMove == 'N' ||
  509.              directionToMove == 'e' || directionToMove == 'E' ||
  510.              directionToMove == 's' || directionToMove == 'S' ||
  511.            directionToMove == 'w' || directionToMove == 'W')
  512.         {
  513.           lastMoveX = playerCoordinateX;
  514.           lastMoveY = playerCoordinateY;
  515.         }
  516.         while ( directionToMove != 'n' && directionToMove != 'N' &&
  517.     directionToMove != 'e' && directionToMove != 'E' &&
  518.            directionToMove != 's' && directionToMove != 'S' &&
  519.              directionToMove != 'w' && directionToMove != 'W')
  520.         {
  521.  
  522.           cout << "Please enter a valid direction: ";
  523.           cin >> directionToMove;
  524.           cout << "\n";
  525.           if (directionToMove == 'n' || directionToMove == 'N' ||
  526.             directionToMove == 'e' || directionToMove == 'E' ||
  527.             directionToMove == 's' || directionToMove == 'S' ||
  528.             directionToMove == 'w' || directionToMove == 'W')
  529.           {
  530.             lastMoveX = playerCoordinateX;
  531.             lastMoveY = playerCoordinateY;
  532.  
  533.             break;
  534.           }
  535.  
  536.         }
  537.  
  538.         cout << "So, you want peg " << lastMoveX << "," << lastMoveY;
  539.         cout << " to move ";
  540.         if (directionToMove == 'n' || directionToMove == 'N')
  541.         {
  542.           cout << "up?" << endl;
  543.         }
  544.         else if (directionToMove == 'e' || directionToMove == 'E')
  545.         {
  546.           cout << "right?" << endl;
  547.         }
  548.         else if (directionToMove == 'w' || directionToMove == 'W')
  549.         {
  550.           cout << "left?" << endl;
  551.         }
  552.         else if (directionToMove == 's' || directionToMove == 'S')
  553.         {
  554.           cout << "down?" << endl;
  555.         }
  556.         cout << "If so, press 'Y' or press 'Q' to choose again:" << endl;
  557.  
  558.         cin >> inputKey;
  559.         cout << "\n" << endl;
  560.         if (inputKey == 'y' || inputKey == 'Y')
  561.         {
  562.           makeAMove = false;
  563.         }
  564.         else if (inputKey == 'q' || inputKey == 'Q' ||
  565.           inputKey == 'n' || inputKey == 'N')
  566.         {
  567.           makeAMove = false;
  568.           makeAMove = true;
  569.           ShowGrid(Board, pegSpace, pegsRemaining, highscore);
  570.         }
  571.         else
  572.         {
  573.           cout << "Please enter a valid key: ";
  574.           cin >> inputKey;
  575.           if (inputKey == 'y' || inputKey == 'Y')
  576.           {
  577.             makeAMove = false;
  578.           }
  579.           else if (inputKey == 'q' || inputKey == 'Q')
  580.           {
  581.             makeAMove = false;
  582.             makeAMove = true;
  583.           }
  584.         }
  585.       }
  586.  
  587.       while (makeAMove == false)
  588.       {
  589.         CalculateMoves(playerCoordinateX, newSpaceX,
  590.           directionToMove, Board, playerCoordinateY, newSpaceY,
  591.           immortalX, immortalY);
  592.  
  593.  
  594.         MoveValidation(Board, playerCoordinateX, playerCoordinateY,
  595.           newSpaceX, newSpaceY, makeAMove, validMove,
  596.           lastMoveX, lastMoveY);
  597.  
  598.         while (validMove == true)
  599.         {
  600.           UpdateMoves(Board, playerCoordinateX,
  601.             playerCoordinateY, newSpaceX, newSpaceY,
  602.             lastMoveX, lastMoveY, validMove, immortalX,
  603.             immortalY);
  604.  
  605.           pegsRemaining--;
  606.           moveCounter++;
  607.           validMove = false;
  608.         }
  609.         ShowGrid(Board, pegSpace, pegsRemaining, highscore);
  610.  
  611.         makeAMove = true;
  612.       }
  613.     }
  614.   }
  615. }
  616.  
  617.  
  618.  
  619.  
  620. void ShowMenu(bool& gameActive, bool& startNewGame, bool& makeAMove,
  621.   char Board[NUMROWS][NUMCOLUMNS], char pegSpace,
  622.   int& currentScore, int& highscore, int pegsRemaining,
  623.   bool validMove, int playerCoordinateX,
  624.   int playerCoordinateY, int lastMoveX, int lastMoveY,
  625.   int newSpaceX, int newSpaceY, char inputKey,
  626.   char directionToMove, int& moveCounter, int& immortalX,
  627.   int& immortalY)
  628.  
  629. {
  630.   int menuInput = '\0';
  631.  
  632.   cout << "\n------- MENU -------\n" << endl;
  633.   cout << "1) Play Game" << endl;
  634.   cout << "2) Exit Game" << endl;
  635.   cout << "Option: ";
  636.   cin >> menuInput;
  637.   if (!cin >> menuInput)
  638.   {
  639.     cin.clear();
  640.     cin.ignore(999, '\n');
  641.     cout << "Please enter a valid menu option: " << endl;
  642.     cin >> menuInput;
  643.   }
  644.   switch (menuInput)
  645.   {
  646.   case 1:
  647.     gameActive = true;
  648.     startNewGame = true;
  649.     makeAMove = true;
  650.     PlayTheGame(Board, pegSpace, startNewGame, pegsRemaining, validMove,
  651.       gameActive, playerCoordinateX, playerCoordinateY, lastMoveX,
  652.       lastMoveY, makeAMove, newSpaceX, newSpaceY,
  653.       inputKey, directionToMove, currentScore, highscore, moveCounter,
  654.       immortalX, immortalY);
  655.  
  656.     break;
  657.  
  658.   case 2:
  659.     cout << "2) Exit Game" << endl;
  660.     exit(0);
  661.     break;
  662.   default:
  663.     cout << "Please enter a valid menu input!" << endl;
  664.  
  665.   }
  666. }
  667.  
  668.  
  669.  
  670. int main()
  671. {
  672. srand((unsigned)time(NULL));
  673.   bool gameActive = false;
  674.   bool makeAMove = false;
  675.  
  676.   bool validMove = true;
  677.   bool startNewGame = true;
  678.   char Board[NUMROWS][NUMCOLUMNS];
  679.  
  680.   char pegSpace = ' ';
  681.   char directionToMove = '\0';
  682.   char inputKey = '\0';
  683.   int pegsRemaining = 24;
  684.   int playerCoordinateX = '\0';
  685.  
  686.   int newSpaceX = '\0';
  687.  
  688.   int lastMoveX = '\0';
  689.   int playerCoordinateY = '\0';
  690.  
  691.   int newSpaceY = '\0';
  692.   int lastMoveY = '\0';
  693.   int highscore = 0;
  694.   int currentScore = 0;
  695.   int immortalX = rand()% 5+1;
  696.   int immortalY = rand()% 5+1;
  697.   int moveCounter = 0;
  698.  
  699.  
  700.  
  701.   IntroductionToGame(gameActive, startNewGame, makeAMove);
  702.  
  703.   ShowMenu(gameActive, startNewGame, makeAMove, Board, pegSpace, currentScore,
  704.     highscore, pegsRemaining, validMove, playerCoordinateX,
  705.     playerCoordinateY, lastMoveX, lastMoveY, newSpaceX,
  706.     newSpaceY, inputKey, directionToMove, moveCounter,
  707.     immortalX, immortalY);
  708.  
  709.   PlayTheGame(Board, pegSpace, startNewGame, pegsRemaining, validMove,
  710.     gameActive, playerCoordinateX, playerCoordinateY, lastMoveX,
  711.     lastMoveY, makeAMove, newSpaceX, newSpaceY,
  712.     inputKey, directionToMove, currentScore, highscore, moveCounter,
  713.     immortalX, immortalY);
  714.  
  715.  
  716.   while (gameActive == false)
  717.   {
  718.     ShowMenu(gameActive, startNewGame, makeAMove, Board, pegSpace,
  719.       currentScore, highscore, pegsRemaining, validMove, playerCoordinateX,
  720.       playerCoordinateY, lastMoveX, lastMoveY, newSpaceX,
  721.       newSpaceY, inputKey, directionToMove, moveCounter,
  722.       immortalX, immortalY);
  723.  
  724.   }
  725. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top