I am somewhat decent at c++ and want to make a console rpg. I am not sure how to start though, except for the character creation. Would anyone be willing to help me get rolling?
Now, whether the rpg is console or not, I think you should first design a map and enable the player to move on it. If you're staying console, I suggest something like
You could later add vectors of items and monsters to it.
When you have basic interface done, you can start working on combat and skills. There's a gazillion ways to do that, so be original.
By the way, it is likely that you'd want to write a simple parser too.
thank you, but could you please explain some things? is struct room a statement, class, or function? I use "using namespace std" so what of the stds could i take out? what is a vector and a parser. I know this sounds like I dont know alot, but this is why I want to do an rpg
struct is like a class but with everything public by default. You can take away all of the std:: if you use "using namespace std". A vector is a class, similar to an array but has many advantages like resizing, easy access to the size of the vector etc. A parser is used to analyse text, can be useful if the user will be able to enter complicated commands.
int state = 0;
struct Room {
virtualvoid room() = 0;
};
struct RoomWithADoor : Room {
int newstate;
RoomWithADoor(int st) : newstate(st) {}
void room() {
cout << "there is a single door";
string str;
getline(cin, str);
if (str == "go") state = newstate;
}
}
int main() {
Room* map[] = {
new RoomWithADoor(1),
new RoomWithDescriptionAndTwoDoors("a nice room", "left", 3, "elevator", 2),
...
};
while(true) map[state] -> room();
}
Advanced. What I told you. One super-generalized room struct (though you can add more as in Intermediate if you want). state variable removed (I'm not even sure that's a good thing. Now there's a lot of pointer related mess. You might want to have std::map<std::string, int> paths; instead).
I either have them doing negative damage if the variables are initialized with the same random percentages (so it adds health) or one overpowers the other if i make one lesser
actually forget about that I decided to finish the rooms first before I do the monsters. But is there anyway to get rid of the double enter with getline
yeah I decided to make that stuff last and just use a "phantom" monster right now. Quick question: in int main why do I have to do the while loop with the switch statement? What is the purpose of that?
There are several rooms (functions). Each corresponds to a value of 'state'. The switch is needed to call the appropriate function when only 'state' is known.
Imagine that there is no loop. Now you enter room 0 and the program ends. To repeat the 'state' to function matching you need to put it in a loop. Note that normally this shouldn't be a while(true). Rather use while(state != -1) or something similar, so that you have a way to end it.
The variable state stores the current room you're in. At each iteration of the loop, the room's "scene" is played and state is updated to the room you chose to go. So, at each iteration, the switch statement calls the appropriate function according to your state (room).
#include <iostream>
#include <string>
usingnamespace std;
int state = 1;
void help();
void room1();
void room2();
int main()
{
while(state == -1)
{
switch(state)
{
case 1:
room1();
break;
case 2:
room2();
}
}
}
void help()
{
//This is where it shows the list of commands that they can do in a given area\\
return;
}
void room1()
{
string action;
//description
cout<<"\nWhat do you want to do?\n>";
if(action == "help")
{
help();
}
else
{
room2();
}
}
void room2()
{
string action;
state = 2;
//description
cout<<"\nWhat do you want to do?\n>";
if(action == "help")
{
help();
}
else
{
room1();
}
}
Not quite.. Firstly, line 14 should be !=. Though I guess that's a typo..
You're not using the state mechanism at all. Recursion is not a great choice. Try adding cout << "I'll be leaving room1 now"; after line 51 and see when that gets printed. Also, recursion abuses stack, so if you're intend to walk from from to room ~ 20000 times, your game should crash. While it is not going to happen, That should illustrate why recursion shouldn't be used without a necessity.
Change calls to room1() and room2() (only in lines 49, 69) to state = 1 and state = 2. And remove line 56. It's redundant. You're only going to be in that function when state == 2.
1) Yes line 14 was a typo
2) How can I put in cout<<"I'll be leaving room1 now"; after line 51 because that is outside every function
3) Yes that is good Ill change lines 49 and 69
#include <iostream>
#include <string>
usingnamespace std;
int state = 1;
void help();
void room1();
void room2();
int main()
{
while(state != -1)
{
switch(state)
{
case 1:
room1();
break;
case 2:
room2();
break;
}
}
}
void help()
{
cout<<"list of commands go here.";
return;
}
void room1()
{
string action;
cout<<"A description of the room. What do you want to do?\n>";
getline(cin, action);
if(action == "help")
{
help();
}
else
{
state = 2;
}
}
void room2()
{
string action;
cout<<"A description of the second room. What do you want to do?\n>";
getline(cin, action);
if(action == "help")
{
help();
}
else
{
state = 1;
}
}
i no that there is no \n this is just the rough bit