school/java/old/Project/GameManager.java
2021-03-10 15:30:40 -05:00

67 lines
1.5 KiB
Java

import java.util.ArrayList;
import java.util.Scanner;
public class GameManager{
private DiceCup diceCup;
public GameManager (int num){
diceCup = new DiceCup(num);
}
public String toString(){
ArrayList<MyDie> dice = diceCup.getDice();
return "GameManager{" +
"\nDie 1 = " + dice.get(0).getValue() +
"\nDie 2 = " + dice.get(1).getValue() +
"\nDie 3 = " + dice.get(2).getValue() + "}";
}
public DiceCup getDice(){
return diceCup;
}
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
int diceSides;
System.out.println("Do you want to play with 6 or 8 dice?");
diceSides = scnr.nextInt();
scnr.nextLine();
GameManager game = new GameManager(diceSides);
String userInput;
while (true){
System.out.println("Type Roll to play, Stop to end");
userInput = scnr.nextLine();
if (userInput.toLowerCase().equals("stop")){break;}
if (game.diceCup.enoughCredits()){
if (userInput.toLowerCase().equals("roll")){
System.out.println("\nCredits before bet: " +
game.diceCup.getCredits());
// Roll Dice
game.getDice().roll();
game.getDice().updateCredits();
System.out.println(game.toString());
System.out.println("Total sum of Dice: " +
game.diceCup.getTotal());
System.out.println("Credits after bet: " +
game.diceCup.getCredits() + "\n");
}
}
else{
System.out.println("You do not have enough credits! \n");
}
}
scnr.close();
}
}