Browse Source

integrate quiz and blackjack into shop

remotes/origin/develop
Max Gerbeth 2 years ago
parent
commit
3fe4b03d9e
  1. 3
      src/main/java/org/bitbiome/commands/CommandListener.java
  2. 6
      src/main/java/org/bitbiome/commands/QuizCommand.java
  3. 15
      src/main/java/org/bitbiome/commands/ShopCommand.java
  4. 26
      src/main/java/org/bitbiome/shop/Shop.java
  5. 4
      src/test/java/org/bitbiome/commands/ShopCommandTest.java

3
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());
}

6
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;

15
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<Item> 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"));
}
}

26
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<Item> allItems;
public ArrayList<Item> 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<Item> arrayList){
System.out.println("");
for(int i = 0; i < arrayList.size(); i++){

4
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);
}

Loading…
Cancel
Save