s.eser 2024-04-28 20:52:08 +02:00
parent 5379345afa
commit b207c6ab88
5 changed files with 102 additions and 15 deletions

Binary file not shown.

Binary file not shown.

View File

@ -22,4 +22,5 @@ public class Player {
}
}

View File

@ -1,6 +1,5 @@
package facade;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
@ -10,6 +9,8 @@ import java.util.Scanner;
import domain.Player;
public class YahtzeeGame {
public int playerCount;
@ -17,19 +18,33 @@ public class YahtzeeGame {
public String savedGamemode;
public YahtzeeGame(int playerCount, String gamemode, String... names) {
public YahtzeeGame() {
}
public void setPlayercount(int playerCount){
this.playerCount = playerCount;
this.savedGamemode = gamemode;
}
public void setPlayerNames(String... names){
for (int i = 0; i < this.playerCount; i++) {
this.players.add(new Player(names[i], this.savedGamemode));
}
}
public String getPlayerName(int player){
return players.get(player).name;
}
public void setGamemode(String gamemode){
this.savedGamemode = gamemode;
}
public void rollDices(int player) {
players.get(player).hand.rollDices();
@ -87,6 +102,17 @@ public class YahtzeeGame {
}
public boolean gameOverAll(){
int counter = 0;
for(int i = 0; i<playerCount; i++){
if(players.get(i).box.gameOver())
counter++;
}
return counter == playerCount;
}
public int returnTotalPoints(int player) {
if (players.get(player).box.gameOver())
@ -339,7 +365,7 @@ public class YahtzeeGame {
}
public void saveAllPlayersHighscores() throws FileNotFoundException{
public void saveAllPlayersHighscores() throws IOException{
for(int i = 0; i<playerCount; i++){
setScoreToHighscores(i,refreshHighscoreList());

View File

@ -1,26 +1,86 @@
package ui;
import java.io.IOException;
import java.util.Scanner;
import facade.YahtzeeGame;
public class TUI {
public static void main(String[] args) {
public static void main(String[] args) throws IOException {
boolean choice = true;
Scanner df = new Scanner(System.in);
String choice ="";
Scanner sc = new Scanner(System.in);
boolean newGame = false;
System.out.println("Yahtzee Star Wars Special!");
while (choice) {
while(newGame){
YahtzeeGame game = new YahtzeeGame(){};
System.out.println("Main menu:\n");
System.out.println("Play");
System.out.println("Highscores");
while (!choice.equals("stop")) {
System.out.println("Main menu:\n");
System.out.println(">Play");
System.out.println(">Highscores");
choice = sc.nextLine();
if(High)
if(choice.equals("Highscores")){
System.out.println(game.showHighscores());
System.out.println(">Return");
System.out.println(">Delete");
choice = sc.nextLine();
if(choice.equals("Return"))
break;
else if(choice.equals("Delete")){
System.out.println("Are you sure you want to delete the Highscore file?\nAs a confirmation type: 'I AM SURE': ");
choice = sc.nextLine();
if(choice.equals("I AM SURE")){
game.deleteHighscores();
System.out.println("Highscore file got deleted...\nReturning to the main menu...");
}
else{
System.out.println("Highscore file not deleted...\nReturning to the main menu...");
}
}
}
else if(choice.equals("Play")){
System.out.println("Choose your gamemode: ");
System.out.println(">Normal");
System.out.println(">StarWarsDay");
System.out.println(">Special8");
game.setGamemode(sc.nextLine());
System.out.println("Amount of players: ");
System.out.println(">1-6");
game.setPlayercount(sc.nextInt());
System.out.println("Type in the player names, lock in each name with Enter: ");
System.out.println(">ex. Lucas [Enter] William [Enter] Lena [Enter]");
String playerNames[] = new String[game.playerCount];
for(int i = 0; i < game.playerCount; i++){
playerNames[i] = sc.nextLine();
}
game.setPlayerNames(playerNames);
while (!game.gameOverAll()) {
for(int i = 0; i<game.playerCount; i++){
System.out.println("Its your turn "+game.getPlayerName(i));
}
}
}
}
}
}
}