Game from Scratch ? C++

Started by
19 comments, last by Stroppy Katamari 11 years, 4 months ago
Guys, I am back and now I have started learning C++ and know to create codes( But still on basics tongue.png ) . Can any one of you give me a code for making a game ( like tic tac toe) from scratch in C++. Please also explain it so i could understand it.
Advertisement
To write your own game from scratch, use this:


int main(void)
{
return 0;
}


Now you will have to add your own code to it, and turn it into a game.
Just start small. Take ultramailman's post and go from there. Store the state of the tic-tac-toe game in an array, 9 separate variables, or a string you constantly parse. You can output a grid easily using the pipe | and the dash - characters. Input can be as simple as entering a number from 1 to 9 (or 0 to 8) that represents the space you want to take your turn in. Save that and move on to the next turn. Don't let someone select a space that already has an X or O.

Maybe when that is working, create a little "AI" that you can play against. Get creative, make it a 4x4 grid instead of a 3x3. Just start small, work piece by piece, and you will start to see your game.
Are you using an engine or library at all for anything visual or is it all text output at this point?

But still on basics


If you are still on basics, you can't make a game.
Learn the language first.
An invisible text.
That depends. A random number guessing game is just a few lines of code and doesn't require intricate knowledge of a programming language.

That depends. A random number guessing game is just a few lines of code and doesn't require intricate knowledge of a programming language.


GameCreator has a valid point. My suggestion is to start small. Take GameCreator's advice and create a random number game. After you finish that, take a stab at another little game. You need to build up your skills (which is often overlooked by new programmers).


[quote name='Sugavanas' timestamp='1355624564' post='5011136']
But still on basics


If you are still on basics, you can't make a game.
Learn the language first.
[/quote]
This is the hard, but very real truth. You can't create a game in a language if you do not know the language. Learn your basics and learn them well.

EDIT: I figured I would answer your original question as well. If you look online quite a few companies have released the source code to their games. Id Software's Doom 3 comes to mind. You can find the source code here. With that being said, be prepared to have it handed to you. The level of coding that goes into games is extremely high. With that being said, however, studying other peoples code is an important part of learning to program.

"The code you write when you learn a new language is shit.
You either already know that and you are wise, or you don’t realize it for many years and you are an idiot. Either way, your learning code is objectively shit." - L. Spiro

"This is called programming. The art of typing shit into an editor/IDE is not programming, it's basically data entry. The part that makes a programmer a programmer is their problem solving skills." - Serapth

"The 'friend' relationship in c++ is the tightest coupling you can give two objects. Friends can reach out and touch your privates." - frob


The level of coding that goes into games is extremely high. With that being said, however, studying other peoples code is an important part of learning to program.


I very much agree that studying code is an important factor, but I don't believe it's applicable yet to the OP.
At this stage a good understanding of the language is a priority, especially so with C++ as there are so many ways to write functioning but terribly written C++ code. Source code for finished games might not always reflect the best practices, or might just do some things in a terribly hack-ish way because of time constraints or because something needed to be fixed quickly (I haven't looked at the source code for Doom myself, so I couldn't say whether this applies here).


Getting code for complete games just handed to you is not going to be all too helpful right now, it mostly encourages copy-paste behaviour and unless every technique/pattern/whatever used in the code is thoroughly documented, you probably won't understand the reason why the developer chose to use a certain technique at a certain location, or what the technique is even supposed to do.

The important thing now is to understand how to use the basic paradigms provided by C++ correctly at an elementary level, and how to properly implement problem solutions with these. Learn about the basic OOP principles, learn about what kind of functionality C++ provides to support OOP, learn about what kind of useful stuff the C++ standard library provides, etc. and work your way up starting from a very simple 'hello world' application while applying the concepts you've learned and using the data structures (eg. lists, maps, vectors, queues, stacks, etc.) and functionality you've read about.

Once you have some knowledge of object-oriented design and the tools your language provides it'll become clearer to you how to implement a simple game such as tic-tac-toe yourself.

I gets all your texture budgets!

Here you go: https://github.com/TTimo/doom3.gpl
It's far better than tic-tac-toe.
Copy pasting doesnt work in game programming (or programming for that matter), learn your language well then consider game programming, even using an engine like ogre / panda3d would require you to understand your language. Think of it like this, what you are trying to do is make a movie on your own but in French and you can only understand basic french words, despite having all the equipment and resources you cant speak French very well.

Learn the language then move onto the movie,.. I mean game

This topic is closed to new replies.

Advertisement