help with really simple rpg

This is a discussion on help with really simple rpg within the C++ Programming forums, part of the General Programming Boards category; i have only been working with C++ off and on the last few weeks and this is my first semi ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    7

    help with really simple rpg

    i have only been working with C++ off and on the last few weeks and this is my first semi large project

    here is a what i want to do (instructions in code)
    Code:
    	//i want to display all this stuff as a item menu and link to it from various places
    	cout<<"Items\n";
    	cout<< item1 << "potions or something\n";
    	cout<< item2 << "something else!!!!\n";
    	//end of the stuff i want as an item menu
    	
    	do {
    		switch (room) {
    		//room coordinate 1,1
    		case 11:
    			if ( man11hp > 0 ) {
    				cout<<"There is a man standing in front of you.\n";
    				cout<<"(a)ttack\n";
    				cout<<"(r)un\n";
    				cout<<"(i)tem\n";   // when i hit input "i" i want it to link to the item menu
    				cin>> action11;
    that is just a small section from the code, before it is just a bunch of variables i have declared

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    What isn't working?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Code:
    cout<< item1 << "potions or something\n";
    You might want a space there:
    Code:
    cout<< item1 << " potions or something\n";
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    7
    its not something thats not working, its just something i dont quite know how to do yet... and a space would be good

  5. #5
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    you could just make a seperate function called menu or something

  6. #6
    Registered User
    Join Date
    Feb 2006
    Posts
    7
    thats what i dont know yet...
    i read the function tutorial but i dont really get how to implement that...

  7. #7
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    example in text format if a condition is met

    Code:
    #include <iostream>
    
    using namepace std;
    
    int main()
    {
    
    int potion = 0;   // define and initalize your items
    int sword = 0;
    
    sword++;   // increment them
    potion++;
    
    // display a message
    
    if ( potion >= 1 )
    {
    cout << "I have a potion" << endl;
    }
    
    if ( sword >= 1 )
    {
    cout << "I have a sword" << endl;
    }
    
    return 0;
    }
    number list option

    Code:
     // assume you have the required amounts....
    
    int potion = 1;
    int sword = 1;
    
    cout << "Sword: " << sword << endl;
    cout << "Potion: " << potion << endl;
    the above is a snippet, but you get the idea. Also avoid using GLOBAL variables. Use a class like the example below and send the information via a function

    Code:
    class Inven
    {
    public:
    Inven();  // constructor to implelent the variables
    
    private:    // use private for vairable names
    int health;
    int potions;
    string myName;
    };

  8. #8
    Registered User
    Join Date
    Feb 2006
    Posts
    7
    these are all good seggustions, but the part i really need help with is using the function to see it from different parts of the code, as i asked in the first post

  9. #9
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    here is one method - this assumes you have collected the items

    // this function stores your items
    Code:
    void storeItems ( void )
    {
    cout << "Potions: " << potions;
    cout << swords: " << swords;
    
    return;
    }
    nest snipped of code in selection example:

    Code:
    switch ( choose )
    {
    case 1:
    
    // call the inventory function
    
    storeItems();
    
    // check to see if you have item
    i
    f ( sword >= 1 )
    {
    useSword();  // call a function that actions the sword being used
    }
    
    else if ( sword <= 0 )
    {
    cout << "You do not have the sword;
    }
    break;
    the sword use function could be this:

    Code:
    void useSword( void )
    {
    cout << "What action?\n"
                           [R[un\n"
                           [A]ttack\n"
                           > ";
    cin >> choose;
    
    switch ( choose )
    {
    case 'A':
    --enemyHp;
    cout << you attack and hit enemy;
    
    break;
    }
    this is a small version of a way to do it. read up on functions to learn more

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple message encryption
    By Vicious in forum C++ Programming
    Replies: 10
    Last Post: 11-07-2004, 10:48 PM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  4. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 07:52 AM
  5. Linker errors with simple static library
    By Dang in forum Windows Programming
    Replies: 5
    Last Post: 09-08-2001, 09:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21