Originally Posted by
Salem
Like doing cout << a[0] << a[1] << a[2] ... << a[n], then discovering for loops.
Try a series of evolutionary steps
- simple console hangman with a fixed word list
- import word list from a file
- add difficulty levels - harder levels choose longer words, or limit response times.
- add demo mode which plays if user does nothing for a while
- switch to a graphical display
- add animation and sounds
- add a network server option to allow remote play
It's all the same program, but you'll learn a lot of new stuff with each step. One aspect of C++ you should focus on is the proper design of your classes. If you find yourself re-writing a lot of code with each new step, then you're doing something wrong (for example modifying the dictionary code if you add graphics).
I don't think I've ever finished a book AND done all the exercises.
Lol... I probably can't even start this since I haven't learned it. How do you get word from a word list anyway?
Also, I haven't learned designing classes either. The book has taught on designing functions, though.
Originally Posted by
dra
imo you should keep doing at least a few exercises per chapter. They help you apply what you learned and some of them can be quite challenging (in a good way).
(Some of) the exercises are indeed challenging. Just that after realizing I have only finished 1/3rd of the book so far, I want to at least try making something from what I have already learned.
Originally Posted by
DougDbug
I think you know enough to make a simple game... I suggest you take a break for a day or two and think about what you've learned, and how you might use that knowledge to make a game. If there's something you want your game to do, and you don't know how to do it, you should still be able to get started on the game. And, you can look-ahead through the book or do some online research. (Of course, you can only make text-based games at this point.*)
There are two major concepts that make programming (in any language) useful... The first is branching (if-statements and switch-statements). I assume you've learned about these. Branching is how programs "make decisions". The second is looping (doing stuff over-and-over), which you have learned. Once you understand these two concepts (and a few other basics) you can start to write useful, interesting, programs.
...I'm not saying it's as simple as that. C++ is a complex language, and there is much more to learn than how to make a loop or if-statement.
One more thing you'll need to know before making a game is how to make things random (unpredictable). If you haven't covered it yet, look-up rand().
* In case you don't know, there are no graphics in ANSI Standard C++. You'll need to use an additional graphics library. Before you jump-into something like that you should have a good understanding of Standard C++ (i.e. The topics in Accelerated C++.) These additional libraries are (mostly) function-libraries, so you need to have a good understanding of all-kinds of functions. (Some libraries use lots of structures and/or classes too.)
And as you probably know, most commercial games are written by a team of programmers. If it takes 20 programmers a year to make a game (20 man-years), it would take 20 years for one expert-programmer to write the same program/game!
And graphic artists and sound producer and etc. I guess...
I have learned about looping, but regarding branching, I have only learned about if and else statements. Never heard of switch before. Also, I forgot to mention it for some reason, but I just learned about iterator this chapter.
I was actually looking for some ideas on what simple program I can write that I should write, but I guess I will go with hangman.
Thank you for the help. Since I'm having school project and my final exams are coming soon (along with a whole bunch of games I want to play), I don't know when I will finish this, but I will post my code then (and when I get stuck).
I have one more thing I want to ask about what I have read in the book. When you write a function, what's the purpose of having the return type as reference?
For example, let's making up a function:
Code:
vector<double>& function(vector<double>& d)
{
}
The book mentions that when a reference is used as an argument, you are telling that you want to change the value of whatever you pass in the argument. But what is the reference to the return type for? Is it to save the workload since the value is returned, instead of being copied then returned?