Level 0 Project Writeup
The aim of this project is to provide a basic introduction to programming. Whether you are new to programming or just want to get more familiar with a new language, this project is meant to help you get started.
This project is designed for those new to programming, or people who want to learn a new language. If you already have the necessary knowledge in one of the languages we use, then feel free to skip to level 1
Learning Goals
- How to set up a basic program skeleton ("Hello World!")
- How to use variables
- How to use conditionals
- How to use loops
- How to use functions
- How to manipulate strings
- How to generate random numbers
- How to parse command line arguments
- How to do user input/output
- How to do file input/output
Project Description
The project is to create a simple hangman game. The game should be able to read in a list of words from a file, and then randomly select one of those words to be the word that the user has to guess. The user should be able to guess letters until they either guess the word correctly or run out of guesses.
The following is a sample run of the program, assuming that the word list is in a file called words.txt
and the executable for the program is called hangman
:
$ ./hangman words.txt
Welcome to Hangman!
You have 5 guesses left.
You have already guessed:
_ _ _ _ _
Guess a letter: h
Incorrect! There are no h's in the word.
You have 4 guesses left.
You have already guessed: h,
_ _ _ _ _
Guess a letter: g
Correct! There is 1 g in the word.
You have 4 guesses left.
You have already guessed: g, h,
g _ _ _ _
Guess a letter: o
Incorrect! There are no o's in the word.
You have 3 guesses left.
You have already guessed: o, g, h,
g _ _ _ _
Guess a letter: a
Correct! There is 1 a in the word.
You have 3 guesses left.
You have already guessed: a, o, g, h,
g a _ _ _
Guess a letter: r
Correct! There is 1 r in the word.
You have 3 guesses left.
You have already guessed: r, a, o, g, h,
g a _ _ r
Guess a letter: e
Correct! There is 1 e in the word.
You have 3 guesses left.
You have already guessed: e, r, a, o, g, h,
g a _ e r
Guess a letter: z
Incorrect! There are no z's in the word.
You have 2 guesses left.
You have already guessed: z, e, r, a, o, g, h,
g a _ e r
Guess a letter: m
Correct! There is 1 m in the word.
Congratulations! You guessed the word correctly!
The word was: gamer
$ ./hangman words.txt
Welcome to Hangman!
You have 5 guesses left.
You have already guessed:
_ _ _ _ _
Guess a letter: a
Incorrect! There are no a's in the word.
You have 4 guesses left.
You have already guessed: a,
_ _ _ _ _
Guess a letter: b
Incorrect! There are no b's in the word.
You have 3 guesses left.
You have already guessed: b, a,
_ _ _ _ _
Guess a letter: c
Incorrect! There are no c's in the word.
You have 2 guesses left.
You have already guessed: c, b, a,
_ _ _ _ _
Guess a letter: d
Incorrect! There are no d's in the word.
You have 1 guesses left.
You have already guessed: d, c, b, a,
_ _ _ _ _
Guess a letter: e
Correct! There is 1 e in the word.
You have 1 guesses left.
You have already guessed: e, d, c, b, a,
_ e _ _ _
Guess a letter: f
Incorrect! There are no f's in the word.
You are out of guesses! The word was hello.
Recommendations
-
We expect that there is a wide range of programming skill among the members of the team. In the past, we've had people with no programming experience all the way to people with vast internship experience. So, when reading this tutorial we recommend a different course of action depending on how experienced you are.
-
For all members, we suggest using Visual Studio Code with any relevant language server extensions installed. This will provide you with syntax highlighting, code completion, and other useful features that will help you write code. However, it is important to note that VS Code is not a fully fledged IDE, and so you will still need to use the command line to perform many functions. However, if you are already comfortable with another text editor or IDE, then feel free to use that instead.