Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h> //library includes
- using namespace std;
- //variables
- int lvl = 0;
- char map[10][20][40]; //3D array: one dimension for rooms, one dimension width % height
- int hp = 10;
- int hpmax = 10;
- int main(){ //main function
- char input; //our input variable
- int x = 7; //our movement variables
- int y = 7;
- for(int gx = 0; gx <= 20; gx++){
- for(int gy = 0; gy <= 20; gy++)
- map[0][gy][gx] = 'x';
- } //nested for loop to generate x and y and plot it to our map
- for(int ey = 3; ey <= 17; ey++){
- for(int ex = 3; ex <= 17; ex++)
- map[0][ey][ex] = ' ';
- } //another nested for loop to fill spaces to our map
- map[0][11][11] = '#';
- map[0][15][14] = '#';
- map[0][4][4] = '#';
- map[0][16][16] = 'E';
- map[0][7][7] = '@';
- for(int gx = 0; gx <= 20; gx++){
- for(int gy = 0; gy <= 20; gy++)
- map[1][gy][gx] = 'x';
- } //for the second map
- for(int ey = 3; ey <= 17; ey++){
- for(int ex = 3; ex <= 17; ex++)
- map[1][ey][ex] = ' ';
- }
- map[1][6][11] = '#';
- map[1][7][14] = '#';
- map[1][7][9] = '#';
- map[1][3][3] = 'E';
- while(1){
- system("cls"); //Clear the screen....
- for(int row = 0; row <= 20; row++){
- for(int col = 0; col <= 20; col++)
- cout << map[lvl][col][row];
- cout << endl;
- } //output the map
- cin >> input; //input
- //movement
- switch(input){
- case 'd':
- if(map[lvl][y+1][x] == 'x') break; //break if y+1 is x
- if(map[lvl][y+1][x] == 'E') lvl += 1; //go to next level lvl
- map[lvl][y][x] = ' '; //fill in a space for now
- y += 1; //increment it
- map[lvl][y][x] = '@'; //then put a @ un the movement
- break; //then break, otherwise ot would do all of them
- case 'a':
- if(map[lvl][y-1][x] == 'x') break;
- if(map[lvl][y-1][x] == 'E') lvl += 1;
- map[lvl][y][x] = ' ';
- y -= 1;
- map[lvl][y][x] = '@';
- break;
- case 's':
- if(map[lvl][y][x+1] == 'x') break;
- if(map[lvl][y][x+1] == 'E') lvl += 1;
- map[lvl][y][x] = ' ';
- x += 1;
- map[lvl][y][x] = '@';
- break;
- case 'w':
- if(map[lvl][y][x-1] == 'x') break;
- if(map[lvl][y][x-1] == 'E') lvl += 1;
- map[lvl][y][x] = ' ';
- x -= 1;
- map[lvl][y][x] = '@';
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment