"How Do I" create RPG in C++ w/o graphics

Hello,
I am in Intro C++ class & I have to create a "RPG" (role play game). I am having some challenges. I have already created a few different variations trying to get progam to run, but I keep breaking stuff when I try to fix it.

So, there are at least 3 menus (main menu, choose warrior, choose weapon) & you must choose options, while a score is awarded, tracked & displayed later. Also, reading/writing to a file, but not worried about that now.

Any advice you can offer will be greatly appreciated! or alternative programs/links/sites/etc...I have searched, but what I have found is all way more advanced than this.

I have below some of what I have done ( I did eliminate some lines):
Thank you so much for your assistance! trendygirl

1
2
[code][code]//Introduction
	[code]cout<<" 
\n\nWELCOME TO THE Women Warriors GAME !!\n\n";
cout<< "Choose from the menu below: \n";

do
{
//reset score
score = 0;
highScore = 0;
randomNumber = 0;

//Display menu
cout<<"1) Story Line & Rules \n";
cout<<"2) Play Game \n";
cout<<" 3) Exit \n";

//Prompt the user for menuChoice
cout<<" Enter your choice here: \n";
cin>>menuChoice;
cin.ignore(80,'\n');

do
{
//Display story line
if (menuChoice == 1)
{
cout<<" You have selected to read the Story Line and the Rules.\n";
cout<<" \"Women Warriors!\"\n\n";
cout<<" It is the year 2212…..";


//Display rules
cout<<" The rules of the games are: \n\n";
cout<<" 1. Select your Woman Warrior from the description provided\n";
cout<<" 2. Then you must select your weapon\n";
cout<<" 3. You will be awarded points based on your choices.\n";
cout<<" 4. Your points will be recorded and displayed at the end.\n\n";
}

else if (menuChoice == 2)
{
//Start game play
cout<<" You have chosen to play the \"Women Warriors\" game.\n";
cout<<" Let's Play the Game!\n";
cout<<" Please choose your Warrior!\n";
//Choose A,B,C = choice //type of female warrior
//Revenge Maven, Renegade Rebel, Righteous Ringleader
cout<<" A - Revenge Maven\n";
cout<<" B - Renegade Rebel\n";
cout<<" C - Righteous Ringleader\n";
cin.ignore(80,'\n');
cin.get(choice);

//Display warrior name & attributes
//display invalid
if (choice == 'A')
{
cout<<" You have chosen Revenge Maven, \"Beatrix Kiddo\"!\n";
cout<<" The Bride....\n";
cout<<" Your points are being awarded!\n";
cout<<score<<endl; //show score
}

else if (choice == 'B')
{
cout<<" You have chosen Renegade Rebel, \"Sarah Connor\"!\n";
cout<<" A cyborg assassin....\n";
cout<<score<<endl; //show score
}

else if (choice == 'C')
{
cout<<" You have chosen the Righteous Ringleader, \"Wonder Woman\"!";
cout<<" Wonder Woman ......\n";
cout<<"Your points are being awarded!\n";
//show score
cout<<score<<endl;
}

//validate input
while (choice <= 'A') && (choice >= 'C');
{
cout<<"Invalid, Please enter A, B, C for your menu choice.\n";
cin>>choice;
}

do
{//Choose 1,2,3 = option
//prompt for weapon selection
cout<<" Please choose the weapon you will use to destroy the villian!\n";
cout<<" 1 - The Lariat of Hestia.\n";
cout<<" 2 - A Samurai Sword.\n";
cout<<" 3 - An M-79 Grenade Launcher.\n";
cin>>option;

if (option == 1)
{
cout<<" You have chosen"<<option<<"as your death weapon!\n";
cout<<" Your points are being awarded!\n";
//show score
cout<<score<<endl;
}

else if (option == 2)
{
cout<<" You have chosen"<<option<<"as your death weapon!\n";
cout<<" Your points are being awarded!\n";
//show score
cout<<score<<endl;
}

else if (option == 3)
{
cout<<" You have chosen"<<option<<"as your death weapon!\n";
cout<<" Your points are being awarded!\n";
//show score
cout<<score<<endl;
}

}while (option != 4);
cout<<" You have entered an invalid choice.\n";
cout<<" You must choose 1 - 3 from the menu.\n";


//Calculate points based on choices
if (menuChoice == 'A')
{
score = 500;
cout<<score<<endl;
}
else if (menuChoice == 'B')
{
score = 400;
cout<<score<<endl;
}
else if (menuChoice == 'C')
{
score = 300;
cout<<score<<endl;
}

//show score
cout<<score<<randomNumber<<endl;

//calculate score and random number
highScore = score + randomNumber;
cout<<highScore<<endl;
}

if (menuChoice == 3)
//Display good bye
{
cout<<"\nThank you for playing Warrior Women\n";
cout<<"\nGoodbye.\n";
}

else (menuChoice !=3);
//Invalid
{
cout<<" You have entered an invalid choice.\n";
cout<<" You must choose 1 - 3 from the menu.\n";
cout<<" Please choose 2 if you want to play again!\n\n";
}
} while (menuChoice != 3); //loop again if 3 not selected[/code][/code][/code]


Last edited on
Damn, what intro class you taking? We need to know so we can warn against taking that class. An RPG, even text based is definitely not an intro appropriate assignment :-/. A little more detail about where it is breaking would be helpful too.
Last edited on by closed account z6A9GNh0
It is "Intro to C++".....below is one example, trying to validate input of choice, A,B,C,

not sure how to do that correctly. I can do it w/##'s, but I have multiple menus & have used ##'s elsewhere, & that "input validation" is also showing up in wrong spot.


//validate input


while (choice <= 'A') && (choice >= 'C');
{
cout<<"Invalid, Please enter A, B, C for your menu choice.\n";
cin.get(choice);
}
Please Use Code tags
Now see, validate input means to me that you are doing checks to make sure the choice is A, B, or C and if they enter a, b, c or some number/symbols you are checking for the stream to go into fail state, resetting it and waiting for the proper choice to be made. Just me, but this does seem a little more complex than a simple Intro class should have. Though, most intro classes are only interested in seeing that you can do it and not necessarily how well you can do it as you will build experience as you go.

So it is breaking at the validation code chunk?

Just so Script Coder won't have a aneurysm (not going to mess with spacing though :P ):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//Introduction
cout<<"\n\nWELCOME TO THE Women Warriors GAME !!\n\n";
cout<< "Choose from the menu below: \n";

do
{
//reset score
score = 0;
highScore = 0;
randomNumber = 0;

//Display menu
cout<<"1) Story Line & Rules \n";
cout<<"2) Play Game \n";
cout<<"3) Exit \n";

//Prompt the user for menuChoice
cout<<" Enter your choice here: \n";
cin>>menuChoice;
cin.ignore(80,'\n');

do
{
//Display story line
if (menuChoice == 1)
{
cout<<" You have selected to read the Story Line and the Rules.\n";
cout<<" \"Women Warriors!\"\n\n";
cout<<" It is the year 2212…..";


//Display rules
cout<<" The rules of the games are: \n\n";
cout<<" 1. Select your Woman Warrior from the description provided\n";
cout<<" 2. Then you must select your weapon\n";
cout<<" 3. You will be awarded points based on your choices.\n";
cout<<" 4. Your points will be recorded and displayed at the end.\n\n";
}

else if (menuChoice == 2)
{
//Start game play
cout<<" You have chosen to play the \"Women Warriors\" game.\n";
cout<<" Let's Play the Game!\n";
cout<<" Please choose your Warrior!\n";
//Choose A,B,C = choice //type of female warrior
//Revenge Maven, Renegade Rebel, Righteous Ringleader
cout<<" A - Revenge Maven\n";
cout<<" B - Renegade Rebel\n";
cout<<" C - Righteous Ringleader\n";
cin.ignore(80,'\n');
cin.get(choice);

//Display warrior name & attributes
//display invalid
if (choice == 'A')
{
cout<<" You have chosen Revenge Maven, \"Beatrix Kiddo\"!\n";
cout<<" The Bride....\n";
cout<<" Your points are being awarded!\n";
cout<<score<<endl; //show score
}

else if (choice == 'B')
{
cout<<" You have chosen Renegade Rebel, \"Sarah Connor\"!\n";
cout<<" A cyborg assassin....\n";
cout<<score<<endl; //show score
}

else if (choice == 'C')
{
cout<<" You have chosen the Righteous Ringleader, \"Wonder Woman\"!";
cout<<" Wonder Woman ......\n";
cout<<"Your points are being awarded!\n";
//show score
cout<<score<<endl;
}

//validate input
while (choice <= 'A') && (choice >= 'C');
{
cout<<"Invalid, Please enter A, B, C for your menu choice.\n";
cin>>choice;
}

do
{//Choose 1,2,3 = option
//prompt for weapon selection
cout<<" Please choose the weapon you will use to destroy the villian!\n";
cout<<" 1 - The Lariat of Hestia.\n";
cout<<" 2 - A Samurai Sword.\n";
cout<<" 3 - An M-79 Grenade Launcher.\n";
cin>>option;

if (option == 1)
{
cout<<" You have chosen"<<option<<"as your death weapon!\n";
cout<<" Your points are being awarded!\n";
//show score
cout<<score<<endl;
}

else if (option == 2)
{
cout<<" You have chosen"<<option<<"as your death weapon!\n";
cout<<" Your points are being awarded!\n";
//show score
cout<<score<<endl;
}

else if (option == 3)
{
cout<<" You have chosen"<<option<<"as your death weapon!\n";
cout<<" Your points are being awarded!\n";
//show score
cout<<score<<endl;
}

}while (option != 4);
cout<<" You have entered an invalid choice.\n";
cout<<" You must choose 1 - 3 from the menu.\n";


//Calculate points based on choices
if (menuChoice == 'A')
{
score = 500;
cout<<score<<endl;
}
else if (menuChoice == 'B')
{
score = 400;
cout<<score<<endl;
}
else if (menuChoice == 'C')
{
score = 300;
cout<<score<<endl;
}

//show score
cout<<score<<randomNumber<<endl;

//calculate score and random number
highScore = score + randomNumber;
cout<<highScore<<endl;
}

if (menuChoice == 3)
//Display good bye
{
cout<<"\nThank you for playing Warrior Women\n";
cout<<"\nGoodbye.\n";
}

else (menuChoice !=3);
//Invalid
{
cout<<" You have entered an invalid choice.\n";
cout<<" You must choose 1 - 3 from the menu.\n";
cout<<" Please choose 2 if you want to play again!\n\n";
}
} while (menuChoice != 3); //loop again if 3 not selected 
I'm sorry, I am a noob.....what do you mean by "code tags?" script coder.....

BHXSpecter, I don't see what you have done...it looks the same. I have worked on it some more as well...but I'm still challenged.

Thank you for help... :)

closed account (o1vk4iN6)
Tags are defined by square brackets with a keyword inside followed by an ending bracket with "/", this is used in nearly every single forum to provide additional formatting to make it easier to read. In this case it allows for C++ syntax highlighting.

[keyword] contents [/keyword]

just replace "keyword" with code, or you can just press the button on the right with "<>".
Last edited on
It is the same code, just put it in tag codes so Script Coder wouldn't freak any more. What university is this class at? I held off changing it because if I use things you don't know yet it will be obvious to the instructor and may make you lose points for passing the class.
ok, well since I already posted it....I don't have to fix it, do I?? (code tags)

I am in Broward County, Broward College, we are using "Starting out w/C++, Early Objects" & are about to work on functions. I would not want to "fancy" it up. I know I am on the right track, I just get the control structures mixed up. I already overheard my prof. talking to 2 guys who submitted the same paper (one has a language barrier). So, I guess they didn't even think about changing anything to make it their own! I would!
oohh, sorry script coder :( although I did review the info on posting info here, having never made a post, I would have required more info on what a "code tag" is! I have tried to correct my mistake, but the page does not want to cooperate now. I'm sure you were not always an expert & you too were a beginner at one time...an example might be helpful, somewhere in the introductory info. I'm sure you could make that happen! help out the other noobs.....we have to learn to crawl before we can walk!

It seems like you have put too many code tags resulting in some mismatched tags. You simply need one [code] tag at the very beginning of any code you're posting and one [/code] tag at the very end. Alternatively, you can select the code in your post and press the <> button (on the right under "Format:" when creating/editing a post).

In summary:

[code]int someCode()
{
return 42;
}[/code]

turns into

1
2
3
4
int someCode()
{
   return 42;
}
Last edited on
WOW! 3 responses about not posting properly...what about suggestions for my assignment? I thought that was the whole idea of having a site like this.....thanks SPECTER!!
Might be frustrating having people comment about the tags but, in fact, it's incredibly hard to read code without them (not impossible, but a lot easier with tags). Also, getting frustrated isn't going to do anything in terms of getting someone to help you.

Though the attempt at the top of the code did make me giggle a bit.

With regards to your code, your question is a bit vague. There's probably a good number of RPG examples out there and no definite way to do one; everyone's approach will be different. You've listed quite a few things there, but is there something in particular that you're struggling with?

If you haven't come across functions yet and you're looking for general advice, you're probably going to get advice that confuses you because you haven't encountered the topics yet. If you're more specific with what you want, I can give an answer that suits you.
Last edited on
My class is about to learn Functions. I have briefly looked at it, & it looks like I would have to rewrite entire program, as you said, w/o completely understanding what I am doing! So, without using Functions, is it possible to create this scenario of multiple menus & return choices & responses w/another control structure? How/what would that be?
You don't need* functions for anything. They are merely a convenience. It is recommended that you use them, though.

You could use a switch block instead of the if statements. I think that would clean it up a bit, though it's really just preference. They both lead to the same outcome.

Now, I may be missing it, but is there a primary question in this thread?
Well a function isn't a control structure, really. Control structures are loops and if statements and the like. What a function would do, is separate your code into smaller, task driven sections. So, for example, you might have a function called ShowMenu() which would print then menu, removing a large chunk of code from main. It would generally tidy it up and make it more readable, amongst other things (which you'll no doubt encounter in the future).

You could tidy your code up a little. For example, you're checking for A, B or C earlier on to output some text. Then you're checking for A, B and C again later to assign points. Why not just assign the points in the blocks where you initial check? In doing so, you can get rid of that whole extra choice variable check towards the end of the code.

Also, are you familiar with the toupper function? It can be used on your choice so that if the user enters a lower case a, b or c, it'll be converted to upper case prior to assessing it.

In general, there seems to be some bracketing issues and some confusion in the do/while loops. I can't be certain of this, as it's hard to tell without the right indentation, but the while statement on line 81 (of the code that BHXSpecter tagged) doesn't look right to me. Looks like you want it to be a while loop in it's own right, but the terminator makes it look like it's the while clause of a do-while loop. Again, hard to tell without brackets and it may be fine, but you may want to check all of this flows as you'd expect it to.

In the weapon choice section, why don't you output the name of the weapon, rather than the number?
Last edited on
Topic archived. No new replies allowed.