Advertisement
Xenitho

Untitled

Apr 24th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. char board[8][8];
  6. short int playerx, playery; //Keeps track of the position of the player, p.
  7. short int i = 0, j = 0;
  8. char move;
  9.  
  10. int main()
  11. {
  12. while(i < 8) //Make a blank board
  13. {
  14. while(j < 8)
  15. {
  16. board[i][j] = '-';
  17. ++j;
  18. }
  19. j = 0;
  20. ++i;
  21. }
  22. board[0][0] = 'p'; //Put the player in the top corner.
  23. playerx = 0; //Player x is position is 0.
  24. playery = 0; //Player y position is 0.
  25. i = 0;
  26. while(1) //Infinite loop.THIS IS WHAT YOU WANT TO LOOK AT! ---------------------------------------------------------------------------
  27. {
  28. cin >> move;
  29. if(move == 'w' || move == 'W')//In case they have caps lock on, check for both.
  30. {
  31. if(playery == 0) //If we are already at the top of the board!
  32. {
  33. cout << "Already at board edge!" << endl; //We can't do this!
  34. }
  35. else //Otherwise
  36. {
  37. --playery; //We can move up the board one space.
  38. }
  39. }
  40. else if(move == 's' || move == 'S')//In case they have caps lock on, check for both.
  41. {
  42. if(playery == 7) //If we are already at the bottom of the board!
  43. {
  44. cout << "Already at board edge!" << endl; //We can't do this!
  45. }
  46. else //Otherwise
  47. {
  48. ++playery; //We can move down the board one space.
  49. }
  50. }
  51. else if(move == 'd' || move == 'D')//In case they have caps lock on, check for both.
  52. {
  53. if(playerx == 7) //If we are already at the left of the board!
  54. {
  55. cout << "Already at board edge!" << endl; //We can't do this!
  56. }
  57. else //Otherwise
  58. {
  59. ++playerx; //We can move across the board one space.
  60. }
  61. }
  62. else if(move == 'a' || move == 'A')//In case they have caps lock on, check for both.
  63. {
  64. if(playerx == 0) //If we are already at the edge of the board!
  65. {
  66. cout << "Already at board edge!" << endl; //We can't do this!
  67. }
  68. else //Otherwise
  69. {
  70. --playerx; //We can move across the board one space.
  71. }
  72. } //BELOW HERE IS JUST DRAWING ------------------------------------------------------------------------------------------------------
  73. i = 0;
  74. j = 0;
  75. while(i < 8) //Make a blank board
  76. {
  77. while(j < 8)
  78. {
  79. board[i][j] = '-';
  80. ++j;
  81. }
  82. j = 0;
  83. ++i;
  84. }
  85. board[playery][playerx] = 'p'; //Then OVERWRITE the square the player is in.
  86. i = 0;
  87. j = 0;
  88. while(i < 8)
  89. {
  90. while(j < 8)
  91. {
  92. cout << board[i][j] << " ";
  93. ++j;
  94. }
  95. cout << "\n\n";
  96. j = 0;
  97. ++i;
  98. }
  99. cout << "\n\n\n\n";
  100. }
  101. return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement