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 knowlege in one of the languages we use, then feel free to skip to level 1 or even level 2.
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 peopl 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's important to note that VSCode is not a fully fledged IDE like you possibly are used to with Eclipse, or maybe even Visual Studio itself. This can be a good thing, however, as it forces you to learn the command line and other tools that you will always rely upon in software development. Ultimately, however, if you are more comfortable with another editor, then feel free to use that instead. The tutorial will just not be directed towards that editor/IDE setup.
-
No matter which of the below categories you fall under, you might still want to read the beginning section of each tutorial to get a working "Hello Word" running in the language if you have never used it before.
No Programming Experience (e.g. no CSE courses taken)
If you have no programming experience, we would recommend following one of the tutorials provided. These tutorials will walk you through the basics of programming and will help you get started with the project. If you reach a point where you feel like you want to try to do something on your own, we would recommend trying it, and then checking back in with the tutorial if you get stuck or want to verify that you are doing something correctly.
Minimal Programming Experiene (e.g. CSE 8A/8B/11)
If you are in or have only taken CSE 8A/8B/11 (basic object oriented programming), it is very possible that you only have experience in Java. If this is the case, then we would recommend starting with the tutorial of the language you want to work in up to getting a working "Hello World" running. Then, you can start working on the project. If you get stuck, then you can refer to the tutorial for help, or you can Google how to do "X" in the language. Because you have some programming experience, most of what you need to learn will be transfering your knowledge of Java to the new language. This is an incredibly important skill in software engineering, and professional software engineers do this all the time.
Some Programming Experience (e.g. CSE 12/15L, up to CSE 100)
If you've taken most of the lower div CSE courses, or maybe even CSE 100, then you've likely had experience in C (CSE 30), C++ (CSE 100), Java (CSE 11/12), and maybe even some others if you've learned it outside of class. If you have not taken CSE courses at UCSD, these would be equivalent to basic object oriented programming, basic data structures, and cursory level systems programming (e.g. C). If this is the case, then you might feel that you already know how to program, and you probably can easily do this assignment. If so, then feel free to skip to the level 1 project. However, if you do want to learn a new language, this kind of simple project is very effective because it forces you to learn all of the basics in another language, and starts to get you immersed in the syntax. In line with this, you could also just skim the tutorial in the language you want learn, then try to apply the knowledge in a level 1 or even level 2 project. Either way, you can do whatever you feel is best for your learning and engagement.
Much Programming Experience (e.g. taken multiple CSE upper divs)
Much of the advice from the previous section still applies here. Do whatever you feel is right for you.