Nearly everything implemented
parent
0dc39592db
commit
df415b4042
|
@ -0,0 +1 @@
|
|||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
bin/ui/TUI.class
BIN
bin/ui/TUI.class
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
|
|
|
@ -42,8 +42,10 @@ public class Hand {
|
|||
|
||||
public int getLockedInDiceAmount() {
|
||||
|
||||
return lockedInDices.size();
|
||||
|
||||
if (lockedInDices != null)
|
||||
return lockedInDices.size();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void rollDices() {
|
||||
|
@ -89,7 +91,7 @@ public class Hand {
|
|||
public ArrayList<Integer> getLockedInDiceNumbers() {
|
||||
ArrayList<Integer> res = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < this.lockedInDices.size(); i++) {
|
||||
for (int i = 0; i < getLockedInDiceAmount(); i++) {
|
||||
|
||||
res.add(this.lockedInDices.get(i).getDiceNumber());
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package facade;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
@ -151,10 +153,10 @@ public class YahtzeeGame {
|
|||
return 0;
|
||||
}
|
||||
|
||||
private String[][] refreshHighscoreList() {
|
||||
private String[][] refreshHighscoreList() throws FileNotFoundException {
|
||||
|
||||
String highscores[][] = new String[10][3];
|
||||
Scanner sc = new Scanner("src/csv/highscores.csv");
|
||||
Scanner sc = new Scanner(new File("src/csv/highscores.csv"));
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
|
||||
|
@ -162,7 +164,12 @@ public class YahtzeeGame {
|
|||
highscores[i][0] = sc.next();
|
||||
highscores[i][1] = sc.next();
|
||||
highscores[i][2] = sc.nextLine();
|
||||
} else {
|
||||
highscores[i][0] = "___";
|
||||
highscores[i][1] = "___";
|
||||
highscores[i][2] = "0";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sc.close();
|
||||
|
@ -402,7 +409,7 @@ public class YahtzeeGame {
|
|||
|
||||
}
|
||||
|
||||
public String showHighscores() {
|
||||
public String showHighscores() throws FileNotFoundException {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
|
|
149
src/ui/TUI.java
149
src/ui/TUI.java
|
@ -1,9 +1,7 @@
|
|||
package ui;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
import facade.YahtzeeGame;
|
||||
|
||||
public class TUI {
|
||||
|
@ -12,107 +10,106 @@ public class TUI {
|
|||
|
||||
String choice = "";
|
||||
Scanner sc = new Scanner(System.in);
|
||||
boolean newGame = false;
|
||||
|
||||
System.out.println("Yahtzee Star Wars Special!");
|
||||
|
||||
while (newGame) {
|
||||
while (!choice.equals("stop")) {
|
||||
|
||||
YahtzeeGame game = new YahtzeeGame() {
|
||||
};
|
||||
System.out.println("Main menu:\n");
|
||||
System.out.println(">Play");
|
||||
System.out.println(">Highscores");
|
||||
choice = sc.nextLine();
|
||||
|
||||
while (!choice.equals("stop")) {
|
||||
|
||||
System.out.println("Main menu:\n");
|
||||
System.out.println(">Play");
|
||||
System.out.println(">Highscores");
|
||||
if (choice.equals("Highscores")) {
|
||||
System.out.println(game.showHighscores());
|
||||
System.out.println(">Return");
|
||||
System.out.println(">Delete");
|
||||
choice = sc.nextLine();
|
||||
if (choice.equals("Return")) {
|
||||
}
|
||||
|
||||
if (choice.equals("Highscores")) {
|
||||
System.out.println(game.showHighscores());
|
||||
System.out.println(">Return");
|
||||
System.out.println(">Delete");
|
||||
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("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...");
|
||||
}
|
||||
|
||||
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]");
|
||||
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()) {
|
||||
|
||||
String playerNames[] = new String[game.playerCount];
|
||||
for (int i = 0; i < game.playerCount; i++) {
|
||||
playerNames[i] = sc.nextLine();
|
||||
}
|
||||
|
||||
game.setPlayerNames(playerNames);
|
||||
if (game.gameOver(i))
|
||||
continue;
|
||||
|
||||
while (!game.gameOverAll()) {
|
||||
System.out.println("Its your turn " + game.getPlayerName(i));
|
||||
System.out.println("This is your Yahtzee Box: ");
|
||||
System.out.println(game.selectedOptionsPrinted(i) + "\n");
|
||||
|
||||
for (int i = 0; i < game.playerCount; i++) {
|
||||
while (!game.allDicesLockedIn(i) || !game.noMoreRolls(i)) {
|
||||
|
||||
if (game.gameOver(i))
|
||||
continue;
|
||||
System.out.println("Your dices: ");
|
||||
System.out.println("Free dices: " + game.getFreeDiceNumbers(i));
|
||||
System.out.println("Locked in dices: " + game.getLockedInDiceNumbers(i));
|
||||
System.out.println(
|
||||
"Type in which free dices you want to keep \n(seperated by space, type 'none' if you dont want to keep any): ");
|
||||
choice = sc.nextLine();
|
||||
game.lockInDices(i, choice.split(" "));
|
||||
game.rollDices(i);
|
||||
System.out.println(game.getLeftRolls(i) + " rolls left");
|
||||
System.out.println("Rerolling dices... ");
|
||||
|
||||
System.out.println("Its your turn " + game.getPlayerName(i));
|
||||
System.out.println("This is your Yahtzee Box: ");
|
||||
System.out.println(game.selectedOptionsPrinted(i) + "\n");
|
||||
}
|
||||
|
||||
while (!game.allDicesLockedIn(i) || !game.noMoreRolls(i)) {
|
||||
System.out.println("Done locking in... Here are your options: ");
|
||||
System.out.println(game.optionsPrinted(i));
|
||||
System.out.println("Which option you want to select?: ");
|
||||
game.selectOption(i, sc.nextLine());
|
||||
|
||||
System.out.println("Your dices: ");
|
||||
System.out.println("Free dices: " + game.getFreeDiceNumbers(i));
|
||||
System.out.println("Locked in dices: " + game.getLockedInDiceNumbers(i));
|
||||
System.out.println(
|
||||
"Type in which free dices you want to keep \n(seperated by space, type 'none' if you dont want to keep any): ");
|
||||
choice = sc.nextLine();
|
||||
game.lockInDices(i, choice.split(" "));
|
||||
game.rollDices(i);
|
||||
System.out.println(game.getLeftRolls(i) + " rolls left");
|
||||
System.out.println("Rerolling dices... ");
|
||||
|
||||
}
|
||||
|
||||
System.out.println("Done locking in... Here are your options: ");
|
||||
System.out.println(game.optionsPrinted(i));
|
||||
System.out.println("Which option you want to select?: ");
|
||||
game.selectOption(i, sc.nextLine());
|
||||
|
||||
if (game.gameOver(i)) {
|
||||
System.out.println(
|
||||
"Your game is over, here is your total score: " + game.returnTotalPoints(i));
|
||||
}
|
||||
if (game.gameOver(i)) {
|
||||
System.out.println(
|
||||
"Your game is over, here is your total score: " + game.returnTotalPoints(i));
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("The game is over, saving all highscores to the highscore table...");
|
||||
game.saveAllPlayersHighscores();
|
||||
|
||||
}
|
||||
|
||||
System.out.println("The game is over, " + game.getWinnerMessage());
|
||||
System.out.println("Saving all highscores to the highscore table...");
|
||||
game.saveAllPlayersHighscores();
|
||||
System.out.println(
|
||||
"If you want to stop the programm type: 'stop', otherwise you will return to the main menu:");
|
||||
choice = sc.nextLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue