Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- void draw(string map[17][5]);
- string input = "";
- string wallTile = "#";
- string spaceTile = ".";
- string stickTile = "-";
- string playerTile = "@";
- int playerX = 5;
- int playerY = 3;
- int stickX = 6;
- int stickY = 1;
- string map[17][5];
- int score = 0;
- //"Background" Tiles
- //first row
- for(int x = 0 ; x < 17 ; x++)
- {
- map[x][0] = wallTile;
- }
- //second row
- map[0][1] = wallTile;
- map[16][1] = wallTile;
- for(int x = 1 ; x < 16 ; x++)
- {
- map[x][1] = spaceTile;
- }
- //third row
- map[0][2] = wallTile;
- map[16][2] = wallTile;
- for(int x = 1 ; x <16 ; x++)
- {
- map[x][2] = spaceTile;
- }
- //fourth row
- map[0][3] = wallTile;
- map[16][3] = wallTile;
- for(int x = 1 ; x < 16 ; x++)
- {
- map[x][3] = spaceTile;
- }
- //fifth row
- for(int x = 0 ; x < 17 ; x++)
- {
- map[x][4] = wallTile;
- }
- //"Foreground" Tiles
- map[playerX][playerY] = playerTile;
- map[stickX][stickY] = stickTile;
- while(input.compare("Exit") !=0 )
- {
- //Redraw map
- draw(map);
- //Get Input
- cout << "Enter a direction: ";
- getline(cin, input);
- //Validate
- while(input.compare("East")!=0
- && input.compare("West")!=0
- && input.compare("North")!=0
- && input.compare("South")!=0
- && input.compare("Exit")!=0)
- {
- cout << "Enter a direction: ";
- getline(cin, input);
- }
- //Update
- if(input.compare("East") == 0)
- {
- playerX++;
- //collision with wall
- if( playerX ==0 ||
- playerX == 16 ||
- playerY == 0 ||
- playerY == 4)
- {
- playerX--;
- }
- // collision with stick
- else if ( playerX == stickX &&
- playerY == stickY)
- {
- score++;
- cout << "Score: " << score << endl;
- stickX = rand()%14 + 1;
- stickY = rand()%2 + 1;
- map[stickX][stickY] = stickTile;
- map[playerX][playerY] = playerTile;
- map[playerX - 1][playerY] = spaceTile;
- }
- else
- {
- map[playerX][playerY] = playerTile;
- map[playerX - 1][playerY] = spaceTile;
- }
- }
- if(input.compare("West") == 0)
- {
- playerX--;
- //collision with wall
- if( playerX ==0 ||
- playerX == 16 ||
- playerY == 0 ||
- playerY == 4)
- {
- playerX++;
- }
- // collision with stick
- else if ( playerX == stickX &&
- playerY == stickY)
- {
- score++;
- cout << "Score: " << score << endl;
- stickX = rand()%14 + 1;
- stickY = rand()%2 + 1;
- map[stickX][stickY] = stickTile;
- map[playerX][playerY] = playerTile;
- map[playerX + 1][playerY] = spaceTile;
- }
- else
- {
- map[playerX][playerY] = playerTile;
- map[playerX + 1][playerY] = spaceTile;
- }
- }
- if(input.compare("North") == 0)
- {
- playerY--;
- //collision with wall
- if( playerX ==0 ||
- playerX == 16 ||
- playerY == 0 ||
- playerY == 4)
- {
- playerY++;
- }
- // collision with stick
- else if ( playerX == stickX &&
- playerY == stickY)
- {
- score++;
- cout << "Score: " << score << endl;
- stickX = rand()%14 + 1;
- stickY = rand()%2 + 1;
- map[stickX][stickY] = stickTile;
- map[playerX][playerY] = playerTile;
- map[playerX][playerY + 1] = spaceTile;
- }
- else
- {
- map[playerX][playerY] = playerTile;
- map[playerX][playerY + 1] = spaceTile;
- }
- }
- if(input.compare("South") == 0)
- {
- playerY++;
- //collision with wall
- if( playerX ==0 ||
- playerX == 16 ||
- playerY == 0 ||
- playerY == 4)
- {
- playerY++;
- }
- // collision with stick
- else if ( playerX == stickX &&
- playerY == stickY)
- {
- score++;
- cout << "Score: " << score << endl;
- stickX = rand()%14 + 1;
- stickY = rand()%2 + 1;
- map[stickX][stickY] = stickTile;
- map[playerX][playerY] = playerTile;
- map[playerX][playerY - 1] = spaceTile;
- }
- else
- {
- map[playerX][playerY] = playerTile;
- map[playerX][playerY - 1] = spaceTile;
- }
- }
- }
- }
- void draw(string map[17][5])
- {
- for(int y = 0 ; y < 5 ; y++)
- {
- for(int x = 0; x < 17 ; x++)
- {
- cout << map[x][y];
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement