Skip to content

austenstrine/hangman

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

hangman

A small, functional C++ hangman game

Hello! I've made this game as a final project for a C++ class.

I'm a beginner at C++, so there's a lot of things I'm still very new at. If I'm making some big mistakes, please let me know! I'm eager to learn - just be nice! I follow the whitespace convention of double tabbing loops, if statements and other complex statements, and single tabbing initializations, function calls, declarations, and other simple lines of code. I'm also double returning in between unrelated, but geographically close blocks of code to help distinguish between the two. I also put the else's for if statements on their own line, without any braces. I've started to experiment with starting the bodies of certain statements on the same line as their beginning brace, but I recently decided that I prefer the whitespace of one brace taking up an entire line - this also leaves more room for commenting. If I haven't fixed that yet, sorry! I've also taken to using comments to provide detailed end statements, describing both the code that is ending at the closing brace, and the function of the code. Generally, the type of statement is in all caps at the end, the function of the statement is in camel case in the middle, and if additional clarification is needed, it is also camel cased, but placed at the beginning with an underscore after it. I would like to get in the habit of extensively using functions with very long, descriptive names in the main function, so that the main function reads like pseudocode, and the sattelite functions have the nitty-grity. This is, of course, pretty complicated in terms of passing variables to those functions, and sometimes may be completely impractical(so I may cheat on occasion), but I think it will provide an additional level of readability and streamlining that will save more time than it spends.

In this code, I use a plaintext file as the source for the words in the english language, and transfer it into a vector of strings. I use a vector so that the source file may be changed - perhaps I will eventually write code that will have fun themes (Pirates vs ninjas?) and insert related words into this source file. I randomly select one of those words from that vector as the word to be guessed by the player. The rules of the game are: The player gets 1.5 as many guesses as letters in the word, rounded down to the nearest integer. If the player guesses correctly, they do not lose a guess. The player may choose to try to guess the full word, and if they guess wrong, they immediately lose. Because I want it to be fun, that one full-word guess will not count if the player accidentally puts in non-letters or too few/many letters - to an extent. The same mistake made repeadedly must be punished! (Lightheartedly of course.) I also provided some simple Ascii illustrations depicting Mr. Ascii's unfortunate walk towards a quick drop and a sudden stop, to provide some macabre humor and a bit of tension to spice things up. This is hangman after all!

Feel free to play with it, and of course, enjoy!

About

A small, functional C++ hangman game

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages