Advertisement
Sinux1

T6E8 Text Adventure Game.cpp

Mar 31st, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5.  
  6.  
  7. void draw(int room)
  8. {
  9.     if (room == 1){
  10.         cout <<"---------" << endl;
  11.         cout <<"| x |   |" << endl;
  12.         cout <<"---------" << endl;
  13.         cout <<"|   |   |" << endl;
  14.         cout <<"---------" << endl;
  15. }
  16.     else if (room == 2){
  17.         cout <<"---------" << endl;
  18.         cout <<"|   | x |" << endl;
  19.         cout <<"---------" << endl;
  20.         cout <<"|   |   |" << endl;
  21.         cout <<"---------" << endl;
  22.  
  23.     }
  24.     else if (room == 3){
  25.         cout <<"---------" << endl;
  26.         cout <<"|   |   |" << endl;
  27.         cout <<"---------" << endl;
  28.         cout <<"| x |   |" << endl;
  29.         cout <<"---------" << endl;
  30.  
  31.     }
  32.     else if (room == 4){
  33.         cout <<"---------" << endl;
  34.         cout <<"|   |   |" << endl;
  35.         cout <<"---------" << endl;
  36.         cout <<"|   | x |" << endl;
  37.         cout <<"---------" << endl;
  38.  
  39.     }
  40. }
  41. bool move(int &room)
  42. {
  43.     // Do not delete this var when function ends, static lets it live
  44.     static int bad_moves;
  45.  
  46.     bool keep_going = true;
  47.     string input;
  48.     cout << "Which direction do you want to move: North, South, East, West" << endl;
  49.     cin >> input;
  50.  
  51.  
  52.     if (room == 1 && input == "East")
  53.         room = 2;
  54.     else if (room == 1 && input == "South")
  55.         room = 3;
  56.     else if (room == 2 && input == "West" || room == 3 && input == "North")
  57.         room = 1;
  58.     else if (room == 2 && input == "South" || room == 3 && input == "East"){
  59.         room =4;
  60.         keep_going = false;
  61.     }
  62.     else{
  63.         cout << "Invalid Movement! You will never escape the game world!!!" << endl;
  64.         bad_moves++;
  65.         if(bad_moves == 3){
  66.             cout << "Bitch you have been banned!!!" << endl;
  67.             exit(0); // Stops the application from anywhere
  68.         }
  69.  
  70.     return keep_going;
  71. }
  72. }
  73.  
  74. int main()
  75. {
  76.  
  77.     int room = 1;
  78.     do{
  79.     draw(room);
  80.  
  81.     }while(move(room));
  82.     cout << "You found the Treasure!!! Buy our DLC!!!" << endl;
  83.  
  84.  
  85.  
  86.  
  87.  
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement