Learn Programming in Java


<<Previous | ToC | Next >>

Seaman

Vivian Killian provided the basic structure of this program, which is basically a rename of a traditional pencil-and-paper game. The name is a pun, "see man" because as you play the game, if you guess the letters wrong, you see more and more of the sailor (seaman) on the boat.

It's always a good idea to set this out in English (or whatever language you think in) so that you know what you are aiming for; this is Vivian's contribution:

1. Pick a word
2. Draw dashes (computer displays this)
3. Guess a letter (loop!)

If the letter is wrong, draw a body part
If the letter is correct, replace the dashes with the letter


The game play requires nested loops (iteration, one of the Five Concepts in the table below). For each turn, the program needs to accept a letter guess (that would be Input in the Five Concepts), and then redraw the new state of the game (Output). Drawing the state of the game usually means putting the boat up with some part of the seaman's body; we can do this with "ASCII graphics" which is typing out on the console letters and/or special characters, so the result looks (more or less) like a picture. We programmers did this for years, long before we had graphics displays. It's a little tricky, so at first we'll play the game by counting the mistakes (but not drawing anything).

The program types out (in another loop) dashes for the unguessed letters and substituting the actual letters that have been guessed correctly. A third (inner) loop compares each guessed letter to every letter in the word (Conditional). And if you want the game to restart after each game ends, that would be another (outer) loop. We can do all of this inside the "StartHere" main() program we have been modifying.

But let's start earlier than that, and try to make this a better English program, starting with the first line. Who picks a word? If the computer picks the word, we would need a dictionary and a bunch of stuff too complicated for this early in your career. So let's say a human player picks the word. If the computer is going to keep score, we need the computer to know what that word is. How would you instruct the computer to do that input (in English)? You know how to do that, right? We did it in the Kitchen computer.


 

So put your improved first line (or more, if you need it) in the entry panel, and then turn the page.

Five Basic Concepts
Sequence
Iteration
Conditional
Variables
Input/Output

 

<<Previous | ToC | Next >>

Revised: 2021 June 3