Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define MAXY 7
- #define MAXX 10
- #define MINM 0
- bool drawBoard(char[][MAXY], int, int);
- int main()
- {
- char board[MAXX][MAXY] = \
- {{'.','.','.','.','.','.','.'},\
- {'.','.','.','.','.','.','.'},\
- {'.','.','.','.','.','.','.'},\
- {'.','.','.','.','.','.','.'},\
- {'.','.','.','.','.','.','.'},\
- {'.','.','.','.','.','.','.'},\
- {'.','.','.','.','.','.','.'},\
- {'.','.','.','.','.','.','.'},\
- {'.','.','.','.','.','.','.'},\
- {'.','.','.','.','.','.','.'}};
- int y=0;
- int x=0;
- bool win;
- bool lose;
- char playermove;
- int py=0;
- int px=0;
- int wy=5;
- int wx=8;
- int t1y=3;
- int t1x=3;
- int t2y=2;
- int t2x=5;
- board[t1x][t1y] = 'T';
- board[t2x][t2y] = 'T';
- board[wx][wy] = 'W';
- while(!win)
- {
- drawBoard(board,px,py);
- if ((py==wy)&&(px==wx))
- {
- win = true;
- }
- if (( (py==t2y)&&(px==t2x) ) || ( (py==t1y) &&(px==t1x) ))
- {
- lose = true;
- }
- if(win){break;}
- if(lose){break;}
- cout<<"Which way would you like to move the character? (W/A/S/D)";
- cin>>playermove;
- switch(playermove)
- {
- case 'W' : if (py>0) {py--;} else py=MAXY;break;
- case 'A' : if (px>0) {px--;} else px=MAXX; break;
- case 'S' : if (py<MAXY) {py++;} else py=0; break;
- case 'D' : if (px<MAXX){px++;} else px=0; break;
- default : cout <<"Error, please enter W/A/S/D \n";
- }
- }
- if(win)
- {
- cout<<"You won! Great job!";
- }
- if(lose)
- {
- cout<<"You lost, idiot!";
- }
- return 0;
- }
- bool drawBoard(char board[][MAXY], int px, int py)
- {
- for (int x = 0; x < MAXX; x++)
- {
- for (int y = 0; y < MAXY; y++)
- {
- cout<<(x==px&&y==py?'P':board[x][y]);
- }
- cout<<"\n";
- }
- }
Add Comment
Please, Sign In to add comment