From 3fe4b03d9e426a5237dd12cae7063df4e35ae6d9 Mon Sep 17 00:00:00 2001 From: Max Gerbeth Date: Tue, 7 Feb 2023 13:15:52 +0100 Subject: [PATCH] integrate quiz and blackjack into shop --- .../bitbiome/commands/CommandListener.java | 3 --- .../org/bitbiome/commands/QuizCommand.java | 6 ++--- .../org/bitbiome/commands/ShopCommand.java | 15 ++++++++--- src/main/java/org/bitbiome/shop/Shop.java | 26 +++++++++++++++++-- .../bitbiome/commands/ShopCommandTest.java | 4 +-- 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/CommandListener.java b/src/main/java/org/bitbiome/commands/CommandListener.java index bd1e520..159785f 100644 --- a/src/main/java/org/bitbiome/commands/CommandListener.java +++ b/src/main/java/org/bitbiome/commands/CommandListener.java @@ -18,9 +18,6 @@ public class CommandListener { commands.put("quit", new QuitCommand()); commands.put("location", new LocationCommand()); commands.put("travel", new TravelCommand()); - commands.put("quiz", new QuizCommand()); - commands.put("blackjack", new BlackJackCommand()); - commands.put("shop", new ShopCommand()); } diff --git a/src/main/java/org/bitbiome/commands/QuizCommand.java b/src/main/java/org/bitbiome/commands/QuizCommand.java index 59d215f..976225d 100644 --- a/src/main/java/org/bitbiome/commands/QuizCommand.java +++ b/src/main/java/org/bitbiome/commands/QuizCommand.java @@ -11,9 +11,9 @@ import java.util.Date; import java.util.Random; import java.util.Scanner; -public class QuizCommand implements CommandAPI { +public class QuizCommand { private Scanner quizScanner; - @Override + public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { quizScanner = new Scanner(System.in); @@ -78,7 +78,7 @@ public class QuizCommand implements CommandAPI { } public static int addGold() { - String playerpath = "src/main/resources/ssplayerconfig.json"; + String playerpath = "src/main/resources/playerconfig.json"; JSONObject playerconfig = JsonParser.getJSONObject(playerpath); int gold = playerconfig.getInt("gold"); gold = gold + 5; diff --git a/src/main/java/org/bitbiome/commands/ShopCommand.java b/src/main/java/org/bitbiome/commands/ShopCommand.java index 1beb579..b4d8fbd 100644 --- a/src/main/java/org/bitbiome/commands/ShopCommand.java +++ b/src/main/java/org/bitbiome/commands/ShopCommand.java @@ -1,5 +1,6 @@ package org.bitbiome.commands; +import org.bitbiome.classes.BlackJack; import org.bitbiome.classes.Colors; import org.bitbiome.classes.TravelEngine; import org.bitbiome.shop.Item; @@ -10,13 +11,16 @@ import java.util.Scanner; public class ShopCommand implements CommandAPI{ - Shop shop = new Shop(); + Shop shop; + BlackJack blackJack; public ShopCommand(){ } @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { + shop = new Shop(scanner, isRunning, message, travelEngine); + blackJack = new BlackJack(travelEngine.getPlayer().getName()); System.out.println(Colors.ANSI_BG_YELLOW + Colors.ANSI_BLACK + "Willkommen im Shop!" + Colors.ANSI_RESET); ArrayList currentItems = shop.loadCurrentShopItems(); @@ -25,7 +29,8 @@ public class ShopCommand implements CommandAPI{ System.out.println("Was willst Du hier im Shop?"); System.out.println("Etwas kaufen: 1"); System.out.println("Das Quiz spielen: 2"); - System.out.println("Den Shop verlassen: 3"); + System.out.println("Blackjack spielen: 3"); + System.out.println("Den Shop verlassen: 4"); String input = scanner.nextLine(); if(validInput(input)){ @@ -60,8 +65,10 @@ public class ShopCommand implements CommandAPI{ } } } else if(input.equals("2")){ - //shop.quiz() + shop.quiz(); } else if(input.equals("3")){ + shop.blackJack(); + }else if(input.equals("4")){ System.out.println("Der Shop wurde verlassen!"); break; } @@ -72,7 +79,7 @@ public class ShopCommand implements CommandAPI{ } public static boolean validInput(String input){ - return (input.equals("1") || input.equals("2") || input.equals("3")); + return (input.equals("1") || input.equals("2") || input.equals("3") || input.equals("4")); } } diff --git a/src/main/java/org/bitbiome/shop/Shop.java b/src/main/java/org/bitbiome/shop/Shop.java index 9bcd1d9..fdc2228 100644 --- a/src/main/java/org/bitbiome/shop/Shop.java +++ b/src/main/java/org/bitbiome/shop/Shop.java @@ -2,6 +2,11 @@ package org.bitbiome.shop; import org.bitbiome.classes.Colors; import org.bitbiome.classes.JsonParser; +import org.bitbiome.classes.TravelEngine; +import org.bitbiome.commands.BlackJackCommand; +import org.bitbiome.commands.QuitCommand; +import org.bitbiome.commands.QuizCommand; +import org.bitbiome.commands.ShopCommand; import org.json.JSONArray; import org.json.JSONObject; @@ -12,13 +17,25 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashSet; import java.util.Random; +import java.util.Scanner; public class Shop { public ArrayList allItems; public ArrayList currentShopItems; public JsonParser jsonParser = new JsonParser(); + public QuizCommand quizCommand = new QuizCommand(); + public BlackJackCommand blackJackCommand = new BlackJackCommand(); + public Scanner scanner; + public boolean isRunning; + public String message; + public TravelEngine travelEngine; + + public Shop(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngin) { + this.scanner = scanner; + this.message = message; + this.isRunning = isRunning; + this.travelEngine = travelEngin; - public Shop() { try { allItems = loadAllItems(); currentShopItems = loadPartofItems(allItems, 3); @@ -216,9 +233,14 @@ public class Shop { } public void quiz(){ - //ToDo + quizCommand.performCommand(scanner, isRunning, message, travelEngine); } + public void blackJack(){ + System.out.println(""); + blackJackCommand.performCommand(scanner, isRunning, message, travelEngine); + System.out.println(""); + } private void printArrayList(ArrayList arrayList){ System.out.println(""); for(int i = 0; i < arrayList.size(); i++){ diff --git a/src/test/java/org/bitbiome/commands/ShopCommandTest.java b/src/test/java/org/bitbiome/commands/ShopCommandTest.java index d80674d..5dad043 100755 --- a/src/test/java/org/bitbiome/commands/ShopCommandTest.java +++ b/src/test/java/org/bitbiome/commands/ShopCommandTest.java @@ -7,7 +7,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; public class ShopCommandTest { final ShopCommand shopCommand = new ShopCommand(); - final Shop shop = new Shop(); + final Shop shop = new Shop(null, true, null, null); @Test public void testValidInput1(){ boolean expected = true; @@ -28,7 +28,7 @@ public class ShopCommandTest { } @Test public void testValidInput4(){ - boolean expected = false; + boolean expected = true; boolean result = shopCommand.validInput("4"); assertEquals(expected, result); }