Hai everyone, i made my very first game (hmm very first app for that matter) today, and decided to share the source with all of you. If something can be optimized, or you can answer one of my commented questions, please do tell me.
Its just a little text-based hangman game, but im a little proud of it lol.
http://pastebin.com/uDfqDppi
Also one more thing, what should i make next to help further my c++ knowledge (This hangman game was the only thing i could think of tbh lol) ?
EDIT: lol ignore the word list, it was just for testing with friends :P.
My first game
Moderator: Coders of Rage
Re: My first game
It looks like you have a few 'questions' in comments within the code, so I'll go ahead and answer them.
1.) So if you don't want to have to specify any dimensions of an array, you might want to try dynamically allocating the array itself, or since your using C++, a vector of vectors can also work well.
2.) Yeah rand() has no max, but you can just use % for that. So rand() % n will return a number between 0 and (n - 1). You can also go further with that and add offsets and such... This is one of the reasons it's desirable to make your own random number generator.
3.) sizeof won't return the size of an array. Really, an array is just a pointer to the first element, and by using the [] operator, your actually like 'seeking' through the memory from that pointer, in intervals of the size of the first element.
4.) case 'y', 'Y' wouldn't work because that's not the syntax of a switch statement. Alternatively, what you can do, is make everything upper (or lower) case, so you don't have to provide support like that for both upper and lower.
That's all I saw where you were like 'wtf', if there's something I missed let me know...
But one thing I see is that your using C++, and yet using printf instead of std::cout... So, you might want to use std::cout; Not sure about pros and cons of each and I don't want to start a C vs. C++ flame in this thread...
Now as to what you should work on next. It really depends with where you want to go from here. Personally, I never made a single console game. I made small examples that did nothing more than do simple operations, just to test my knowledge. Once I thought I had it down, I moved straight to incorporating an API to make graphical games. So, that's one thing you can do... the other choice is making another console game, in which case I'd say try to make a simple real time game (maybe pong?)
1.) So if you don't want to have to specify any dimensions of an array, you might want to try dynamically allocating the array itself, or since your using C++, a vector of vectors can also work well.
2.) Yeah rand() has no max, but you can just use % for that. So rand() % n will return a number between 0 and (n - 1). You can also go further with that and add offsets and such... This is one of the reasons it's desirable to make your own random number generator.
3.) sizeof won't return the size of an array. Really, an array is just a pointer to the first element, and by using the [] operator, your actually like 'seeking' through the memory from that pointer, in intervals of the size of the first element.
4.) case 'y', 'Y' wouldn't work because that's not the syntax of a switch statement. Alternatively, what you can do, is make everything upper (or lower) case, so you don't have to provide support like that for both upper and lower.
That's all I saw where you were like 'wtf', if there's something I missed let me know...
But one thing I see is that your using C++, and yet using printf instead of std::cout... So, you might want to use std::cout; Not sure about pros and cons of each and I don't want to start a C vs. C++ flame in this thread...
Now as to what you should work on next. It really depends with where you want to go from here. Personally, I never made a single console game. I made small examples that did nothing more than do simple operations, just to test my knowledge. Once I thought I had it down, I moved straight to incorporating an API to make graphical games. So, that's one thing you can do... the other choice is making another console game, in which case I'd say try to make a simple real time game (maybe pong?)
- Kyosaur
- Chaos Rift Cool Newbie
- Posts: 78
- Joined: Tue Jul 13, 2010 2:00 am
- Favorite Gaming Platforms: PS2,PS3,NDS
- Programming Language of Choice: C++
Re: My first game
1. Im very new to c++, but i'll look into both of those.XianForce wrote:It looks like you have a few 'questions' in comments within the code, so I'll go ahead and answer them.
1.) So if you don't want to have to specify any dimensions of an array, you might want to try dynamically allocating the array itself, or since your using C++, a vector of vectors can also work well.
2.) Yeah rand() has no max, but you can just use % for that. So rand() % n will return a number between 0 and (n - 1). You can also go further with that and add offsets and such... This is one of the reasons it's desirable to make your own random number generator.
3.) sizeof won't return the size of an array. Really, an array is just a pointer to the first element, and by using the [] operator, your actually like 'seeking' through the memory from that pointer, in intervals of the size of the first element.
4.) case 'y', 'Y' wouldn't work because that's not the syntax of a switch statement. Alternatively, what you can do, is make everything upper (or lower) case, so you don't have to provide support like that for both upper and lower.
That's all I saw where you were like 'wtf', if there's something I missed let me know...
But one thing I see is that your using C++, and yet using printf instead of std::cout... So, you might want to use std::cout; Not sure about pros and cons of each and I don't want to start a C vs. C++ flame in this thread...
Now as to what you should work on next. It really depends with where you want to go from here. Personally, I never made a single console game. I made small examples that did nothing more than do simple operations, just to test my knowledge. Once I thought I had it down, I moved straight to incorporating an API to make graphical games. So, that's one thing you can do... the other choice is making another console game, in which case I'd say try to make a simple real time game (maybe pong?)
2. Yeah had to lookup a tut for that, im used to rand(int max, int min = 0), so was an odd concept of having no params / needing to be seeded lol.
3.Well sizeof does return the size, but not how im used to (sizeof(Array) would return the first dimension's size, and sizeof(Array[]) would return the second ... any other way to do this? maybe with pointers (no idea when to use these and references except for certain functions tbh).
4. That blows D: ... So there's no way to go: case 1 .. 115: ?
You did miss the bottom one btw (most of the WTF's except the array dimension/the bottom variable ones are me "asking" if there's an alternative way to go about doing said task). Anyways, is variable creation handled at compile time, or is it real time (i guessed that its a mix of both. Everything but "new" *dynamic memory stuff i mean* is done at compile? makes sense i guess lol).
Im looking into a sdl/opengl/directx, but having a tough time picking one. I assume directx is more favored by the gaming industry ? Once i get a litte used to them, i'll start working on pong (my main goal is pacman and asteroids! lol).
Thanks for replying btw :D. If you have any optimizing tips for me, dont be shy btw lol (hard to optimize things when you dont know anything about how things are handled / anything about the compiler :\).
Re: My first game
Uhh. Variables aren't created at compile time. Then you'd have a bunch a variables floating around that aren't in use. All variables are created at runtime.
I wouldn't really know where to optimize it, because I didn't look through it much. But I don't think optimizing is too important for you at this point.
DirectX is going to favored in the game industry, but it's a little confusing to understand at first.I'd definitely recommend buying some sort of book on it. I currently have two books that use DirectX -> Beginning Game Programming (an alright book, but seems to focus more on teaching DirectX rather than game development concepts) and Game Coding Complete (GREAT book!). I don't use DirectX too often, because I don't like trading the cross platform nature of my code, along with some simplicity just to use something that is 'more favored in the games industry'.
If you really just want to jump into game development I'd recommend SDL or SFML. With DirectX your going to have to go through plenty of hoops just to get something small going, but with SDL and SFML, things are a lot simpler. Then when your ready, you can integrate OpenGL with SDL or SFML.
I wouldn't really know where to optimize it, because I didn't look through it much. But I don't think optimizing is too important for you at this point.
DirectX is going to favored in the game industry, but it's a little confusing to understand at first.I'd definitely recommend buying some sort of book on it. I currently have two books that use DirectX -> Beginning Game Programming (an alright book, but seems to focus more on teaching DirectX rather than game development concepts) and Game Coding Complete (GREAT book!). I don't use DirectX too often, because I don't like trading the cross platform nature of my code, along with some simplicity just to use something that is 'more favored in the games industry'.
If you really just want to jump into game development I'd recommend SDL or SFML. With DirectX your going to have to go through plenty of hoops just to get something small going, but with SDL and SFML, things are a lot simpler. Then when your ready, you can integrate OpenGL with SDL or SFML.
- WSPSNIPER
- Chaos Rift Regular
- Posts: 145
- Joined: Sun Jan 03, 2010 6:19 pm
- Current Project: top down shooter
- Favorite Gaming Platforms: ps3
- Programming Language of Choice: c++
Re: My first game
i would agree to go with SFML or SDL but if you WANT to go with dirextx then go for it, learn as many api's as possiable but i have to say i prefer opengl to d3d so just keep that in mind, SFML is made with opengl and SDL can utilize opengl but d3d is d3d with no helpXianForce wrote: If you really just want to jump into game development I'd recommend SDL or SFML. With DirectX your going to have to go through plenty of hoops just to get something small going, but with SDL and SFML, things are a lot simpler. Then when your ready, you can integrate OpenGL with SDL or SFML.
Re: My first game
This is not a good recommendation. Learning APIs does not make you a good programmer.WSPSNIPER wrote:learn as many api's as possiable
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: My first game
I agree. Research as many APIs as possible, and choose what suits your needs best. While knowing every API would be great for a resume, it's completely unnecessary. Learning an API takes time, and learning every one of them is a ridiculous goal to set for yourself.K-Bal wrote:This is not a good recommendation. Learning APIs does not make you a good programmer.WSPSNIPER wrote:learn as many api's as possiable
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
-
- Chaos Rift Junior
- Posts: 209
- Joined: Thu Feb 12, 2009 8:46 pm
Re: My first game
That's an uninformatively bold statement to not supply any proof or reasoning for. Note that WSPSNIPER did not say that learning different API's makes you a better programmer, but taken lightly, it's an excellent recommendation.K-Bal wrote:This is not a good recommendation. Learning APIs does not make you a good programmer.WSPSNIPER wrote:learn as many api's as possiable
Depending on the type or size of the architecture you are learning, you may spend years learning its traps, pitfalls, and corner cases, but you may never fully learn everything about it. Take the time to familiarize yourself with many architectures, and make a golden attempt to learn the core basics; concepts, features, and general API. This will allow you to rapidly gain a more intimate familiarity with it if you so choose.
But stick with one, this will allow you to effectively learn the more advanced features that your API, library, or language uses, and you'll be able to piece together information more quickly. If you find yourself in a situation where your library does not support a certain feature, or if you do not have the freedom to use the architecture you are most comfortable with, then you may find that making the switch to something else is easier and less frustrating if you are already familiar with it. And if you make an attempt at familiarizing yourself with many decent API's, then you may be able to grasp the basic structure and concepts of other similar API's more quickly.
Learning is never a bad idea.
Last edited by wearymemory on Sat Jul 24, 2010 8:36 pm, edited 2 times in total.
- WSPSNIPER
- Chaos Rift Regular
- Posts: 145
- Joined: Sun Jan 03, 2010 6:19 pm
- Current Project: top down shooter
- Favorite Gaming Platforms: ps3
- Programming Language of Choice: c++
Re: My first game
i agree that learning an api dosent make you a better programmer but being able to to program in many different situations provided by the different api dose, if you master one api you will be good at that but if you learn the core ideas behind how many are constructed you start to understand that there are many solutions to a single problem and you have an advantage when faced with a problem because you know many different things about what you are trying to do not just what the one api of choice has to offer. and if you want to use a different api it will be easy to pick up if your use to learning different things but if you only know sfml and you want to use somthing like d3d you will have almost no idea what is happening but if you use opengl and sfml you will see how sfml uses opengl to create its image functions and stuff so you will understand d3d more then if you never learned opengl and just mastered sfml. ( i know opengl is not an good example but you get what i mean )K-Bal wrote:This is not a good recommendation. Learning APIs does not make you a good programmer.WSPSNIPER wrote:learn as many api's as possiable