View previous topic :: View next topic |
Author |
Message |
dkwannab Advanced Cheater
Reputation: 0
Joined: 11 Apr 2008 Posts: 52
|
Posted: Wed May 21, 2008 6:39 pm Post subject: [Request] rpg text game code/tut C++ |
|
|
Edit: I think this sums it up: i will no longer be using the old code im starting from scratch, so im also changing this thread to what i need now ^_^
Code: | Hi every 1,
I have been creating this text based rpg in c++ using just a lot of the basic commands from the iostream
so far i have developed things like:
-stats (health, strength etc)
-fighting monsters (monsters are by random)
-leveling up and earning stat points
-dying (loose 5 levels when you die, level zero or below = game over)
-different attacks (different attacks do different damage)
-stat bonuses (swords, potions)
I've been trying to develop my game a lot further using the same simple commands, but when i incorporated things like inventory, shop, exp, etc.
they didn't function properly.
I have realised that to further develop it i will need to use classes (I have a little bit of knowledge about how the work but not much)
Because of this i have to start my game again.
I am requesting a code snippet of a text rpg made using classes. (I learn quicker this way then using tuts; I already read a tut on using classes but i'm still not sure on how i would incorporate it into a game)
If you don't have a code then a tut will be fine.
Thanks in advance |
Last edited by dkwannab on Fri May 23, 2008 12:10 am; edited 2 times in total |
|
Back to top |
|
 |
Mussy69 Grandmaster Cheater
Reputation: 0
Joined: 09 Mar 2007 Posts: 842 Location: Sydney
|
Posted: Thu May 22, 2008 1:48 am Post subject: |
|
|
Aren't you a bit worried someone will steal your source and turn it into their own, but it's really helpful to ME not for stealing but learning because i've just started learning C++ xD
_________________
|
|
Back to top |
|
 |
killersamurai Expert Cheater
Reputation: 0
Joined: 10 Sep 2007 Posts: 197 Location: Colorado
|
Posted: Thu May 22, 2008 3:23 am Post subject: |
|
|
I would suggest making classes. Make a character class that would be the base for everything. Then makes two other classes, one for the player and one for the enemies. You would be able to make an exp system better if you take an OO approach.
For the shop, create a class that contains a structure that holds item information. Then, use a vector to hold all the items you add. Then, create functions that will interact with the user.
I have to go to work, so I can't provide an example right now. But when I get off, I can provide one if no one else has.
http://books.google.com/books?id=OA9vMnZrCrcC&pg=PA235&lpg=PA235&dq=critter+c%2B%2B&source=web&ots=Wza46iwuZ6&sig=TMftCa1LN55bgDfbptwJiINsCVs&hl=en#PPA247,M1
Last edited by killersamurai on Thu May 22, 2008 3:38 pm; edited 1 time in total |
|
Back to top |
|
 |
WolfDm3 Grandmaster Cheater
Reputation: 0
Joined: 11 Jun 2007 Posts: 502 Location: Mississippi
|
Posted: Thu May 22, 2008 7:49 am Post subject: |
|
|
Alright, im on my cellphone so it is hard to be explanatory but you could try this Code: | int exp = 0 if exp > 100 (level up function) | then put this on monsters, you may have to add more
|
|
Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Thu May 22, 2008 7:03 pm Post subject: |
|
|
Yeah, I agree with the OO approach;
also, you should create like a Monster data file or something; coding all of that stuff in is terrible practice.
_________________
|
|
Back to top |
|
 |
dkwannab Advanced Cheater
Reputation: 0
Joined: 11 Apr 2008 Posts: 52
|
Posted: Thu May 22, 2008 7:42 pm Post subject: |
|
|
EDIT: WolfDm3 wrote: | Alright, im on my cellphone so it is hard to be explanatory but you could try this Code: | int exp = 0 if exp > 100 (level up function) | then put this on monsters, you may have to add more |
I spent ages doing all this but it fails because its like my inventory, instead of adding on it just shows the exp from you last battle, the reason i can have it keep adding on stats is because its a set amount each time, but with items, messos and exp it changes everytime so when you look at your exp/inventory it will only show what you got from your last battle =(
i need help on the oo method :s
I still need help with setting up an equip menu aswell =\ but basically like i said i needa know how i can make stuff add on instead of only showing from last battle =\
(ill post full code up top)
Code: | case 'W':
case 'w':
if (equip >= 1) {
cout << "You currently equiped with a " << equipName << ".\n";
cout << "Your currently carrying a " << itemName << "\n";
cout << "Do you want to equip this as your current weapon? <y/n>\n";
choice = getch();
clear();
}else {
cout << "You currently equiped with nothing.\n";
cout << "Your currently carrying a " << itemName << "\n";
cout << "Do you want to equip this as your current weapon? <y/n>\n";
choice = getch();
clear();
}if (choice == 121) {
equip++;
cout << "The " << itemName << " has been equiped\n";
pause();
break;
}else if (choice == 110) {
cout << "The item has not been equiped\n";
pause();
break;
}else {
cout << "You Didn't input 'y' or 'n' try again\n";
pause();
break;
} |
|
|
Back to top |
|
 |
|