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; package facade;
import java.io.FileNotFoundException;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
@ -10,6 +9,8 @@ import java.util.Scanner;
import domain.Player; import domain.Player;
public class YahtzeeGame { public class YahtzeeGame {
public int playerCount; public int playerCount;
@ -17,19 +18,33 @@ public class YahtzeeGame {
public String savedGamemode; public String savedGamemode;
public YahtzeeGame(int playerCount, String gamemode, String... names) { public YahtzeeGame() {
}
public void setPlayercount(int playerCount){
this.playerCount = playerCount; this.playerCount = playerCount;
this.savedGamemode = gamemode;
}
public void setPlayerNames(String... names){
for (int i = 0; i < this.playerCount; i++) { for (int i = 0; i < this.playerCount; i++) {
this.players.add(new Player(names[i], this.savedGamemode)); 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) { public void rollDices(int player) {
players.get(player).hand.rollDices(); 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) { public int returnTotalPoints(int player) {
if (players.get(player).box.gameOver()) 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++){ for(int i = 0; i<playerCount; i++){
setScoreToHighscores(i,refreshHighscoreList()); setScoreToHighscores(i,refreshHighscoreList());

View File

@ -1,26 +1,86 @@
package ui; package ui;
import java.io.IOException;
import java.util.Scanner; import java.util.Scanner;
import facade.YahtzeeGame;
public class TUI { public class TUI {
public static void main(String[] args) { public static void main(String[] args) throws IOException {
boolean choice = true; String choice ="";
Scanner df = new Scanner(System.in); Scanner sc = new Scanner(System.in);
boolean newGame = false;
System.out.println("Yahtzee Star Wars Special!"); System.out.println("Yahtzee Star Wars Special!");
while (choice) { while(newGame){
YahtzeeGame game = new YahtzeeGame(){};
System.out.println("Main menu:\n"); while (!choice.equals("stop")) {
System.out.println("Play");
System.out.println("Highscores"); 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));
}
}
}
}
} }
} }
} }