Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "Player.h"
- using namespace std;
- const int k_MazeWidth = 42;
- const int k_MazeHeight = 42;
- class Maze
- {
- public:
- int stepCounter;
- char maze[k_MazeWidth][k_MazeHeight]
- {
- { "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+" },
- { "| | | | | | | |-|" },
- { "+ +-+-+ +-+ + + + + +-+-+-+ + + +-+-+ + +" },
- { "| | | | | | | | | |" },
- { "+-+ + + + + +-+-+-+-+-+-+-+-+-+-+-+ + + +" },
- { "| | | | | | | | | |" },
- { "+ +-+ +-+ + + +-+-+-+-+ + +-+ + +-+-+ + +" },
- { "| | | | | | | | | | | | |" },
- { "+ + +-+ + +-+ +-+ + + + + + +-+-+ +-+-+-+" },
- { "| | | | | | | | |" },
- { "+-+-+ +-+-+-+-+ +-+-+ +-+-+ +-+-+ +-+ + +" },
- { "| | | | | | | | | | |" },
- { "+ + +-+ + +-+-+-+ + +-+ + +-+ + +-+ + + +" },
- { "| | | | | | | | | | | |" },
- { "+ +-+-+-+-+ + +-+-+ + +-+-+ + +-+-+-+ + +" },
- { "| | | | | | | | | | |" },
- { "+-+ +-+-+ +-+ + + + +-+ + +-+ +-+-+ +-+ +" },
- { "| | | | | | | | | | | | |" },
- { "+ +-+ + +-+ +-+ + + + +-+-+ + + + +-+ + +" },
- { "| | | | | | | | | | | | | | | |" },
- { "+-+ +-+ + +-+ +-+ + +-+ +-+ +-+ + + + + +" },
- { "| | | | | | | | | | |" },
- { "+ +-+ +-+-+-+-+ + + + + + + +-+-+-+-+-+-+" },
- { "| | | | | | | | | | | | |" },
- { "+ + +-+ + +-+ + + + + + +-+ + +-+-+ + +-+" },
- { "| | | | | | | | | | | | |" },
- { "+ + + + +-+ +-+-+-+-+ +-+ +-+-+-+-+ +-+ +" },
- { "| | | | | | | | | | | |" },
- { "+ + + +-+-+-+ +-+ + + + + + +-+-+ + + +-+" },
- { "| | | | | | | | |" },
- { "+-+ +-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+ +" },
- { "| | | | | | | | |" },
- { "+ +-+ + + + +-+ +-+ +-+-+ + +-+-+ +-+ + +" },
- { "| | | | | | | | | | | | |" },
- { "+ + + +-+-+-+ +-+-+-+ + +-+ +-+ +-+ + + +" },
- { "| | | | | | | | | | | |" },
- { "+ +-+ + +-+ +-+ +-+ +-+-+-+ + + + +-+-+ +" },
- { "| | | | | | | | | | | |" },
- { "+ + +-+ +-+-+ +-+ + + + + +-+ + + +-+ + +" },
- { "| | | | | | | | |" },
- { "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+" }
- };
- void DrawMaze(Player *player, int goalX, int goalY)
- {
- for (int i = 0; i < k_MazeHeight; i++) // First dimension loop.
- {
- for (int j = 0; j < k_MazeWidth; j++) // Second dimension loop.
- {
- if (j == player->GetX() && i == player->GetY)
- {
- cout << "@";
- }
- else if (j == goalX && i == goalY)
- {
- cout << "X";
- }
- else
- {
- cout << maze[i][j]; // Use both loop variables.
- }
- }
- cout << endl; // Print a newline character so we get a nice matrix.
- }
- }
- bool CheckCollision(char userInput, Player *player)
- {
- if (userInput == 'd')
- {
- // Check if the slope besides the player x is blank
- if (maze[player->GetY()][player->GetX() + 1] == ' ')
- {
- // Update player position
- player->SetX(player->GetX() + 1); //right 1 space
- stepCounter++; // this will count steps ONLY when d is pressed by the user AND if the space is blank.
- }
- else
- {
- maze[player->GetY()][player->GetX()]; //wall
- }
- }
- else if (userInput == 'a')
- {
- // Check if the slope besides the player x is blank
- if (maze[player->GetY()][player->GetX() - 1] == ' ')
- {
- player->SetX(player->GetX() - 1); //left 1 space
- stepCounter++; // this will count steps ONLY when a is pressed by the user AND if the space is blank.
- }
- else
- {
- maze[player->GetY()][player->GetX()]; //wall
- }
- }
- else if (userInput == 'w')
- {
- // Check if the slope besides the player y is blank
- if (maze[player->GetY() - 1][player->GetX()] == ' ')
- {
- player->SetY(player->GetY() - 1); //up 1 space
- stepCounter++; // this will count steps ONLY when w is pressed by the user AND if the space is blank.
- }
- else
- {
- maze[player->GetY()][player->GetX()]; //wall
- }
- }
- else if (userInput == 's')
- {
- // Check if the slope besides the player y is blank
- if (maze[player->GetY() + 1][player->GetX()] == ' ')
- {
- player->SetY(player->GetY + 1); //down 1 space
- stepCounter++; // this will count steps ONLY when s is pressed by the user AND if the space is blank.
- }
- else
- {
- maze[player->GetY()][player->GetX()]; //wall
- }
- }
- }
- private:
- int i, j;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement