Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<conio.h>
- #include<fstream>
- #include<stdlib.h>
- using namespace std;
- char map[20][20];
- char input;
- int x = 5;
- int y = 5;
- char chinput = 'v';
- int main() {
- fstream mapfile;
- mapfile.open("mapfile.txt",ios::in);
- for(int xx = 0; xx < 20; xx++) {
- for(int yy = 0; yy < 20; y++)
- mapfile >> map[xx][yy];
- }
- while(true) {
- system("cls");
- for(int xx = 0; xx < 20; xx++) {
- for(int yy = 0; yy < 20; y++)
- cout << map[xx][yy];
- cout << endl;
- }
- map[x][y] = '@';
- input = _getch();
- switch(input) {
- case 'd':
- if(map[y+1][x] == 'G') {
- cout << "YOU REACHED THE GOAL!" << endl;
- cin.get();
- cin.get();
- }
- if(map[y+1][x] != ' ') break;
- map[y][x] = ' ';
- y++;
- map[y][x] = '@';
- break;
- case 'a':
- if(map[y-1][x] == 'G') {
- cout << "YOU REACHED THE GOAL!" << endl;
- cin.get();
- cin.get();
- }
- if(map[y-1][x] != ' ') break;
- map[y][x] = ' ';
- y--;
- map[y][x] = '@';
- break;
- case 'w':
- if(map[y][x+1] == 'G') {
- cout << "YOU REACHED THE GOAL!" << endl;
- cin.get();
- cin.get();
- }
- if(map[y][x+1] != ' ') break;
- map[y][x] = ' ';
- x++;
- map[y][x] = '@';
- break;
- case 's':
- if(map[y][x-1] == 'G') {
- cout << "YOU REACHED THE GOAL!" << endl;
- cin.get();
- cin.get();
- }
- if(map[y][x-1] != ' ') break;
- map[y][x] = ' ';
- x--;
- map[y][x] = '@';
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement