From 63ec77cf5c94070b91053cebf6f1e1f1c0890c09 Mon Sep 17 00:00:00 2001 From: FelixKrull Date: Tue, 15 Feb 2022 11:00:12 +0100 Subject: [PATCH] Change Output of choose method to match gameboard --- src/main/java/Player.java | 19 ++++++++++++++----- src/test/java/PlayerTest.java | 20 ++++++++++---------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/main/java/Player.java b/src/main/java/Player.java index fd04ee1..647ac5e 100644 --- a/src/main/java/Player.java +++ b/src/main/java/Player.java @@ -50,19 +50,28 @@ public class Player { } public int choose(ArrayList usableFigures) { + StringBuilder out = new StringBuilder("["); + Iterator it = usableFigures.iterator(); + for(int i = 0; i Collections.max(usableFigures) || input < Collections.min(usableFigures)) { + if (input > Collections.max(usableFigures) + 1 || input < Collections.min(usableFigures) + 1) { System.out.println("Die eingegebene Zahl war zu groß oder zu klein.\n" + - "Bitte nur Zahlen von " + Collections.min(usableFigures) + " bis " + Collections.max(usableFigures) + " eingeben."); + "Bitte nur Zahlen von " + (Collections.min(usableFigures) + 1) + " bis " + (Collections.max(usableFigures) + 1) + " eingeben."); return -1; } - return input; + return input - 1; } catch (Exception e) { System.out.println("Die Eingabe hat keine Zahl bekommen.\n" + - "Bitte nur Zahlen von " + Collections.min(usableFigures) + " bis " + Collections.max(usableFigures) + " eingeben."); + "Bitte nur Zahlen von " + (Collections.min(usableFigures) + 1) + " bis " + (Collections.max(usableFigures) + 1)+ " eingeben."); return -1; } } diff --git a/src/test/java/PlayerTest.java b/src/test/java/PlayerTest.java index 0a38a78..69a6892 100644 --- a/src/test/java/PlayerTest.java +++ b/src/test/java/PlayerTest.java @@ -174,16 +174,16 @@ public class PlayerTest { static Stream checkChooseMethodData() { return Stream.of( - Arguments.of("Figure 1 choosen", "1\n", new ArrayList<>(Arrays.asList(1,2,3,4)), 1), - Arguments.of("Figure 2 choosen", "2\n", new ArrayList<>(Arrays.asList(1,2,3,4)), 2), - Arguments.of("Figure 3 choosen", "3\n", new ArrayList<>(Arrays.asList(1,2,3,4)),3), - Arguments.of("Figure 4 choosen", "4\n", new ArrayList<>(Arrays.asList(1,2,3,4)),4), - Arguments.of("Index out of bounds choosen", "16\n",new ArrayList<>(Arrays.asList(1,2,3,4)), -1), - Arguments.of("Index out of bounds choosen", "-2\n",new ArrayList<>(Arrays.asList(1,2,3,4)), -1), - Arguments.of("Input a letter or char", "g\n",new ArrayList<>(Arrays.asList(1,2,3,4)), -1), - Arguments.of("Input a empty string", "\n",new ArrayList<>(Arrays.asList(1,2,3,4)), -1), - Arguments.of("Input a special character", "&\n",new ArrayList<>(Arrays.asList(1,2,3,4)), -1), - Arguments.of("Only one Figure available", "1\n", new ArrayList<>(List.of(1)),1), + Arguments.of("Figure 1 choosen", "1\n", new ArrayList<>(Arrays.asList(0,1,2,3)), 0), + Arguments.of("Figure 2 choosen", "2\n", new ArrayList<>(Arrays.asList(0,1,2,3)), 1), + Arguments.of("Figure 3 choosen", "3\n", new ArrayList<>(Arrays.asList(0,1,2,3)),2), + Arguments.of("Figure 4 choosen", "4\n", new ArrayList<>(Arrays.asList(0,1,2,3)),3), + Arguments.of("Index out of bounds choosen", "16\n",new ArrayList<>(Arrays.asList(0,1,2,3)), -1), + Arguments.of("Index out of bounds choosen", "-2\n",new ArrayList<>(Arrays.asList(0,1,2,3)), -1), + Arguments.of("Input a letter or char", "g\n",new ArrayList<>(Arrays.asList(0,1,2,3)), -1), + Arguments.of("Input a empty string", "\n",new ArrayList<>(Arrays.asList(0,1,2,3)), -1), + Arguments.of("Input a special character", "&\n",new ArrayList<>(Arrays.asList(0,1,2,3)), -1), + Arguments.of("Only one Figure available", "1\n", new ArrayList<>(List.of(0)), 0), Arguments.of("Figure not available", "4\n", new ArrayList<>(Arrays.asList(1,2)),-1) ); }