My Text-Based RPG...

This is a discussion on My Text-Based RPG... within the C++ Programming forums, part of the General Programming Boards category; Hi guys, I would like to take a look at this text based RPG i created. It is not even ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    25

    Question My Text-Based RPG...

    Hi guys,

    I would like to take a look at this text based RPG i created. It is not even nearly completed. It is just a prototype which helps me to brush up all the things i've learned so far in C++ (im a beginner)...So please be gentle :P (RUN the program, please)

    Any comments or suggestion will be highly appreciated! This is my 1st attempt to create a game.
    It might be difficult ot read in the console screen so please pay careful attention

    Code:
    /////////////////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////   PROTOTYPE  - DEMO  ////////////////////////////////////////////////////
    /////////////////////////////     IN PROGRESS...  ///////////////////////////////////////////////
    
    /////////////////////////////////////////////////
    //   (!)(!)So this isnt the actual game.(!)(!)
    //   It is just a prototype from which
    //   I am trying to learn the logic in
    //    creating Text-Based RPG 's. It still needs A LOT of work in order
    //   to be considered as COMPLETED
    //
    //////////////////////////////////////
    #include <iostream>
    using namespace std;
    
    void move(int&, int&);
    void menu();
    
    bool game = true;
    int main()
    {
    	int    posx = 0;
    	int    posy = 0;
    	while (game == true)
    	{
    		cout << endl << endl<< "What do you like to do? ";
    		cout << endl << "1)Move" << endl << "2)Show current position" << endl;
    		cout << "3) Show world map " << endl;
    		cout << "4) quit  ----->  Choose: ";
    		int choice;
    		cin >> choice;
    
    			switch(choice)
    			{
    				case 1:
    					move(posx, posy);
    					break;
    				case 2:
                                            cout << endl << "----------------------------" << endl;
    					cout << endl << "Current position: ("<< posx << "," << posy <<")";
                                            cout << endl << "----------------------------" << endl;
    					break;
    				case 3:
    					cout << endl << "=== WORLD-MAP===" << endl;
    					cout << endl << "Castle (2,1) " << endl;
    					cout << endl <<"=====================" << endl;
    					break;
    				case 4:
    					game = false;
    					break;
    			}
    	} // while loop BOOL
    
    	cout << endl << endl << "Game Over" ;
    
    } // int main()
    
    
    ///////////////////////////////////////
    //
    //  This function moves the character
    //
    //////////////////////////////////////
    void move(int &posx, int &posy)
    {
    	cout << "------------------------------------------" << endl;
    	cout << endl << "HELP: Every time you move, you move" << endl;
    	cout << "1point either North, South, East, West " << endl;
    	cout << "For example, if you choose 'North' then your position " << endl;
    	cout << "from (0,0) will be (0,1) ----> ( x-coordinate , y-coordinate) "<< endl;
    	cout << endl << "Where to move?";
    	cout << endl<< "1)North 2)South 3)East";
    	int choice;
    	cin >> choice;
    		
    		if (choice == 1)
    			posy +=1;  // move 1 point UP (y)
    		else if (choice==2)
    			posy -=1;
    		else if (choice==3)
    			posx+=1;  //move 1 point RIGHT (x)
    
    		//test
    		if((posx == 2) && (posy==1))
    		{
    			cout <<endl << "You reached the castle!";
    		//test
    			menu();
    		}		
    }
    
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // This function appears when you reach the castle.
    // It shows you a menu and asks you whether you want to enter search or leave
    // If you "search" then the do-while loop will repeat the menu
    // if you "leave" then it gets out of the function
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////
    void menu()
    {
    	int choice;
    	do{
    				cout << endl << "1)Enter 2)Search 3) Quit";
    				cin >> choice;
    					switch(choice)
    					{
    						case 1:
    							cout << endl << "You entered the castle" << endl;
    							// "show castle Menu";
    							// ..to be continued
    							cout << "I'll end the game HERE cause i didnt finished it yet..." << endl;
    							game=false;
    							break;
    						case 2:
    							cout <<endl << endl << "Theres nothing here to search" << endl;
    							break;
    						case 3:
    							game = false;
    					} // switch
    	}while(choice == 2);
    }
    Last edited by Greek_89; 01-15-2011 at 06:09 AM.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,625
    Well how about that? It reminds me too of my first attempt to write a text-RPG. I wrote it in Just Basic. I never completed it but it surely taught me much. Anyway, keep it up!

    ( Αν θες τη γνώμη μου, το να χρησιμοποιείς συντεταγμένες για ένα τέτοιο παιχνίδι δεν είναι καλή ιδέα. Δώσε καλύτερα στον παίκτη μια σειρά από επιλογές και μπες κατευθείαν στο θέμα. Στο λέω γιατί η συντεταγμένες είναι σχετικές ... ο παίκτης δεν θα μπορεί να δει τίποτα. Καλή συνέχεια! )
    Devoted my life to programming...

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    A begginer writing a text based dungeon game.

    The problem with your approach is that you have to change the code radically with each new idea.

    As I demonstrate, the basic data structure is the 'map' through which your player walks. Adding new rooms just involves changing the map data. The code itself doesn't care at all.

    Adding a new feature (say moving up/down) would only change one function in the code. If you hard-code every room, then adding up/down would mean visiting an awful lot of code to copy/paste the same functionality.

    When you get to adding objects / monsters etc which can move from room to room, then the 'map' approach really starts to win. Adding a list of objects in each room makes it a snap to pick up an object from one room (remove from the room object list, and add to the player object list), and then drop it in another room.

    If you hard-code everything (there is a lamp here), and you pick it up, then you need some kind of flag to keep track of where the lamp is now.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,625
    Well, he says he's a beginner. Using a 'map' as you say requires some average to advanced knowledge, doesn't it?
    Devoted my life to programming...

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,739
    Quote Originally Posted by Sipher
    Using a 'map' as you say requires some average to advanced knowledge, doesn't it?
    Looking at Salem's C example from the thread that was linked to, I'd say no, it doesn't.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Dec 2009
    Posts
    25
    Quote Originally Posted by Sipher View Post
    Well how about that? It reminds me too of my first attempt to write a text-RPG. I wrote it in Just Basic. I never completed it but it surely taught me much. Anyway, keep it up!

    ( Αν θες τη γνώμη μου, το να χρησιμοποιείς συντεταγμένες για ένα τέτοιο παιχνίδι δεν είναι καλή ιδέα. Δώσε καλύτερα στον παίκτη μια σειρά από επιλογές και μπες κατευθείαν στο θέμα. Στο λέω γιατί η συντεταγμένες είναι σχετικές ... ο παίκτης δεν θα μπορεί να δει τίποτα. Καλή συνέχεια! )
    katalabainw ti thes na peis..sthn arxh dn hthela n xrhsimopoihsw suntetagmenes alla opws eipa apla to eftiaksa ayto to paixnidi gia na eksaskhthw sauta pou ematha st c++..(sth periptwsh twn suntetagmenwn hthela na xrhsimopoihsw tis sunarthseis me reference& parametrous)..meta mou rthe st mualo ena final fantasy paixnidi k eipa na balw "world map" wste n mporesei na kateu8unthei o paikths.

    bebaia skeftomoun na balw k ena random generator (rand()). etsi se kathe "bhma" that ebaza kai to rand() gia na dw an o paikths tha epefte se maxh (kathws proxwraei sto world map) 'h apla na sunexisei to taksidi...alla bebaia tha epiane MPOLIKO kwdiko!

    Alla euxaristw gia th sumboulh!

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,739
    Sipher and Greek_89, I understand that you guys might want to poke a little fun at those bots running around, but please be careful: a trigger happy me nearly permanent banned Greek_89.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Now seriously... this is an english speaking forum, and seeing Greek_89 has no problems speaking english, you shouldn't be speaking to Greek_89 in non-english, Sipher.
    Sipher: I suggest you also use english when communicating, regardless of whether people communicate to you in another language. It will benefit everyone.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Dec 2009
    Posts
    25
    Quote Originally Posted by Elysia View Post
    Now seriously... this is an english speaking forum, and seeing Greek_89 has no problems speaking english, you shouldn't be speaking to Greek_89 in non-english, Sipher.
    Sipher: I suggest you also use english when communicating, regardless of whether people communicate to you in another language. It will benefit everyone.
    if you see my characters,this is english..its just CODED english cause we are in a "cold war" era..

    Anyway for those who hate the greek culture (even though greeks gave you the lights for your present-day comfort to program or use math) here is an EXACT translation in ENGLISH:

    "I understand what you are trying to tell me... at first i didnt want to use coordinates but as i said, i created it in order to train the knowledge ive already got in c++..(in the case of the coordinates i wanted to use the functions with reference parameters..then final fantasy came up in my mind and ichose to put a world map so the player could navigate.

    of course i was thinking of including a rando generator so in each step i would made, i would use the rand() to see whether the player would fall into a battle (as he walks to the world map) or to continue his journey..but this ofcourse would require a lot of code!

    But thanks for the advice "

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Quote Originally Posted by Greek_89 View Post
    if you see my characters,this is english..its just CODED english cause we are in a "cold war" era..

    Anyway for those who hate the greek culture (even though greeks gave you the lights for your present-day comfort to program or use math) here is an EXACT translation in ENGLISH:
    We don't hate greek. But we can't read greek. I couldn't even translate your message using google translate.
    But the point is that this is an international forum. The mods here read and speak english. Those who visit speak and read english. We don't speak or read greek, and that is why it's bad to use greek here.
    Messages gets archived here, so to speak, for everyone to search, read and digest. Your issue may help others. That is, if it isn't greek.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Dec 2010
    Posts
    16
    A minor piece of information:
    Code:
    while(game == true)
    is a bit more professional when put as:
    Code:
    while(game)
    You declared game as true already, so while returns 1 automatically when you call game, you don't have to check for value.

  12. #12
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    is a bit more professional when put as:
    Eh?

    They are the same thing.

  13. #13
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    I think that was the point.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    I just got a kick out of the more professional comment. I don't see either of those as more or less professional than the other. In fact one of them is just more explicit. But since none of us are trying to save space in the lines of code we type I don't see the point.

  15. #15
    Registered User
    Join Date
    Dec 2009
    Posts
    25
    Quote Originally Posted by User-_-Name View Post
    A minor piece of information:
    Code:
    while(game == true)
    is a bit more professional when put as:
    Code:
    while(game)
    You declared game as true already, so while returns 1 automatically when you call game, you don't have to check for value.
    No its OK! thanks for that..yeah your right.. "while(game)" is an alternative...although its like saying 2+1=3 or 1+2=3..but ive seem most of the programs being written like yours

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 01:59 PM
  2. text rpg help
    By xxwerdxx in forum Game Programming
    Replies: 1
    Last Post: 11-26-2005, 07:16 PM
  3. Check out My Text Rpg Game
    By knight543 in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2002, 10:40 PM
  4. Text based GUI?
    By jon_nc17 in forum C++ Programming
    Replies: 1
    Last Post: 05-16-2002, 11:45 AM
  5. Text Based Game
    By drdroid in forum C++ Programming
    Replies: 2
    Last Post: 02-18-2002, 05:21 PM

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