Guest User

Untitled

a guest
Jan 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.88 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class ucmd{
  8.       public:
  9.             string getarg(string,string);
  10.             string getcmd(string);
  11. };
  12.  
  13. string ucmd::getcmd(string full){
  14.        if ( full.find(" ") != full.npos ){
  15.           return full.erase(full.find(" "),full.length()-full.find(" "));
  16.        }else{
  17.              return "CMD_FAIL";
  18.        };
  19. };
  20.  
  21. string ucmd::getarg( string cmd, string full){
  22.        string str = full.substr(cmd.length()+1);
  23.        string err = "Invalid command arguments!";
  24.        
  25.        if ( str.length() < 1 ){
  26.           return err;
  27.        }else if ( str == " " ){
  28.              return err;
  29.        }else if ( str == "" ){
  30.              return err;
  31.        }else{
  32.              return str;
  33.        };
  34. };
  35.  
  36. class item{
  37.       bool reach;
  38.       string usetext;
  39.       string uid;
  40.       public:
  41.              void setreachable(bool);
  42.              bool getreachable();
  43.              string getusetext();
  44.              void setusetext(string);
  45.              void setuid(string);
  46. };
  47.  
  48. void item::setuid(string name){
  49.      uid = name;
  50. };
  51.  
  52. void item::setusetext(string text){
  53.      usetext = text;
  54. };
  55.  
  56. string item::getusetext(){
  57.        return usetext;
  58. };
  59.  
  60. bool item::getreachable(){
  61.      return reach;
  62. };
  63.  
  64. void item::setreachable( bool reachable ){
  65.      reach = reachable;
  66. };
  67.  
  68. class character{
  69.       item holding;
  70.      
  71.       public:
  72.              void take(item);
  73.              bool canReach(item);
  74. };
  75.  
  76. bool character::canReach(item name){
  77.      return name.getreachable();
  78. };
  79.  
  80. void character::take( item name){
  81.      if ( name.getreachable() == true ){
  82.         holding = name;
  83.         //cout << name.getusetext() << endl;
  84.      }else{
  85.            cout << "You can't reach that!" << endl;
  86.      };
  87. };
  88.  
  89. int main(int argc, char *argv[])
  90. {
  91.     // for storage.
  92.     string cinline;
  93.    
  94.     // so we can use single argument commands :)
  95.     ucmd cmd;
  96.    
  97.     // The player.
  98.     character player;
  99.    
  100.     // Lets do the introduction...
  101.     cout << "You smell the damp, chemical air.. you awake..\n" << endl;
  102.     cout << "As you look around you see a table set afront you, on the table sits a glass beaker, a bunsen burner, a vial labeled as sulphuric acid and a glass dropper \n" << endl;
  103.     cout << "You try to stand up, you find your left hand is handcuffed to the chair, which is bolted to the ground.. what will you do?\n" << endl;
  104.    
  105.     // Alright, now lets create the items we stated in the intro.
  106.     item beaker;
  107.     item acid;
  108.     item glassdropper;
  109.     item burner;
  110.    
  111.     // set their information.
  112.     beaker.setuid( "item_beaker" );
  113.     beaker.setreachable(true);
  114.     beaker.setusetext( "You grab the glass beaker." );
  115.    
  116.     acid.setuid( "item_acid" );
  117.     acid.setreachable(true);
  118.     acid.setusetext( "You grab the vial of acid, don't spill!" );
  119.    
  120.     glassdropper.setuid( "item_glass_dropper" );
  121.     glassdropper.setreachable(true);
  122.     glassdropper.setusetext( "You grab the glass dropper, it has a small rubber pad on the top." );
  123.    
  124.     burner.setuid( "item_burner" );
  125.     burner.setreachable(true);
  126.     burner.setusetext( "You turn the burner on, and it slowly heats up." );
  127.    
  128.     while( true ){
  129.            
  130.            // Ghetto commands system..
  131.            getline( cin, cinline );
  132.            
  133.            
  134.            if ( cmd.getcmd(cinline) == "open" ){
  135.               cout << cmd.getarg( "open", cinline ) << endl;
  136.            }else if ( cmd.getcmd(cinline) == "take" ){
  137.                  // i need the cmd.getarg  to somehow link back to the item's UID, and that would go back to the 'item <whatever arg>'
  138.                  //player.take( cmd.getarg( "take", cinline) );
  139.           }else{
  140.                 cout << "Invalid command!" << endl;
  141.           };
  142.     };
  143.    
  144.     // So it doesn't close incase we pass the while loop.
  145.     system("PAUSE");
  146. };
Add Comment
Please, Sign In to add comment