Page 2 of 4

Re: Where to start...I'm the new guy btw

Posted: Fri Apr 24, 2009 3:56 pm
by MarauderIIC
2-D and 3-D arrays are easy to visualize as a rectangle or a cube.
Also, I'd recommend starting to split things out into different functions.

Re: Where to start...I'm the new guy btw

Posted: Fri Apr 24, 2009 4:09 pm
by rolland
Hello Simon, and welcome to the forums.
Terranova3y2 wrote:The game itself is actually terrible, I wouldn't force it on anyone but I decided to show the code here just to show my progress with C++
I wouldn't call it terrible, but you're entitled to your own opinion. ;) It's actually kind of interesting (I'm a sucker for nearly all text games).
Terranova3y2 wrote:I plan to add more things to the game as I learn them. (Health system, being able to restart after making a mistake, better story, multiple paths) but so far this is where I am.
Sounds like a very educational adventure into game development. Good luck.
Terranova3y2 wrote:I'm hoping that I'm structuring my programs well (please tell me if I'm not) and if you see anywhere I could improve it would be awesome.
Come to think of it, I've never actually made a text-based game. When I was starting, I jumped right into the thick of 2d games and crashed into the ground then quit for a few months... So I can't really offer any specific advice about the structure(I dislike all the if statements; just can't think of a replacement right now). I'll probably play around with making something like this tonight to see if I can come up with some good advice.

The only thing I have in terms of code improvement are a few linux-compatibility whines. :mrgreen:
1. You should probably explicitly #include <cstdlib> for system("pause").
2. That said, system("pause") only works on ms and dos (and ms-dos?), and some people have extreme prejudices against it anyway: (Things to Avoid in C/C++ -- system("pause"), Part 4 <-- has other things to avoid in c/c++ as well)
You may want to replace all the system pauses with (note: I'm NOT an expert on anything, so this could be horrible code; in which case, I appoligze for my incompetence.):

Code: Select all

cout << "Press ENTER to continue..." << endl;
 cin.ignore();
cin.get();
It would/should be easy to replace all instances using the replace all function of your IDE (I can't think of one that doesn't have it) should you choose to.

Well, I'm out. But before I go, I have a question. What publisher?? I must know.

Re: Where to start...I'm the new guy btw

Posted: Fri Apr 24, 2009 5:13 pm
by Terranova3y2
MarauderIIC wrote:2-D and 3-D arrays are easy to visualize as a rectangle or a cube.
Also, I'd recommend starting to split things out into different functions.
I was reading a bit more today about arrays, I think I'll have to go back over them again because I understand how they work but I can't really think of a reason why to use them just yet, I've still a looooong way to go :P

When my first version of the game was giving me the bug I spoke of before, I rewrote it and actually tried to split up all the different paths into their own functions but I couldn't get it working properly so I went back again to the very basics and got it working as I posted it lol. I'll definitely be going back to it and making use of functions.
rolland wrote:When I was starting, I jumped right into the thick of 2d games
That was my first instinct when I decided to start learning but I stopped myself and I'm forcing myself to learn it properly, it can be hard sometimes lol. I've messed around with RPG Maker and Game Maker in the past and thought to myself when I got to C++ "it can't be that hard" I couldn't have been more wrong haha.
rolland wrote:Sounds like a very educational adventure into game development. Good luck.
The reason I'm doing it like that is to keep myself interested and to keep my mind thinking of ways I can use what I'm learning in the game. I hope it keeps working ^^
rolland wrote:The only thing I have in terms of code improvement are a few linux-compatibility whines. :mrgreen:
Yeah I had a feeling that system("pause); would only be ms compatible. The reason I did it was for the promot to press any key to continue plus it was the only way I knew how to do it :cry:
I'll keep an eye out now to try and keep it as neutral as possible so all people can enjoy the future AAA command prompt text adventure regardless of OS :P
rolland wrote:Well, I'm out. But before I go, I have a question. What publisher?? I must know.
I worked for GOA, they have the european distribution of Warhammer Online. I was lead the lead english tester for their casual mmo games.

Re: Where to start...I'm the new guy btw

Posted: Fri Apr 24, 2009 6:16 pm
by eatcomics
Terranova3y2 wrote:Well the basics for my text game is complete. I think the problem before was the way I had it structured. I was seeing messages "in-game" that shouldn't have been there. I rewrote the game with a better structure and now its bug free :D

The game itself is actually terrible, I wouldn't force it on anyone but I decided to show the code here just to show my progress with C++

Code: Select all

program was here but I didn't want to take up too much space :P
I plan to add more things to the game as I learn them. (Health system, being able to restart after making a mistake, better story, multiple paths) but so far this is where I am.

I'm hoping that I'm structuring my programs well (please tell me if I'm not) and if you see anywhere I could improve it would be awesome.

I went out and bought a book on C++ yesterday and have been reading through it. I'm up to arrays and I get the general idea but now its talking about multidimensional arrays and I had to take a break.

P.S - Sorry for the double post, I thought it better to put it here than make a new thread.
hey it looks great, you seem to be doing pretty well... I remember the code from my first projects *shudders*... but your's looks very readable. As for structure, I'd recomend learning how to use functions and splitting up your files early on, it will help a lot trust me ;)

Re: Where to start...I'm the new guy btw

Posted: Fri Apr 24, 2009 7:21 pm
by Terranova3y2
eatcomics wrote:hey it looks great, you seem to be doing pretty well... I remember the code from my first projects *shudders*... but your's looks very readable. As for structure, I'd recomend learning how to use functions and splitting up your files early on, it will help a lot trust me ;)
Thanks :D

Well I've rewrote the program again this time using an array to hold the values for menu choices

Code: Select all

int menuArray[2] = {1,2}; // Array handling players choices
I've added in the use of functions too, I don't think I'm using them as well as I could though.

Code: Select all

// Main Menu Function
int MainMenu() 
{
	cout << "Welcome to my text game \n";
	cout << "\n";
	cout << "1.) Start Game\n";
	cout << "2.) Exit Game\n\n";
	cin >> playerInput;
	return 1;
}
I'm only showing one function because theres six in total and it will take up way too much space lol

heres my main too

Code: Select all

int main()
{
	MainMenu();

	if (playerInput == menuArray[0]) // Tests for players input
	{
		cout << "\nLets Begin!\n\n";
	}
	else
	{
		cout << "\nThank you for playing.\n\n";
		system("pause");
		return 0;
	}

	SecondScreen();

	if (playerInput == menuArray[0]) // Tests for players input
	{
		cout << "\nYou see what looks like a mansion,\n";
		cout << "surrounded by a misty forest.\n";
	}
	else
	{
		cout << "\nAfter searching for hours you find nothing.\n";
		cout << "\nGAME OVER!\n\n";
		system("pause");
		return 0;
	}

	ThirdScreen();

	if (playerInput == menuArray[0]) // Tests for players input
	{
		cout << "\nYou climb down the ladder into a narrow alley.\n";
	}
	else 
	{
		cout << "\nYou search for hours and find nothing.\n\n";
		cout << "GAME OVER!\n\n";
		system("pause");
		return 0;
	}

	FourthScreen();

	if (playerInput == menuArray[1]) // tests for players input
	{
		cout << "You see something on the door frame\n";
	}
	else
	{
		cout << "After searching for hours you find nothing. \n";
		cout << "\nGAME OVER!\n\n";
		system("pause");
		return 0;
	}

	FifthScreen();

	if (playerInput == 12 + 17) // tests if player answered correctly
		{
			cout << "The door opens slowly and you enter\n";
		}
	else
		{
			cout << "\nYou really suck at math\n";
			cout << "\nGAME OVER!\n";
			system("pause");
			return 0;
		}

	//Exiting Message
	cout << "\nThank you for playing my text game. \n";
	cout << "\nMore will be added soon.\n";
	system("pause");
	return 0;
}
Originally I had the if statements inside each function but I was getting a problem where regardless of the choice you made in the game it would just move onto the next function in the list so I kept them in the main for the time being until I figure out how to end the program inside a function.

Once I figure that out I think the next thing will to be expand the game a little and add in a health system. I think I have the idea for it in my head but we'll see.

Any critique would be greatly appreciated.

Re: Where to start...I'm the new guy btw

Posted: Sat Apr 25, 2009 12:06 pm
by eatcomics
Well it's good you're using functions, but there is still a lot of stuff in your main that could be in functions. Like you could make an input function that did all the input getting and result printing, then you could have an exit function... You know just to make main as small and easy to follow, but like I said before, using headers and seperate files is very helpful and putting your functions in different files would help organization even more. Like have a file that holds your input and output stuff, and an exit file...

For a program like this you're fine without it, but it would be good practice for when your programs get bigger and more complicated ;) But a mighty fine program none the less! :mrgreen:

Re: Where to start...I'm the new guy btw

Posted: Sat Apr 25, 2009 1:55 pm
by rolland
eatcomics wrote:hey it looks great, you seem to be doing pretty well... I remember the code from my first projects *shudders*... but your's looks very readable. As for structure, I'd recomend learning how to use functions and splitting up your files early on, it will help a lot trust me ;)
Agreed on every point.

Re: Where to start...I'm the new guy btw

Posted: Sat Apr 25, 2009 3:47 pm
by Terranova3y2
Thanks for all positive replies guys, keeps me motivated to keep going :D

I'm working away again tonight. I'll be taking out all the system commands and changing them with

Code: Select all

    cout << "Press ENTER to continue..." << endl;
    cin.ignore();
    cin.get();
    exit(0);
as rolland mentioned and probably making it into its own function too which will solve having the if statements in the main now that I know the exit command lol.

I assumed by the way you guys were saying make things into their own functions you meant it as the way I did it, but I noticed that you guys are saying to make them into their own files and headers. I'm not really sure what that means, would it be to save each function as its own program and then calling it into this one? It's something I'll look into as I go but any insight would be cool :)

Re: Where to start...I'm the new guy btw

Posted: Sat Apr 25, 2009 4:01 pm
by eatcomics
Terranova3y2 wrote: I assumed by the way you guys were saying make things into their own functions you meant it as the way I did it, but I noticed that you guys are saying to make them into their own files and headers. I'm not really sure what that means, would it be to save each function as its own program and then calling it into this one? It's something I'll look into as I go but any insight would be cool :)
Yes, that's exactly what we mean, split it into headers and include them in your main file; it makes large projects much more manageable, trust me. Just a good google search for c++ headers should tell you what you want to know ;)

Re: Where to start...I'm the new guy btw

Posted: Sat Apr 25, 2009 4:35 pm
by Terranova3y2
eatcomics wrote:
Terranova3y2 wrote: I assumed by the way you guys were saying make things into their own functions you meant it as the way I did it, but I noticed that you guys are saying to make them into their own files and headers. I'm not really sure what that means, would it be to save each function as its own program and then calling it into this one? It's something I'll look into as I go but any insight would be cool :)
Yes, that's exactly what we mean, split it into headers and include them in your main file; it makes large projects much more manageable, trust me. Just a good google search for c++ headers should tell you what you want to know ;)
Awesome. I'll be checking that out once I get all my functions working properly.

I forgot to mention, today I went on a big adventure to find the fabled "accelerated c++" book that everyone seems to say is god. I learnt a hard lesson... Ireland sucks for C++ books. I went to 3 different stores and only one of them had more than 3 C++ books, one didnt even have any!

In the end I ordered it online and it should be here by wednesday :D

Re: Where to start...I'm the new guy btw

Posted: Sat Apr 25, 2009 11:54 pm
by Martyj
I went the college route and learned java first. I'll be doing c++ this summer. Tbh learning java has helped me with more than just understanding java. I can read some c++ (can't write it though) can do php. Also it helps you understand the computer more. I'd recommend starting on java because it's a good language. It's not platform dependent, if you program on a mac you can use a java program on windows. I would not recommend using tutorials that just go through the language by showing you programs. Id recommend a book that goes over all of java.

What's nice about java is you get an api to use. The sun corp provides you with everything you would ever need and more.

Another thing that helps is a good IDE.

Here is the book I used for java
http://www.amazon.com/Building-Java-Pro ... 565&sr=8-1

That's my suggestion though, start with java.

Re: Where to start...I'm the new guy btw

Posted: Sun Apr 26, 2009 1:28 pm
by Terranova3y2
Cheers for the advice Martyj but I've already started with C++

Everything is now in a function for the game.

Code: Select all

int main()
{
	MainMenu();
	SecondScreen();
	ThirdScreen();
	FourthScreen();
	FifthScreen();
	ExitingMessage();
	return 0;
}
I had a look at a few different pages on using headers but I think for the moment it might be a bit over my head. I'll keep looking though and eventually change it. I'm working out how to make use a health system in the game now so I think that means I'll have to start using loops. Once I figure that out I'll be making the screen look a bit nicer with some formatting.

EDIT: Jesus I'm a retard. I've figured out headers, all functions are in there own files now.

Re: Where to start...I'm the new guy btw

Posted: Sun Apr 26, 2009 4:56 pm
by MarauderIIC
I had a MUD engine at one point.
I recommend making a "class" for your rooms, for starters. And probably use vectors and pointers. :)

You use multidimensional arrays/vectors/whatever for many things that you can visualize as a rectangle or a cube. Like for your text adventure, if you had at 2d array of rooms, then when you moved east/west you would increase/decrease the x coordinate, and when you moved north/south you would increase/decrease the y coordinate. If you could also move up & down, you might add a third dimension.

For my particular design though, I had a 1-D array with pointers to the other rooms that were exits. So like exits[0] was north, exits[1] was east, etc.

Don't worry if you don't understand all of this, you can at least use it as a jumping-off point for some more reading :)

Re: Where to start...I'm the new guy btw

Posted: Sun Apr 26, 2009 6:36 pm
by Terranova3y2
I understand a bit of what you said. I understand the principle of it but it's something I really need to read more about before I start trying to use.

I've made a class for my rooms now. Pretty much the entire program is in there lol.

My main now only calls one function

Code: Select all

int main()
{
	MainMenu();
	cin.ignore();
	cin.get();
	return 0;
}
Each room calls the next in its if statement

Code: Select all

if (playerInput == menuArray[0]) // Tests for players input
	{
		ThirdScreen();
	}
I've also formatted the text of each room a bit better so it looks nice.

Code: Select all

####################
#   My Text Game   #
#                  #
#    version 0.6   #
 ####################
I've already worked out a very basic health system too but I can't implement it until I start working with loops so thats what I'm reading about at the moment.

Re: Where to start...I'm the new guy btw

Posted: Mon Apr 27, 2009 7:15 am
by rolland
Marauder, that was... wow. I've never thought of it like that before. :bow: I will now burn that into my brain- hd(-1,0).