Advertisement
Guest User

Untitled

a guest
May 8th, 2013
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3. #include<fstream>
  4. #include<stdlib.h>
  5. using namespace std;
  6. char map[20][20];
  7. char input;
  8. int x = 5;
  9. int y = 5;
  10. char chinput = 'v';
  11. int main() {
  12.     fstream mapfile;
  13.     mapfile.open("mapfile.txt",ios::in);
  14.     for(int xx = 0; xx < 20; xx++) {
  15.         for(int yy = 0; yy < 20; y++)
  16.             mapfile >> map[xx][yy];
  17.     }
  18.     while(true) {
  19.         system("cls");
  20.         for(int xx = 0; xx < 20; xx++) {
  21.             for(int yy = 0; yy < 20; y++)
  22.                 cout << map[xx][yy];
  23.                 cout << endl;
  24.         }
  25.         map[x][y] = '@';
  26.         input = _getch();
  27.         switch(input) {
  28.         case 'd':
  29.             if(map[y+1][x] == 'G') {
  30.                 cout << "YOU REACHED THE GOAL!" << endl;
  31.                 cin.get();
  32.                 cin.get();
  33.             }
  34.             if(map[y+1][x] != ' ') break;
  35.             map[y][x] = ' ';
  36.             y++;
  37.             map[y][x] = '@';
  38.             break;
  39.         case 'a':
  40.             if(map[y-1][x] == 'G') {
  41.                 cout << "YOU REACHED THE GOAL!" << endl;
  42.                 cin.get();
  43.                 cin.get();
  44.             }
  45.             if(map[y-1][x] != ' ') break;
  46.             map[y][x] = ' ';
  47.             y--;
  48.             map[y][x] = '@';
  49.             break;
  50.         case 'w':
  51.             if(map[y][x+1] == 'G') {
  52.                 cout << "YOU REACHED THE GOAL!" << endl;
  53.                 cin.get();
  54.                 cin.get();
  55.             }
  56.             if(map[y][x+1] != ' ') break;
  57.             map[y][x] = ' ';
  58.             x++;
  59.             map[y][x] = '@';
  60.             break;
  61.         case 's':
  62.             if(map[y][x-1] == 'G') {
  63.                 cout << "YOU REACHED THE GOAL!" << endl;
  64.                 cin.get();
  65.                 cin.get();
  66.             }
  67.             if(map[y][x-1] != ' ') break;
  68.             map[y][x] = ' ';
  69.             x--;
  70.             map[y][x] = '@';
  71.             break;
  72.         }
  73.     }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement