diff --git a/domain/Dice.java b/domain/Dice.java new file mode 100644 index 0000000..f18854c --- /dev/null +++ b/domain/Dice.java @@ -0,0 +1,4 @@ +package domain; + +public class Dice { +} diff --git a/domain/Game.java b/domain/Game.java new file mode 100644 index 0000000..f1d22f0 --- /dev/null +++ b/domain/Game.java @@ -0,0 +1,15 @@ +package domain; + +import java.util.ArrayList; + +public class Game { + ArrayList currentPlayers; + + public Game(){ + currentPlayers = new ArrayList(); + } + + public void addPlayer(Player playerToAdd){ + currentPlayers.add(playerToAdd); + } +} diff --git a/domain/Player.java b/domain/Player.java new file mode 100644 index 0000000..e2bc9a8 --- /dev/null +++ b/domain/Player.java @@ -0,0 +1,15 @@ +package domain; + +public class Player { + int playerNumber; + String name; + String color; + int score; + + public Player(int playerNumber, String name, String color, int score) { + this.playerNumber = playerNumber; + this.name = name; + this.color = color; + this.score = score; + } +} diff --git a/fassade/KniffelSystem.java b/fassade/KniffelSystem.java new file mode 100644 index 0000000..b4926f2 --- /dev/null +++ b/fassade/KniffelSystem.java @@ -0,0 +1,50 @@ +package fassade; + +import domain.Game; +import domain.Player; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Random; + +public class KniffelSystem { + ArrayList playerColors; + Game game; + public KniffelSystem(){ + game = new Game(); + playerColors = new ArrayList<>(Arrays.asList( + "\u001B[31m", // Quelle 2 Anfang + "\u001B[32m", // + "\u001B[34m", // + "\u001B[33m", // + "\u001B[36m")); // Quelle 2 Ende + } + + public String scorebaordData(){ + return "Scoreboard - TODO"; + } + + public String addPlayer(int playerNumber, String name) { + String playerColor = colorPicker(playerNumber); + Player playerToAdd = new Player(playerNumber, name, playerColor, 0); + game.addPlayer(playerToAdd); + + return changePlayerNameColor(name, playerColor); + } + + private String changePlayerNameColor(String name, String color){ + String ANSI_RESET = "\u001B[0m"; + + return String.format(color + name + ANSI_RESET); + } + + private String colorPicker(int playerNumber){ + if (playerNumber == 1){ + return "\u001B[35m"; // Quelle 2 + } + + Random rand = new Random(); // Quelle 1 Anfang + int randomIndex = rand.nextInt(playerColors.size()); // + return playerColors.remove(randomIndex); // Quelle 1 Ende + } +} diff --git a/quellen.txt b/quellen.txt new file mode 100644 index 0000000..27c16c8 --- /dev/null +++ b/quellen.txt @@ -0,0 +1,7 @@ +1: +Von KI: ChatGPT 3.5 +Prompt: "pick a random element from an array list and remove it afterwards" + +2: +Von KI: ChatGPT 3.5 +Prompt: "could you give me 5 popular colors and pink in the ANSI format?" diff --git a/tui/TUI.java b/tui/TUI.java new file mode 100644 index 0000000..6f283a8 --- /dev/null +++ b/tui/TUI.java @@ -0,0 +1,90 @@ +package tui; + +import fassade.KniffelSystem; + +import java.util.Scanner; + +public class TUI { + static KniffelSystem gameSystem; + static Scanner sc = new Scanner(System.in); + + public static void main(String[] args) { + System.out.println("Welcome to the PR2 Kniffel game!"); + while (true){ + mainMenuOutput(); + } + } + + private static int mainMenuOutput(){ + System.out.println("What do you want to do?"); + System.out.println("1 - Play"); + System.out.println("2 - See scoreboard"); + System.out.println("3 - Exit"); + System.out.print("> "); + String mainMenuUserInput = sc.nextLine().toLowerCase(); + + + if ((mainMenuUserInput.equals("1")) + || (mainMenuUserInput.equals("play"))){ + mainMenuPlay(); + System.out.println("play"); // TEST + return 1; + } + else if ((mainMenuUserInput.equals("2")) + || (mainMenuUserInput.equals("see scoreboard")) + || (mainMenuUserInput.equals("see")) + || (mainMenuUserInput.equals("scoreboard"))){ + System.out.println("scoreboard"); // TEST + return 2; + } + else { + System.out.println("exit"); // TEST + mainMenuExit(); + return 3; + } + } + + private static void mainMenuPlay(){ + gameSystem = new KniffelSystem(); + + System.out.println("How many players are you? (1-6)"); + System.out.print("> "); + String mainMenuPlayAmountPlayersInput = sc.nextLine().toLowerCase(); + + int amountPlayers = Integer.parseInt(mainMenuPlayAmountPlayersInput); + for (int i = 0; i < amountPlayers; i++){ + System.out.printf("Player %d: ", i + 1); + System.out.println("Enter your name: "); + System.out.print("> "); + String playerName = sc.nextLine(); + + String coloredPlayerName = gameSystem.addPlayer(i+1, playerName); + System.out.printf("Welcome %s! \n\n", coloredPlayerName); + } + } + + private static void mainMenuScoreboard(){ + + } + + private static void mainMenuExit(){ + System.out.println("Do you really want to exit? (Y/n)"); + System.out.print("> "); + String mainMenuExitUserInput = sc.nextLine().toLowerCase(); + + if ((mainMenuExitUserInput.equals("y")) + || (mainMenuExitUserInput.equals("yes")) + || mainMenuExitUserInput.isBlank()){ + System.out.print("Exiting, see you next time!"); + System.exit(0); + } + else { + System.out.println("Returning to main menu"); + System.out.println(); + mainMenuOutput(); + } + + System.out.printf("|%s| \nIs blank? %b\n", mainMenuExitUserInput, mainMenuExitUserInput.isBlank()); // TEST + + } +}