Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <string>
- #include <curses.h>
- using namespace std;
- class ucmd{
- public:
- string getarg(string,string);
- string getcmd(string);
- };
- string ucmd::getcmd(string full){
- if ( full.find(" ") != full.npos ){
- return full.erase(full.find(" "),full.length()-full.find(" "));
- }else{
- return "CMD_FAIL";
- };
- };
- string ucmd::getarg( string cmd, string full){
- string str = full.substr(cmd.length()+1);
- string err = "Invalid command arguments!";
- if ( str.length() < 1 ){
- return err;
- }else if ( str == " " ){
- return err;
- }else if ( str == "" ){
- return err;
- }else{
- return str;
- };
- };
- class item{
- bool reach;
- string usetext;
- string uid;
- public:
- void setreachable(bool);
- bool getreachable();
- string getusetext();
- void setusetext(string);
- void setuid(string);
- };
- void item::setuid(string name){
- uid = name;
- };
- void item::setusetext(string text){
- usetext = text;
- };
- string item::getusetext(){
- return usetext;
- };
- bool item::getreachable(){
- return reach;
- };
- void item::setreachable( bool reachable ){
- reach = reachable;
- };
- class character{
- item holding;
- public:
- void take(item);
- bool canReach(item);
- };
- bool character::canReach(item name){
- return name.getreachable();
- };
- void character::take( item name){
- if ( name.getreachable() == true ){
- holding = name;
- //cout << name.getusetext() << endl;
- }else{
- cout << "You can't reach that!" << endl;
- };
- };
- int main(int argc, char *argv[])
- {
- // for storage.
- string cinline;
- // so we can use single argument commands :)
- ucmd cmd;
- // The player.
- character player;
- // Lets do the introduction...
- cout << "You smell the damp, chemical air.. you awake..\n" << endl;
- 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;
- 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;
- // Alright, now lets create the items we stated in the intro.
- item beaker;
- item acid;
- item glassdropper;
- item burner;
- // set their information.
- beaker.setuid( "item_beaker" );
- beaker.setreachable(true);
- beaker.setusetext( "You grab the glass beaker." );
- acid.setuid( "item_acid" );
- acid.setreachable(true);
- acid.setusetext( "You grab the vial of acid, don't spill!" );
- glassdropper.setuid( "item_glass_dropper" );
- glassdropper.setreachable(true);
- glassdropper.setusetext( "You grab the glass dropper, it has a small rubber pad on the top." );
- burner.setuid( "item_burner" );
- burner.setreachable(true);
- burner.setusetext( "You turn the burner on, and it slowly heats up." );
- while( true ){
- // Ghetto commands system..
- getline( cin, cinline );
- if ( cmd.getcmd(cinline) == "open" ){
- cout << cmd.getarg( "open", cinline ) << endl;
- }else if ( cmd.getcmd(cinline) == "take" ){
- // i need the cmd.getarg to somehow link back to the item's UID, and that would go back to the 'item <whatever arg>'
- //player.take( cmd.getarg( "take", cinline) );
- }else{
- cout << "Invalid command!" << endl;
- };
- };
- // So it doesn't close incase we pass the while loop.
- system("PAUSE");
- };
Add Comment
Please, Sign In to add comment