Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- char board[8][8];
- short int playerx, playery; //Keeps track of the position of the player, p.
- short int i = 0, j = 0;
- char move;
- int main()
- {
- while(i < 8) //Make a blank board
- {
- while(j < 8)
- {
- board[i][j] = '-';
- ++j;
- }
- j = 0;
- ++i;
- }
- board[0][0] = 'p'; //Put the player in the top corner.
- playerx = 0; //Player x is position is 0.
- playery = 0; //Player y position is 0.
- i = 0;
- while(1) //Infinite loop.THIS IS WHAT YOU WANT TO LOOK AT! ---------------------------------------------------------------------------
- {
- cin >> move;
- if(move == 'w' || move == 'W')//In case they have caps lock on, check for both.
- {
- if(playery == 0) //If we are already at the top of the board!
- {
- cout << "Already at board edge!" << endl; //We can't do this!
- }
- else //Otherwise
- {
- --playery; //We can move up the board one space.
- }
- }
- else if(move == 's' || move == 'S')//In case they have caps lock on, check for both.
- {
- if(playery == 7) //If we are already at the bottom of the board!
- {
- cout << "Already at board edge!" << endl; //We can't do this!
- }
- else //Otherwise
- {
- ++playery; //We can move down the board one space.
- }
- }
- else if(move == 'd' || move == 'D')//In case they have caps lock on, check for both.
- {
- if(playerx == 7) //If we are already at the left of the board!
- {
- cout << "Already at board edge!" << endl; //We can't do this!
- }
- else //Otherwise
- {
- ++playerx; //We can move across the board one space.
- }
- }
- else if(move == 'a' || move == 'A')//In case they have caps lock on, check for both.
- {
- if(playerx == 0) //If we are already at the edge of the board!
- {
- cout << "Already at board edge!" << endl; //We can't do this!
- }
- else //Otherwise
- {
- --playerx; //We can move across the board one space.
- }
- } //BELOW HERE IS JUST DRAWING ------------------------------------------------------------------------------------------------------
- i = 0;
- j = 0;
- while(i < 8) //Make a blank board
- {
- while(j < 8)
- {
- board[i][j] = '-';
- ++j;
- }
- j = 0;
- ++i;
- }
- board[playery][playerx] = 'p'; //Then OVERWRITE the square the player is in.
- i = 0;
- j = 0;
- while(i < 8)
- {
- while(j < 8)
- {
- cout << board[i][j] << " ";
- ++j;
- }
- cout << "\n\n";
- j = 0;
- ++i;
- }
- cout << "\n\n\n\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement