From 1ef5d9bfb9b5f6ad9284aa00024656352a4d543a Mon Sep 17 00:00:00 2001 From: Chris Stevens Date: Mon, 13 Apr 2015 12:03:56 -0400 Subject: [PATCH 1/2] build alphabet, add guessedLetters array --- .../java/com/hangman/players/YourPlayer.java | 22 ++++++++++++++++--- .../com/hangman/players/YourPlayerTest.java | 15 +++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/hangman/players/YourPlayer.java b/src/main/java/com/hangman/players/YourPlayer.java index ddcfbd3..75e80ef 100644 --- a/src/main/java/com/hangman/players/YourPlayer.java +++ b/src/main/java/com/hangman/players/YourPlayer.java @@ -1,13 +1,29 @@ package com.hangman.players; import com.hangman.Player; - -import java.util.Arrays; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; +import java.util.Random; public class YourPlayer implements Player { + + public List alphabet = new ArrayList(); + private List guessedLetters = new ArrayList(); + @Override public char GetGuess(List currentClue) { + buildAlphabet(); + char letter = alphabet.get(0); + guessedLetters.add(letter); return 'a'; } + + public List GetGuessedLetters() { + return guessedLetters; + } + + private void buildAlphabet() { + for (int i = 0; i <= 25; i++) { + alphabet.add((char)i); + } + } } diff --git a/src/test/java/com/hangman/players/YourPlayerTest.java b/src/test/java/com/hangman/players/YourPlayerTest.java index d613f6b..8161ab3 100644 --- a/src/test/java/com/hangman/players/YourPlayerTest.java +++ b/src/test/java/com/hangman/players/YourPlayerTest.java @@ -2,6 +2,8 @@ import org.junit.Test; import java.util.Arrays; +import java.util.List; +import java.util.ArrayList; import static org.junit.Assert.assertEquals; public class YourPlayerTest { @@ -31,4 +33,17 @@ public void GuessesAWhenAIsThereAreAsInTheClueAsWell() { assertEquals('a', guess); } + + @Test + public void AddLetterToGuessedListAfterGuess() { + YourPlayer player = new YourPlayer(); + + player.GetGuess(Arrays.asList('_', '_', '_')); + List guessedLetters = player.GetGuessedLetters(); + + List expectedList = new ArrayList(); + expectedList.add('a'); + + assertEquals(expectedList, guessedLetters); + } } From b21a362dec6226a5faa9e7e41404a59c733c89ac Mon Sep 17 00:00:00 2001 From: Chris Stevens Date: Mon, 13 Apr 2015 15:21:22 -0400 Subject: [PATCH 2/2] fix compile error --- src/main/java/com/hangman/players/YourPlayer.java | 6 +++--- src/test/java/com/hangman/players/YourPlayerTest.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/hangman/players/YourPlayer.java b/src/main/java/com/hangman/players/YourPlayer.java index 75e80ef..db3fefd 100644 --- a/src/main/java/com/hangman/players/YourPlayer.java +++ b/src/main/java/com/hangman/players/YourPlayer.java @@ -2,7 +2,6 @@ import com.hangman.Player; import java.util.ArrayList; import java.util.List; -import java.util.Random; public class YourPlayer implements Player { @@ -14,7 +13,7 @@ public char GetGuess(List currentClue) { buildAlphabet(); char letter = alphabet.get(0); guessedLetters.add(letter); - return 'a'; + return letter; } public List GetGuessedLetters() { @@ -22,7 +21,8 @@ public List GetGuessedLetters() { } private void buildAlphabet() { - for (int i = 0; i <= 25; i++) { + for (int i = 'a'; i <= 'z'; i++) { + System.out.print(i); alphabet.add((char)i); } } diff --git a/src/test/java/com/hangman/players/YourPlayerTest.java b/src/test/java/com/hangman/players/YourPlayerTest.java index 8161ab3..1e42ed2 100644 --- a/src/test/java/com/hangman/players/YourPlayerTest.java +++ b/src/test/java/com/hangman/players/YourPlayerTest.java @@ -4,7 +4,7 @@ import java.util.Arrays; import java.util.List; import java.util.ArrayList; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; public class YourPlayerTest { @Test @@ -13,7 +13,7 @@ public void GuessesAWhenThereAreNoSuccessfulCharactersGuessedYet() { char guess = player.GetGuess(Arrays.asList('_', '_', '_')); - assertEquals('a', guess); + assertTrue(player.alphabet.contains(guess)); } @Test