Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Text-Based) Games for C++ practice

Tags:

c++

A self-learning version of "20 questions" might be quite fun (if you are unfamiliar with this, there is quite a fun implementation of this at Guess the Dictator/Sit-Com Character).

An example session (based on questions from this web site):

Are you female?
> N
Are you overweight?
> N
Do you live in an apartment building?
> Y
Do you travel for your job?
> N
Do you have strange schemes to make money? 
> N
Do you live in California?
> N
Are you a new doctor?
> N
Is your father gay?
> Y
Are you gay?
> N
Are you an actor?
> N
Are both your parents gay?
> N
Are you black?
> N
I guess you are Chandler from Friends, am I right?
> Y

At this point, if I had answered N, I would have to say who I was thinking of, choose a question which distinguishes my chosen dictator/sit-com character from Chandler from Friends, and then say whether the answer to my question is "yes" or "no". This question is then remembered, and the program becomes slowly more and more knowledgeable about sit-com characters and dictators.

Depending on how you did this, this could help you learn:

  • Console I/O (to ask the user the questions)
  • Binary trees (each question is a node in the binary tree, and the child nodes are the questions you ask depending on the yes/no response)
  • File I/O (if you save the tree to disk)

I'm trying to remember some of the fun stuff I did way back when in my high school CS class. They're not all games but here it goes:

Text based (ASCII) animation - Basically I animated an ASCII dragon coming into the terminal, saying something, and leaving. After "drawing" each frame it was cleared so basically it was a frame-by-frame ASCII animation generator.

Maze - Used Unicode characters in kind of the same concept. I got keyboard input from the arrow keys and redrew your block going through the maze based on your input. Again, clearing the screen after each frame and printing out the text again.

Snake - similar concept as the above but it was a snake game.

Simple chat - this polled a shared text file on a central server in our school (that someone accidentally chmoded 0777) and facilitated basically a really simple chat room.

The beeper - this program became infamous at my school. Up until XP apparently the sound buffer on Windows computers could easily get overloaded by text. Running this caused the computer to beep until you turned it off (and in most instances also caused it to get bogged down so much you had to do a hard reboot). Definitely pissed off the administration of our high school. Plus it's only a 2-liner.

char o = 7;  
while(1) cout << o;

Anyway, not sure if this helped you get any ideas but just use your imagination. You can have a lot of fun without having to know a lot about programming. Just be creative.


Zork of course!


Facebook has some cool engineering puzzles that I like, but they may be a bit advanced for just starting out. I'm am a so-so C++ programmer, so I solved the puzzles first in Python, then in C++.

Check out: Facebook Engineering Puzzles

They seem to have everything from easy (Hors d'oeuvre) to quite challenging (Buffet).

I believe these puzzles were set up for recruiting, but they're fun on their own. (Maybe I'm kind of geeky?)

Plus, they have an added benefit: never know when you might need a job.


A good source of classic games is

http://www.atariarchives.org/basicgames/

The games are in old school basic but learning to translate and write these in any language would certainly be useful to gaining skills.

For instance if you wanted to tackle a few cards games this would be good to create headers, functions, classes and put code into libraries that could be re-used between two or more of the games.

It is not so much what you do as long it stretches your skills and moves from the trivial to something less so...

Find a mentor to review your code and make suggestions about what to try or do different.