Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #define SIZE 19
- using namespace std;
- char Maze_1 [SIZE][SIZE] = {
- {'S',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*'}, //1
- {'*',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*'},
- {'*',' ','*',' ','*','*','*',' ','*',' ','*','*','*','*','*','*','*','*','*'},
- {'*',' ',' ',' ','*',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*'},
- {'*',' ','*','*','*',' ','*','*','*','*','*','*','*','*','*',' ','*',' ','*'},
- {'*',' ','*',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ','*',' ','*',' ','*'},
- {'*',' ','*','*','*','*','*',' ','*','*','*','*','*',' ','*','*','*',' ','*'},
- {'*',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ','*',' ','*',' ',' ',' ','*'},
- {'*','*','*',' ','*',' ','*','*','*','*','*',' ','*',' ','*',' ','*',' ','*'},
- {'*',' ',' ',' ','*',' ','*',' ',' ',' ','*',' ','*',' ','*',' ','*',' ','*'},
- {'*','*','*',' ','*',' ','*',' ','*',' ','*',' ','*',' ','*',' ','*',' ','*'},
- {'*',' ',' ',' ','*',' ',' ',' ','*',' ','*',' ','*',' ',' ',' ','*',' ','*'},
- {'*',' ','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*','*'},
- {'*',' ',' ',' ',' ',' ',' ',' ','*',' ','*',' ',' ',' ',' ',' ',' ',' ','*'},
- {'*','*','*','*','*',' ','*',' ','*',' ','*',' ','*','*','*','*','*',' ','*'},
- {'*',' ',' ',' ','*',' ','*',' ','*',' ',' ',' ','*',' ',' ',' ','*',' ','*'},
- {'*',' ','*','*','*',' ','*',' ','*','*','*','*','*',' ','*',' ','*',' ','*'},
- {'*',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ','*',' ','*',' ',' '},
- {'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','E'}
- };
- class Maze{
- public:
- void draw_Maze(){
- cout << "\n\tWELCOME TO THE MAZE RUNNER 9.8.7\n" << endl;
- for(int i = 0; i < SIZE; i++){
- for(int j = 0; j < SIZE; j++){
- cout << Maze_1 [i][j];
- }
- cout << " " << endl;
- }
- }
- //print maze // row col sym
- void print_Maze(int energy = 10){
- for(int i = 0; i < SIZE; i++){
- for( int j = 0; j < SIZE; j++){
- cout << Maze_1 [i][j];
- }
- cout << " " << endl;
- }
- cout << "Energy of the hero: ";
- cout << energy << endl;
- }
- private:
- char sym;
- int row,col;
- };
- class Hero : public Maze{
- public:
- //Hero stands at the position by default
- Hero(){
- cout << "Please enter the starting position of Hero: ";
- cin >> row >> col;
- Hsym = 'H';
- energy = 10;
- Maze_1[row][col] = Hsym;
- }
- int Move(){
- cout << "W,A,S or D to move: ";
- cin >> move;
- cout << " " << endl;
- if(move == 'W' || move == 'w'){
- row--;
- if(row >= 0 && row < SIZE && col >= 0 && col < SIZE){
- if(Maze_1[row][col] != '*'){
- Maze_1[row][col] = Hsym;
- Maze_1[row + 1][col] = ' ';
- energy--;
- }else{
- row++;
- Maze_1[row][col] = Hsym;
- }
- }
- else{
- row++;
- Maze_1[row][col] = Hsym;
- }
- }
- if(move == 's' || move == 'S'){
- row++;
- if(row >= 0 && row < SIZE && col >= 0 && col < SIZE){
- if(Maze_1[row][col] != '*'){
- Maze_1[row][col] = Hsym;
- Maze_1[row - 1][col] = ' ';
- energy--;
- }else{
- row--;
- Maze_1[row][col] = Hsym;
- }
- }else{
- row--;
- Maze_1[row][col] = Hsym;
- }
- }
- if(move == 'a' || move == 'A'){
- col--;
- if(col >= 0 && col < SIZE && row >= 0 && row < SIZE){
- if(Maze_1[row][col] != '*'){
- Maze_1[row][col] = Hsym;
- Maze_1[row][col + 1] = ' ';
- energy--;
- }else{
- col++;
- Maze_1[row][col] = Hsym;
- }
- }else{
- col++;
- Maze_1[row][col] = Hsym;
- }
- }
- if(move == 'D' || move == 'd'){
- col++;
- if(col >= 0 && col < SIZE && row >= 0 && row < SIZE){
- if(Maze_1[row][col] != '*'){
- Maze_1[row][col] = Hsym;
- Maze_1[row ][col - 1] = ' ';
- energy--;
- }else{
- col--;
- Maze_1[row][col] = Hsym;
- }
- }else{
- col--;
- Maze_1[row][col] = Hsym;
- }
- }
- return energy;
- }
- /*int energy_Level(char sym){
- if(sym == '+'){
- energy++;
- }
- else if(sym == '-'){
- energy--;
- }
- return energy;
- }*/
- private:
- char Hsym;
- int row;
- int col;
- char move;
- protected:
- int energy;
- };
- int main(){
- int energy;
- char move;
- Maze p1; // starting position of Hero
- p1.draw_Maze();
- Hero p2;
- system("cls");
- p2.print_Maze();
- while(1){
- energy = p2.Move();
- system("cls");
- p2.print_Maze(energy);
- if(energy == 0){
- cout << "The Hero dies!!!!" << endl;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement