Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- #include<conio.h>
- using namespace std;
- int main()
- {
- int life = 3;
- int minx = 0;
- int miny = 0;
- int maxx = 25;
- int maxy = 15;
- int treasurex = 10;
- int treasurey = 10;
- int playerx = 0;
- int playery = 0;
- int trap1x = 5;
- int trap1y = 5;
- int trap2x = 15;
- int trap2y = 5;
- int trap3x = 5;
- int trap3y = 10;
- int trap4x = 15;
- int trap4y = 10;
- int lifeaddx = 10;
- int lifeaddy = 5;
- int key = '\0';
- cout << "Welcome to the game" << endl;
- cout << "You are at position (0,0)" << endl;
- cout << "Enter 'w' to move up, 's' to move down, 'a' to move left, 'd' to move right" << endl;
- cout << "Enter 'q' to quit the game" << endl;
- system("pause");
- system("cls");
- while (1) {
- key = _getch();
- switch (key) {
- case 'w':
- if (playery > miny) {
- playery--;
- }
- break;
- case 's':
- if (playery < maxy) {
- playery++;
- }
- break;
- case 'a':
- if (playerx > minx) {
- playerx--;
- }
- break;
- case 'd':
- if (playerx < maxx) {
- playerx++;
- }
- break;
- case 'q':
- cout << "You quit the game" << endl;
- exit(0);
- }
- cout << "You are at position (" << playerx << "," << playery << ")" << endl;
- if (playerx == treasurex && playery == treasurey) {
- cout << "You found the treasure" << endl;
- cout << "You win the game" << endl;
- exit(0);
- }
- if (playerx == trap1x && playery == trap1y) {
- cout << "You are caught in trap 1" << endl;
- life--;
- }
- if (playerx == trap2x && playery == trap2y) {
- cout << "You are caught in trap 2" << endl;
- life--;
- }
- if (playerx == trap3x && playery == trap3y) {
- cout << "You are caught in trap 3" << endl;
- life--;
- }
- if (playerx == trap4x && playery == trap4y) {
- cout << "You are caught in trap 4" << endl;
- life--;
- }
- if (playerx == lifeaddx && playery == lifeaddy) {
- cout << "You found a life" << endl;
- life++;
- }
- cout << "Your Life is now " << life << endl;
- if (life == 0) {
- cout << "You lost the game" << endl;
- exit(0);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement