kellex

testgamelinux c++

Jul 20th, 2013
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h> //library includes
  3. using namespace std;
  4. //variables
  5. int lvl = 0;
  6. char map[10][20][40]; //3D array: one dimension for rooms, one dimension width % height
  7. int hp = 10;
  8. int hpmax = 10;
  9. int main(){ //main function
  10. char input; //our input variable
  11. int x = 7; //our movement variables
  12. int y = 7;
  13.     for(int gx = 0; gx <= 20; gx++){
  14.     for(int gy = 0; gy <= 20; gy++)
  15.     map[0][gy][gx] = 'x';
  16.     } //nested for loop to generate x and y and plot it to our map
  17.     for(int ey = 3; ey <= 17; ey++){
  18.     for(int ex = 3; ex <= 17; ex++)
  19.     map[0][ey][ex] = ' ';
  20.     } //another nested for loop to fill spaces to our map
  21.     map[0][11][11] = '#';
  22.     map[0][15][14] = '#';
  23.     map[0][4][4] = '#';
  24.     map[0][16][16] = 'E';
  25.     map[0][7][7] = '@';
  26.    
  27.     for(int gx = 0; gx <= 20; gx++){
  28.     for(int gy = 0; gy <= 20; gy++)
  29.     map[1][gy][gx] = 'x';
  30.     } //for the second map
  31.     for(int ey = 3; ey <= 17; ey++){
  32.     for(int ex = 3; ex <= 17; ex++)
  33.     map[1][ey][ex] = ' ';
  34.     }
  35.     map[1][6][11] = '#';
  36.     map[1][7][14] = '#';
  37.     map[1][7][9] = '#';
  38.     map[1][3][3] = 'E';
  39.     while(1){
  40.              system("cls"); //Clear the screen....
  41.              for(int row = 0; row <= 20; row++){
  42.              for(int col = 0; col <= 20; col++)
  43.              cout << map[lvl][col][row];
  44.              cout << endl;
  45.              } //output the map
  46.              cin >> input; //input
  47.              //movement
  48.              switch(input){
  49.                            case 'd':
  50.                                 if(map[lvl][y+1][x] == 'x') break; //break if y+1 is x
  51.                                 if(map[lvl][y+1][x] == 'E') lvl += 1; //go to next level lvl
  52.                                 map[lvl][y][x] = ' '; //fill in a space for now
  53.                                 y += 1; //increment it
  54.                                 map[lvl][y][x] = '@'; //then put a @ un the movement
  55.                                 break; //then break, otherwise ot would do all of them
  56.                            case 'a':
  57.                                 if(map[lvl][y-1][x] == 'x') break;
  58.                                 if(map[lvl][y-1][x] == 'E') lvl += 1;
  59.                                 map[lvl][y][x] = ' ';
  60.                                 y -= 1;
  61.                                 map[lvl][y][x] = '@';
  62.                                 break;
  63.                            case 's':
  64.                                 if(map[lvl][y][x+1] == 'x') break;
  65.                                 if(map[lvl][y][x+1] == 'E') lvl += 1;
  66.                                 map[lvl][y][x] = ' ';
  67.                                 x += 1;
  68.                                 map[lvl][y][x] = '@';
  69.                                 break;
  70.                            case 'w':
  71.                                 if(map[lvl][y][x-1] == 'x') break;
  72.                                 if(map[lvl][y][x-1] == 'E') lvl += 1;
  73.                                 map[lvl][y][x] = ' ';
  74.                                 x -= 1;
  75.                                 map[lvl][y][x] = '@';
  76.                                 break;
  77.                             }
  78.                         }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment