school/java/old/Project/GameManager.java

67 lines
1.5 KiB
Java
Raw Normal View History

2021-02-18 11:26:36 -05:00
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();
2021-02-18 20:42:54 -05:00
return "GameManager{" +
"\nDie 1 = " + dice.get(0).getValue() +
2021-02-18 11:26:36 -05:00
"\nDie 2 = " + dice.get(1).getValue() +
2021-02-18 20:42:54 -05:00
"\nDie 3 = " + dice.get(2).getValue() + "}";
2021-02-18 11:26:36 -05:00
}
public DiceCup getDice(){
return diceCup;
}
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
int diceSides;
2021-02-18 20:42:54 -05:00
System.out.println("Do you want to play with 6 or 8 dice?");
2021-02-18 11:26:36 -05:00
diceSides = scnr.nextInt();
2021-02-18 20:42:54 -05:00
scnr.nextLine();
2021-02-18 11:26:36 -05:00
GameManager game = new GameManager(diceSides);
String userInput;
while (true){
2021-02-18 20:42:54 -05:00
System.out.println("Type Roll to play, Stop to end");
userInput = scnr.nextLine();
2021-02-18 11:26:36 -05:00
2021-02-18 20:42:54 -05:00
if (userInput.toLowerCase().equals("stop")){break;}
if (game.diceCup.enoughCredits()){
2021-02-18 11:26:36 -05:00
2021-02-18 20:42:54 -05:00
if (userInput.toLowerCase().equals("roll")){
System.out.println("\nCredits before bet: " +
game.diceCup.getCredits());
// Roll Dice
game.getDice().roll();
game.getDice().updateCredits();
2021-02-18 11:36:56 -05:00
2021-02-18 20:42:54 -05:00
System.out.println(game.toString());
2021-02-18 11:26:36 -05:00
2021-02-18 20:42:54 -05:00
System.out.println("Total sum of Dice: " +
game.diceCup.getTotal());
System.out.println("Credits after bet: " +
game.diceCup.getCredits() + "\n");
2021-02-18 11:26:36 -05:00
2021-02-18 20:42:54 -05:00
}
}
else{
System.out.println("You do not have enough credits! \n");
}
2021-02-18 11:26:36 -05:00
}
scnr.close();
}
}