Guest User

Untitled

a guest
May 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #define MAXY 7
  5. #define MAXX 10
  6. #define MINM 0
  7.  
  8. bool drawBoard(char[][MAXY], int, int);
  9.  
  10. int main()
  11. {
  12. char board[MAXX][MAXY] = \
  13. {{'.','.','.','.','.','.','.'},\
  14. {'.','.','.','.','.','.','.'},\
  15. {'.','.','.','.','.','.','.'},\
  16. {'.','.','.','.','.','.','.'},\
  17. {'.','.','.','.','.','.','.'},\
  18. {'.','.','.','.','.','.','.'},\
  19. {'.','.','.','.','.','.','.'},\
  20. {'.','.','.','.','.','.','.'},\
  21. {'.','.','.','.','.','.','.'},\
  22. {'.','.','.','.','.','.','.'}};
  23.  
  24. int y=0;
  25. int x=0;
  26. bool win;
  27. bool lose;
  28. char playermove;
  29. int py=0;
  30. int px=0;
  31. int wy=5;
  32. int wx=8;
  33. int t1y=3;
  34. int t1x=3;
  35. int t2y=2;
  36. int t2x=5;
  37.  
  38. board[t1x][t1y] = 'T';
  39. board[t2x][t2y] = 'T';
  40. board[wx][wy] = 'W';
  41. while(!win)
  42. {
  43. drawBoard(board,px,py);
  44.  
  45. if ((py==wy)&&(px==wx))
  46. {
  47. win = true;
  48. }
  49.  
  50. if (( (py==t2y)&&(px==t2x) ) || ( (py==t1y) &&(px==t1x) ))
  51. {
  52. lose = true;
  53. }
  54.  
  55. if(win){break;}
  56. if(lose){break;}
  57.  
  58. cout<<"Which way would you like to move the character? (W/A/S/D)";
  59. cin>>playermove;
  60.  
  61. switch(playermove)
  62. {
  63. case 'W' : if (py>0) {py--;} else py=MAXY;break;
  64. case 'A' : if (px>0) {px--;} else px=MAXX; break;
  65. case 'S' : if (py<MAXY) {py++;} else py=0; break;
  66. case 'D' : if (px<MAXX){px++;} else px=0; break;
  67. default : cout <<"Error, please enter W/A/S/D \n";
  68. }
  69. }
  70.  
  71. if(win)
  72. {
  73. cout<<"You won! Great job!";
  74. }
  75.  
  76. if(lose)
  77. {
  78. cout<<"You lost, idiot!";
  79. }
  80.  
  81. return 0;
  82. }
  83.  
  84. bool drawBoard(char board[][MAXY], int px, int py)
  85. {
  86. for (int x = 0; x < MAXX; x++)
  87. {
  88. for (int y = 0; y < MAXY; y++)
  89. {
  90. cout<<(x==px&&y==py?'P':board[x][y]);
  91. }
  92. cout<<"\n";
  93. }
  94. }
Add Comment
Please, Sign In to add comment