|
| 1 | +# Hangman in Java - for code sparring. |
| 2 | + |
| 3 | +This program tries to solve a game of hangman. It doesn't do a very good job - it's your job to fork it and create a new solution for it. |
| 4 | + |
| 5 | +## How To |
| 6 | + |
| 7 | +Fork this repo then clone it. To run the tests: |
| 8 | + |
| 9 | +```bash |
| 10 | +mvn test |
| 11 | +``` |
| 12 | + |
| 13 | +Tough stuff. To run the program: |
| 14 | + |
| 15 | +```bash |
| 16 | +mvn package |
| 17 | +java -jar target/Hangman-1.jar |
| 18 | +``` |
| 19 | + |
| 20 | +When you run the program you'll see something like this: |
| 21 | + |
| 22 | +```bash |
| 23 | +Erics-MacBook-Pro:HangmanJava paytonrules$ java -jar target/Hangman-1.jar |
| 24 | +Current Clue Is _ _ _ _ _ |
| 25 | +Current Clue Is _ _ _ _ _ |
| 26 | +Current Clue Is _ _ _ _ _ |
| 27 | +Current Clue Is _ _ _ _ _ |
| 28 | +Current Clue Is _ _ _ _ _ |
| 29 | +Current Clue Is _ _ _ _ _ |
| 30 | +Current Clue Is _ _ _ _ _ |
| 31 | +Current Clue Is _ _ _ _ _ |
| 32 | +Current Clue Is _ _ _ _ _ |
| 33 | +com.hangman.Game Over |
| 34 | +``` |
| 35 | + |
| 36 | +What this means is is that the clue length was five characters, and your player successfully guessed....nothing. To see why let's take a look at YourPlayer.java. |
| 37 | + |
| 38 | +```java |
| 39 | +public class YourPlayer implements Player { |
| 40 | + @Override |
| 41 | + public char GetGuess(List<Character> clue) { |
| 42 | + return 'a'; |
| 43 | + } |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +That's right `YourPlayer` - regardless of the clue - will guess the letter `a`. If it got `a` right, it guessed `a`. Wrong? `a`. It's a pretty stupid player. |
| 48 | + |
| 49 | +So to complete this exercise you will need to delete return 'a' - and instead return better guesses. How? Well look the parameter: |
| 50 | + |
| 51 | +`List<Character> clue`. The clue is exactly what you're seeing on screen. It is an array of characters where the '_' character means that you haven't gotten that location correct yet. |
| 52 | + |
| 53 | +This stumps people so let's go through an example. Let's assume the secret word is "aaron". The first time GetGuess is called it will get: |
| 54 | + |
| 55 | +`['_', '_', '_', '_', '_']` |
| 56 | + |
| 57 | +`YourPlayer` will guess 'a'. The next time GuetGuess is called it will look like: |
| 58 | + |
| 59 | +`['a', 'a', '_', '_', '_']` |
| 60 | + |
| 61 | +Naturally `YourPlayer` will guess 'a' again, because it is stupid. To complete this exercise you need to make `YourPlayer` good at hangman. |
| 62 | + |
| 63 | +## Tips |
| 64 | + |
| 65 | +* Maybe keep track of what you've guessed. |
| 66 | +* Vowels are good. |
| 67 | +* Your testing WILL BE GRADED! |
0 commit comments