Advertisement
wild4fun88

Untitled

Nov 24th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.16 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <string>
  4. #include <iomanip>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8.  
  9. //declare array for game board and fill it
  10. char gameBoard[20][20] =
  11. { {'-' , '-' , '-' , '-' , '-' , '-' , '-' , '-' , '-' , '-' , '-', '-' , '-' , '-' , '-' , '-' , '-' , '-' , '-' , '-'}
  12. , {'|' , '#' , '#' , '#' , '|' , '#' , '#' , '#' , '#' , '#' , '#', '#' , '#' , '#' , '#' , '#' , '#' , '#' , '#' , '|'}
  13. , {'|' , '#' , '|' , '#' , '|' , '#' , '|' , '-' , '-' , '-' , '-', '-' , '-' , '#' , '-' , '-' , '-' , '-' , '-' , '|'}
  14. , {'|' , '#' , '|' , '#' , '#' , '#' , '|' , '#' , '#' , '#' , '#', '#' , '|' , '#' , '#' , '#' , '#' , '#' , '#' , '|'}
  15. , {'|' , 'O' , '|' , '#' , '|' , '-' , '-' , '#' , '|' , '-' , '|', '#' , '|' , '-' , '-' , '-' , '-' , '-' , '#' , '|'}
  16. , {'|' , '-' , '-' , '-' , '|' , '#' , '|' , '#' , '|' , '#' , '|', '#' , '|' , '#' , '#' , '#' , '#' , '#' , '#' , '|'}
  17. , {'|' , '#' , '#' , '#' , '|' , '#' , '|' , '#' , '#' , '#' , '|', '#' , '|' , '#' , '-' , '-' , '-' , '-' , '-' , '|'}
  18. , {'|' , '#' , '|' , '#' , '|' , '#' , '|' , '-' , '#' , '|' , '-', '#' , '|' , '#' , '|' , '#' , '#' , '#' , '#' , '|'}
  19. , {'|' , '#' , '|' , '#' , '|' , '#' , '|' , '#' , '#' , '|' , '#', '#' , '|' , '#' , '#' , '#' , '-' , '-' , '#' , '|'}
  20. , {'|' , '#' , '|' , '#' , '|' , '#' , '|' , '#' , '-' , '|' , '#', '#' , '|' , '-' , '-' , '-' , '|' , '|' , '#' , '|'}
  21. , {'|' , '#' , '|' , '#' , '#' , '#' , '|' , '#' , '#' , '|' , '#', '#' , '#' , '|' , '#' , '#' , '#' , '|' , '#' , '|'}
  22. , {'|' , '#' , '|' , '#' , '|' , '-' , '-' , '-' , '#' , '|' , '#', '|' , '#' , '|' , '#' , '-' , '-' , '|' , '#' , '|'}
  23. , {'|' , '#' , '|' , '#' , '|' , '#' , '#' , '#' , '#' , '|' , '#', '|' , '#' , '|' , '#' , '|' , '#' , '#' , '#' , '|'}
  24. , {'|' , '#' , '-' , '-' , '|' , '#' , '|' , '-' , '#' , '|' , '#', '|' , '#' , '|' , '#' , '-' , '-' , '#' , '-' , '|'}
  25. , {'|' , '#' , '#' , '#' , '|' , '#' , '|' , '#' , '#' , '|' , '#', '|' , '#' , '|' , '#' , '#' , '#' , '#' , '#' , '|'}
  26. , {'|' , '#' , '|' , '#' , '|' , '#' , '|' , '#' , '#' , '|' , '#', '|' , '#' , '|' , '-' , '-' , '-' , '-' , '#' , '|'}
  27. , {'|' , '#' , '|' , '#' , '#' , '#' , '|' , '#' , '#' , '|' , '#', '|' , '#' , '#' , '#' , '#' , '#' , '#' , '#' , '|'}
  28. , {'|' , '#' , '|' , '#' , '|' , '-' , '-' , '-' , '-' , '-' , '#', '|' , '#' , '|' , '-' , '-' , '-' , '-' , '#' , '|'}
  29. , {'|' , 'X' , '|' , '#' , '|' , '#' , '#' , '#' , '#' , '#' , '#', '|' , '#' , '|' , '#' , '#' , '#' , '#' , '#' , '|'}
  30. , {'-' , '-' , '-' , '-' , '-' , '-' , '-' , '-' , '-' , '-' , '-', '-' , '-' , '-' , '-' , '-' , '-' , '-' , '-' , '-'}};
  31.  
  32. void up(int &, int &); // pass the players position to all
  33. void down(int &, int &); // functions by reference
  34. void left(int &, int &);
  35. void right(int &, int &);
  36.  
  37. int main()
  38. {
  39. int playerX = 1; // variable to hold players x coord remember higher numbers move right
  40. int playerY = 18; // variable to hold players y coord remember higher numbers move down
  41. bool game = false; // bool to hold tell when the game is over
  42.  
  43. // at start of program clear the screen and output the map
  44. system("cls"); //clear screen
  45. for(int i=0; i<20; i++) // start display map
  46. {
  47. for(int j=0; j<20; j++)
  48. {
  49. cout << gameBoard[i][j];
  50. }
  51.  
  52. cout << endl;
  53. } // end display map
  54.  
  55. // You need to create a main game loop, anything that your game needs to do needs to take place
  56. // inside this loop
  57. // hint: You can use a do while loop, and it needs to include your display of the board,
  58. // a prompt to the user, a function call and a check to see if the game is won
  59. do
  60. {
  61. // inside the loop clear the screen and display the map again to start
  62. system("cls");
  63. for(int i=0; i<20; i++)
  64. {
  65. for(int j=0; j<20; j++)
  66. {
  67. cout << gameBoard[i][j];
  68. }
  69.  
  70. cout << endl;
  71. }
  72.  
  73. // After the board is displayed tell the player their current location and ask which
  74. // way they want to go and get their input
  75. cout << "Your current location is (" << playerX << "," << playerY << ")" << endl;
  76. cout << "Which way to you want to go? (Up = U, Down = D, Left = L, Right = R)" << endl;
  77. char UserMove;
  78. cin >> UserMove;
  79.  
  80. // Based off the input the user enters call one of the functions to move their player
  81. // in the desired direction
  82. UserMove = toupper(UserMove);
  83.  
  84. if(UserMove == 'U')
  85. {
  86. void up();
  87. }
  88. else if(UserMove == 'D')
  89. {
  90. void down();
  91. }
  92. else if(UserMove == 'L')
  93. {
  94. void left();
  95. }
  96. else if(UserMove == 'R')
  97. {
  98. void right();
  99. }
  100. else
  101. {
  102. cout << "You entered a invailed character, try again" << endl;
  103. //cin >> UserMove;
  104. }
  105.  
  106. // the last thing to do before the loop starts over is check if the player has won
  107. // ak the player position is the same as the end xy(1,4) or array[4][1]
  108. if(playerX == 1 && playerY == 4)
  109. {
  110. game = true;
  111. }
  112.  
  113. } // end do while loop
  114. while(game == false);
  115. // outside the loop make sure to tell the player they won
  116. system("cls");
  117. cout << "YOU WIN!!!" << endl;
  118.  
  119.  
  120. system("pause");
  121. return 0;
  122. } // end main
  123.  
  124.  
  125. void up() // function that moves the player in the up direction
  126. {
  127. // the first part of this function needs to check if the move is valid
  128. // make sure the space to be moved into is a '#' or the end 'O' not a wall
  129. // hint: use an If and check the next space == #
  130.  
  131. // If the move is vaild you need to replace the current space with a # and
  132. // place the players peice into the new square and change their coords
  133. // hint: vertical movement is controled in the first array
  134.  
  135.  
  136.  
  137. // If the move is bad tell the user
  138.  
  139.  
  140. } // end up()
  141.  
  142.  
  143. void down() // function that moves the player in the down direction
  144. {
  145. // the first part of this function needs to check if the move is valid
  146. // make sure the space to be moved into is a '#' not a wall
  147. // hint: use an If and check the next space == #
  148.  
  149.  
  150. // If the move is vaild you need to replace the current space with a # and
  151. // place the players peice into the new square
  152. // hint: vertical movement is controled in the first array
  153.  
  154.  
  155.  
  156. // If the move is bad tell the user
  157.  
  158.  
  159. } // end down()
  160.  
  161. void left() // function that moves the player in the left direction
  162. {
  163. // the first part of this function needs to check if the move is valid
  164. // make sure the space to be moved into is a '#' not a wall
  165. // hint: use an If and check the next space == #
  166.  
  167.  
  168. // If the move is vaild you need to replace the current space with a # and
  169. // place the players peice into the new square
  170. // hint: horizontal movement is controled in the second array
  171.  
  172.  
  173.  
  174.  
  175. // If the move is bad tell the user
  176.  
  177.  
  178.  
  179. } // end left()
  180.  
  181. void right() // function that moves the player in the right direction
  182. {
  183. // the first part of this function needs to check if the move is valid
  184. // make sure the space to be moved into is a '#' not a wall
  185. // hint: use an If and check the next space == #
  186.  
  187.  
  188.  
  189. // If the move is vaild you need to replace the current space with a # and
  190. // place the players peice into the new square
  191. // hint: horizontal movement is controled in the second array
  192.  
  193.  
  194.  
  195.  
  196. // If the move is bad tell the user
  197.  
  198.  
  199.  
  200. } // end right()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement