Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #define SIZE 19
  4.  
  5. using namespace std;
  6.  
  7. char Maze_1 [SIZE][SIZE] = {
  8. {'S',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*'}, //1
  9. {'*',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*'},
  10. {'*',' ','*',' ','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*','*'},
  11. {'*',' ',' ',' ','*',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*'},
  12. {'*',' ','*','*','*',' ','*','*','*','*','*','*','*','*','*',' ','*',' ','*'},
  13. {'*',' ','*',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ','*',' ','*',' ','*'},
  14. {'*',' ','*','*','*','*','*',' ','*','*','*','*','*',' ','*','*','*',' ','*'},
  15. {'*',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ','*',' ','*',' ',' ',' ','*'},
  16. {'*','*','*',' ','*',' ','*','*','*','*','*',' ','*',' ','*',' ','*',' ','*'},
  17. {'*',' ',' ',' ','*',' ','*',' ',' ',' ','*',' ','*',' ','*',' ','*',' ','*'},
  18. {'*','*','*',' ','*',' ','*',' ','*',' ','*',' ','*',' ','*',' ','*',' ','*'},
  19. {'*',' ',' ',' ','*',' ',' ',' ','*',' ','*',' ','*',' ',' ',' ','*',' ','*'},
  20. {'*',' ','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*'},
  21. {'*',' ',' ',' ',' ',' ',' ',' ','*',' ','*',' ',' ',' ',' ',' ',' ',' ','*'},
  22. {'*','*','*','*','*',' ','*',' ','*',' ','*',' ','*','*','*','*','*',' ','*'},
  23. {'*',' ',' ',' ','*',' ','*',' ','*',' ',' ',' ','*',' ',' ',' ','*',' ','*'},
  24. {'*',' ','*','*','*',' ','*',' ','*','*','*','*','*',' ','*',' ','*',' ','*'},
  25. {'*',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ','*',' ','*',' ',' '},
  26. {'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','E'}
  27. };
  28.  
  29.  
  30. class Maze{
  31. public:
  32. void draw_Maze(){
  33. cout << "\n\tWELCOME TO THE MAZE RUNNER 9.8.7\n" << endl;
  34. for(int i = 0; i < SIZE; i++){
  35. for(int j = 0; j < SIZE; j++){
  36. cout << Maze_1 [i][j];
  37. }
  38. cout << " " << endl;
  39. }
  40. }
  41. //print maze // row col sym
  42. void print_Maze(int energy = 10){
  43. for(int i = 0; i < SIZE; i++){
  44. for( int j = 0; j < SIZE; j++){
  45. cout << Maze_1 [i][j];
  46. }
  47. cout << " " << endl;
  48. }
  49. cout << "Energy of the hero: ";
  50. cout << energy << endl;
  51. }
  52.  
  53.  
  54. private:
  55. char sym;
  56. int row,col;
  57. };
  58.  
  59. class Hero : public Maze{
  60. public:
  61. //Hero stands at the position by default
  62. Hero(){
  63. cout << "Please enter the starting position of Hero: ";
  64. cin >> row >> col;
  65. Hsym = 'H';
  66. energy = 10;
  67. Maze_1[row][col] = Hsym;
  68. }
  69. int Move(){
  70. cout << "W,A,S or D to move: ";
  71. cin >> move;
  72. cout << " " << endl;
  73.  
  74. if(move == 'W' || move == 'w'){
  75. row--;
  76. if(row >= 0 && row < SIZE && col >= 0 && col < SIZE){
  77. if(Maze_1[row][col] != '*'){
  78. Maze_1[row][col] = Hsym;
  79. Maze_1[row + 1][col] = ' ';
  80. energy--;
  81. }else{
  82. row++;
  83. Maze_1[row][col] = Hsym;
  84. }
  85. }
  86. else{
  87. row++;
  88. Maze_1[row][col] = Hsym;
  89. }
  90. }
  91.  
  92. if(move == 's' || move == 'S'){
  93. row++;
  94. if(row >= 0 && row < SIZE && col >= 0 && col < SIZE){
  95. if(Maze_1[row][col] != '*'){
  96. Maze_1[row][col] = Hsym;
  97. Maze_1[row - 1][col] = ' ';
  98. energy--;
  99. }else{
  100. row--;
  101. Maze_1[row][col] = Hsym;
  102. }
  103. }else{
  104. row--;
  105. Maze_1[row][col] = Hsym;
  106. }
  107. }
  108.  
  109. if(move == 'a' || move == 'A'){
  110. col--;
  111. if(col >= 0 && col < SIZE && row >= 0 && row < SIZE){
  112. if(Maze_1[row][col] != '*'){
  113. Maze_1[row][col] = Hsym;
  114. Maze_1[row][col + 1] = ' ';
  115. energy--;
  116. }else{
  117. col++;
  118. Maze_1[row][col] = Hsym;
  119. }
  120. }else{
  121. col++;
  122. Maze_1[row][col] = Hsym;
  123. }
  124. }
  125.  
  126. if(move == 'D' || move == 'd'){
  127. col++;
  128. if(col >= 0 && col < SIZE && row >= 0 && row < SIZE){
  129. if(Maze_1[row][col] != '*'){
  130. Maze_1[row][col] = Hsym;
  131. Maze_1[row ][col - 1] = ' ';
  132. energy--;
  133. }else{
  134. col--;
  135. Maze_1[row][col] = Hsym;
  136. }
  137. }else{
  138. col--;
  139. Maze_1[row][col] = Hsym;
  140. }
  141. }
  142. return energy;
  143. }
  144.  
  145. /*int energy_Level(char sym){
  146. if(sym == '+'){
  147. energy++;
  148. }
  149. else if(sym == '-'){
  150. energy--;
  151. }
  152. return energy;
  153. }*/
  154.  
  155. private:
  156. char Hsym;
  157. int row;
  158. int col;
  159. char move;
  160.  
  161. protected:
  162. int energy;
  163. };
  164.  
  165.  
  166.  
  167.  
  168.  
  169. int main(){
  170. int energy;
  171. char move;
  172.  
  173.  
  174. Maze p1; // starting position of Hero
  175. p1.draw_Maze();
  176. Hero p2;
  177. system("cls");
  178. p2.print_Maze();
  179.  
  180. while(1){
  181. energy = p2.Move();
  182. system("cls");
  183. p2.print_Maze(energy);
  184. if(energy == 0){
  185. cout << "The Hero dies!!!!" << endl;
  186. break;
  187. }
  188. }
  189.  
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement