Guest User

Untitled

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