Advertisement
DrAungWinHtut

advanture.cpp

Mar 15th, 2025
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<conio.h>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int life = 3;
  9.     int minx = 0;
  10.     int miny = 0;
  11.     int maxx = 25;
  12.     int maxy = 15;
  13.  
  14.     int treasurex = 10;
  15.     int treasurey = 10;
  16.  
  17.     int playerx = 0;
  18.     int playery = 0;
  19.  
  20.     int trap1x = 5;
  21.     int trap1y = 5;
  22.  
  23.     int trap2x = 15;
  24.     int trap2y = 5;
  25.  
  26.     int trap3x = 5;
  27.     int trap3y = 10;
  28.  
  29.     int trap4x = 15;
  30.     int trap4y = 10;
  31.  
  32.     int lifeaddx = 10;
  33.     int lifeaddy = 5;
  34.  
  35.     int key = '\0';
  36.     cout << "Welcome to the game" << endl;
  37.     cout << "You are at position (0,0)" << endl;
  38.     cout << "Enter 'w' to move up, 's' to move down, 'a' to move left, 'd' to move right" << endl;
  39.     cout << "Enter 'q' to quit the game" << endl;
  40.     system("pause");
  41.     system("cls");
  42.     while (1) {
  43.        
  44.         key = _getch();
  45.         switch (key) {
  46.         case 'w':
  47.             if (playery > miny) {
  48.                 playery--;
  49.             }
  50.             break;
  51.         case 's':
  52.             if (playery < maxy) {
  53.                 playery++;
  54.             }
  55.             break;
  56.         case 'a':
  57.             if (playerx > minx) {
  58.                 playerx--;
  59.             }
  60.             break;
  61.         case 'd':
  62.             if (playerx < maxx) {
  63.                 playerx++;
  64.             }
  65.             break;
  66.         case 'q':
  67.             cout << "You quit the game" << endl;
  68.             exit(0);
  69.         }
  70.         cout << "You are at position (" << playerx << "," << playery << ")" << endl;
  71.         if (playerx == treasurex && playery == treasurey) {
  72.             cout << "You found the treasure" << endl;
  73.             cout << "You win the game" << endl;
  74.             exit(0);
  75.         }
  76.         if (playerx == trap1x && playery == trap1y) {
  77.             cout << "You are caught in trap 1" << endl;
  78.             life--;        
  79.         }
  80.         if (playerx == trap2x && playery == trap2y) {
  81.             cout << "You are caught in trap 2" << endl;
  82.             life--;
  83.         }
  84.         if (playerx == trap3x && playery == trap3y) {
  85.             cout << "You are caught in trap 3" << endl;
  86.             life--;
  87.         }
  88.         if (playerx == trap4x && playery == trap4y) {
  89.             cout << "You are caught in trap 4" << endl;
  90.             life--;
  91.         }
  92.         if (playerx == lifeaddx && playery == lifeaddy) {
  93.             cout << "You found a life" << endl;
  94.             life++;
  95.         }
  96.         cout << "Your Life is now " << life << endl;
  97.         if (life == 0) {
  98.             cout << "You lost the game" << endl;
  99.             exit(0);
  100.         }
  101.     }
  102.     return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement