Przeglądaj źródła

Caught a mistake in reRoll, all set now

Lauren Green 6 lat temu
rodzic
commit
da2e13d230

+ 6
- 0
src/main/java/io/zipcoder/casino/DicePlayer.java Wyświetl plik

29
     public Player getPlayer() {
29
     public Player getPlayer() {
30
         return player;
30
         return player;
31
     }
31
     }
32
+
33
+    public void printBalanceAtEnd() {
34
+        System.out.println("Your total balance is now: $" + getPlayer().getCurrentBalance());
35
+    }
32
 }
36
 }
37
+
38
+

+ 1
- 0
src/main/java/io/zipcoder/casino/Player.java Wyświetl plik

8
     Player(String name, int initialBalance){
8
     Player(String name, int initialBalance){
9
         this.name = name;
9
         this.name = name;
10
         this.initialBalance = initialBalance;
10
         this.initialBalance = initialBalance;
11
+        this.currentBalance = initialBalance;
11
     }
12
     }
12
 
13
 
13
     public int getInitialBalance() {
14
     public int getInitialBalance() {

+ 39
- 39
src/main/java/io/zipcoder/casino/ScoreSheet.java Wyświetl plik

32
 
32
 
33
 
33
 
34
     public void printScoreCard(){
34
     public void printScoreCard(){
35
-        System.out.print("1. Aces: Totals all Ones ** Score ** ");
35
+        System.out.print(String.format("%-35s","1. Aces: Totals all Ones"));
36
         if(getScore(ScoreSheet.ROW.ACES) != null) {
36
         if(getScore(ScoreSheet.ROW.ACES) != null) {
37
-            System.out.println(getScore(ScoreSheet.ROW.ACES));
37
+            System.out.println("** " + getScore(ScoreSheet.ROW.ACES) + " **");
38
         } else {
38
         } else {
39
-            System.out.println("open");
39
+            System.out.println("** open **");
40
         }
40
         }
41
-        System.out.print("2. Twos: Totals all Twos ** Score ** ");
41
+        System.out.print(String.format("%-35s","2. Twos: Totals all Twos"));
42
         if(getScore(ScoreSheet.ROW.TWOS) != null) {
42
         if(getScore(ScoreSheet.ROW.TWOS) != null) {
43
-            System.out.println(getScore(ScoreSheet.ROW.TWOS));
43
+            System.out.println("** " + getScore(ScoreSheet.ROW.TWOS) + " **");
44
         } else {
44
         } else {
45
-            System.out.println("open");
45
+            System.out.println("** open **");
46
         }
46
         }
47
-        System.out.print( "3. Threes: Totals all Threes ** Score ** ");
47
+        System.out.print(String.format("%-35s", "3. Threes: Totals all Threes"));
48
         if(getScore(ScoreSheet.ROW.THREES) != null) {
48
         if(getScore(ScoreSheet.ROW.THREES) != null) {
49
-            System.out.println(getScore(ScoreSheet.ROW.THREES));
49
+            System.out.println("** " + getScore(ScoreSheet.ROW.THREES) + " **");
50
         } else {
50
         } else {
51
-            System.out.println("open");
51
+            System.out.println("** open **");
52
         }
52
         }
53
-        System.out.print( "4. Fours: Totals all Fours ** Score ** ");
53
+        System.out.print(String.format("%-35s", "4. Fours: Totals all Fours"));
54
         if(getScore(ScoreSheet.ROW.FOURS) != null) {
54
         if(getScore(ScoreSheet.ROW.FOURS) != null) {
55
-            System.out.println(getScore(ScoreSheet.ROW.FOURS));
55
+            System.out.println("** " + getScore(ScoreSheet.ROW.FOURS) + " **");
56
         } else {
56
         } else {
57
-            System.out.println("open");
57
+            System.out.println("** open **");
58
         }
58
         }
59
-        System.out.print( "5. Fives: Totals all Fives ** Score ** ");
59
+        System.out.print(String.format("%-35s", "5. Fives: Totals all Fives"));
60
         if(getScore(ScoreSheet.ROW.FIVES) != null) {
60
         if(getScore(ScoreSheet.ROW.FIVES) != null) {
61
-            System.out.println(getScore(ScoreSheet.ROW.FIVES));
61
+            System.out.println("** " + getScore(ScoreSheet.ROW.FIVES) + " **");
62
         } else {
62
         } else {
63
-            System.out.println("open");
63
+            System.out.println("** open **");
64
         }
64
         }
65
-        System.out.print( "6. Sixes: Totals all Sixes ** Score ** ");
65
+        System.out.print(String.format("%-35s", "6. Sixes: Totals all Sixes"));
66
         if(getScore(ScoreSheet.ROW.SIXES) != null) {
66
         if(getScore(ScoreSheet.ROW.SIXES) != null) {
67
-            System.out.println(getScore(ScoreSheet.ROW.SIXES));
67
+            System.out.println("** " + getScore(ScoreSheet.ROW.SIXES) + " **");
68
         } else {
68
         } else {
69
-            System.out.println("open");
69
+            System.out.println("** open **");
70
         }
70
         }
71
-        System.out.print( "7. 3 of a Kind ** Score ** ");
71
+        System.out.print(String.format("%-35s", "7. 3 of a Kind"));
72
         if(getScore(ScoreSheet.ROW.THREEOFAKIND) != null) {
72
         if(getScore(ScoreSheet.ROW.THREEOFAKIND) != null) {
73
-            System.out.println(getScore(ScoreSheet.ROW.THREEOFAKIND));
73
+            System.out.println("** " + getScore(ScoreSheet.ROW.THREEOFAKIND) + " **");
74
         } else {
74
         } else {
75
-            System.out.println("open");
75
+            System.out.println("** open **");
76
         }
76
         }
77
-        System.out.print( "8. 4 of a Kind ** Score ** ");
77
+        System.out.print(String.format("%-35s", "8. 4 of a Kind"));
78
         if(getScore(ScoreSheet.ROW.FOUROFAKIND) != null) {
78
         if(getScore(ScoreSheet.ROW.FOUROFAKIND) != null) {
79
-            System.out.println(getScore(ScoreSheet.ROW.FOUROFAKIND));
79
+            System.out.println("** " + getScore(ScoreSheet.ROW.FOUROFAKIND) + " **");
80
         } else {
80
         } else {
81
-            System.out.println("open");
81
+            System.out.println("** open **");
82
         }
82
         }
83
-        System.out.print( "9. Full House ** Score ** ");
83
+        System.out.print(String.format("%-35s", "9. Full House"));
84
         if(getScore(ScoreSheet.ROW.FULLHOUSE) != null) {
84
         if(getScore(ScoreSheet.ROW.FULLHOUSE) != null) {
85
-            System.out.println(getScore(ScoreSheet.ROW.FULLHOUSE));
85
+            System.out.println("** " + getScore(ScoreSheet.ROW.FULLHOUSE) + " **");
86
         } else {
86
         } else {
87
-            System.out.println("open");
87
+            System.out.println("** open **");
88
         }
88
         }
89
-        System.out.print("10. Small Straight: Sequence of 4 ** Score ** ");
89
+        System.out.print(String.format("%-35s","10. Small Straight: Sequence of 4"));
90
         if(getScore(ScoreSheet.ROW.SMALLSTRAIGHT) != null) {
90
         if(getScore(ScoreSheet.ROW.SMALLSTRAIGHT) != null) {
91
-            System.out.println(getScore(ScoreSheet.ROW.SMALLSTRAIGHT));
91
+            System.out.println("** " + getScore(ScoreSheet.ROW.SMALLSTRAIGHT) + " **");
92
         } else {
92
         } else {
93
-            System.out.println("open");
93
+            System.out.println("** open **");
94
         }
94
         }
95
-        System.out.print("11. Large Striaght: Sequence of 5 ** Score ** ");
95
+        System.out.print(String.format("%-35s","11. Large Striaght: Sequence of 5"));
96
         if(getScore(ScoreSheet.ROW.LARGESTRAIGHT) != null) {
96
         if(getScore(ScoreSheet.ROW.LARGESTRAIGHT) != null) {
97
-            System.out.println(getScore(ScoreSheet.ROW.LARGESTRAIGHT));
97
+            System.out.println("** " + getScore(ScoreSheet.ROW.LARGESTRAIGHT) + " **");
98
         } else {
98
         } else {
99
-            System.out.println("open");
99
+            System.out.println("** open **");
100
         }
100
         }
101
-        System.out.print("12. Yahtzee: 5 of a Kind ** Score ** ");
101
+        System.out.print(String.format("%-35s","12. Yahtzee: 5 of a Kind "));
102
         if(getScore(ScoreSheet.ROW.YAHTZEE) != null) {
102
         if(getScore(ScoreSheet.ROW.YAHTZEE) != null) {
103
-            System.out.println(getScore(ScoreSheet.ROW.YAHTZEE));
103
+            System.out.println("** " + getScore(ScoreSheet.ROW.YAHTZEE) + " **");
104
         } else {
104
         } else {
105
-            System.out.println("open");
105
+            System.out.println("** open **");
106
         }
106
         }
107
-        System.out.print( "13. Chance: Sum of Dice ** Score ** ");
107
+        System.out.print(String.format("%-35s", "13. Chance: Sum of Dice"));
108
         if(getScore(ScoreSheet.ROW.CHANCE) != null) {
108
         if(getScore(ScoreSheet.ROW.CHANCE) != null) {
109
-            System.out.println(getScore(ScoreSheet.ROW.CHANCE));
109
+            System.out.println("** " + getScore(ScoreSheet.ROW.CHANCE) + " **");
110
         } else {
110
         } else {
111
-            System.out.println("open");
111
+            System.out.println("** open **");
112
         }
112
         }
113
         System.out.println();
113
         System.out.println();
114
     }
114
     }

+ 10
- 6
src/main/java/io/zipcoder/casino/Yahtzee.java Wyświetl plik

1
 package io.zipcoder.casino;
1
 package io.zipcoder.casino;
2
 
2
 
3
+import java.lang.reflect.Array;
3
 import java.util.ArrayList;
4
 import java.util.ArrayList;
5
+import java.util.Arrays;
4
 import java.util.Scanner;
6
 import java.util.Scanner;
5
 
7
 
6
 public class Yahtzee extends DiceGame implements Game, Gamble{
8
 public class Yahtzee extends DiceGame implements Game, Gamble{
43
         startRound();
45
         startRound();
44
         System.out.println("You scored " + dicePlayer.getScoreSheet().getTotalScore() + " points.");
46
         System.out.println("You scored " + dicePlayer.getScoreSheet().getTotalScore() + " points.");
45
         payout();
47
         payout();
48
+        dicePlayer.printBalanceAtEnd();
46
         //Return to console.
49
         //Return to console.
47
     }
50
     }
48
 
51
 
71
 
74
 
72
     public void giveOptions() {
75
     public void giveOptions() {
73
         int choice = 0;
76
         int choice = 0;
74
-        System.out.println("Would you like to:\n1. Roll all dice again.\n2. Roll some dice again.\n3. Stop rolling and score.");
77
+        System.out.print("Would you like to:\n1. Roll all dice again.\n2. Roll some dice again.\n3. Stop rolling and score.\nNumber of Selection: ");
75
 
78
 
76
         Scanner in = new Scanner(System.in);
79
         Scanner in = new Scanner(System.in);
77
         choice = in.nextInt();
80
         choice = in.nextInt();
89
             case 2:
92
             case 2:
90
                 System.out.println("Which numbers would you like to reroll? List the numbers separated by spaces.");
93
                 System.out.println("Which numbers would you like to reroll? List the numbers separated by spaces.");
91
                 Scanner in2 = new Scanner(System.in);
94
                 Scanner in2 = new Scanner(System.in);
92
-                String diceToRoll = in2.next();
95
+                String diceToRoll = in2.nextLine();
93
                 reRoll(diceToRoll);
96
                 reRoll(diceToRoll);
94
                 System.out.println("\nYou rolled:");
97
                 System.out.println("\nYou rolled:");
95
                 dicePlayer.printCup();
98
                 dicePlayer.printCup();
103
 
106
 
104
     public void reRoll(String diceToRoll){
107
     public void reRoll(String diceToRoll){
105
 
108
 
106
-        String[] numbersString = diceToRoll.replace(",", "").split(" ");
109
+        String[] numbersString = diceToRoll.split(" ");
107
         ArrayList<Integer> numbers = new ArrayList<>();
110
         ArrayList<Integer> numbers = new ArrayList<>();
108
         for(String s: numbersString) {
111
         for(String s: numbersString) {
109
             numbers.add(Integer.parseInt(s));
112
             numbers.add(Integer.parseInt(s));
110
         }
113
         }
114
+
111
         for(Integer i : numbers) {
115
         for(Integer i : numbers) {
112
             for(int j = 0; j < 5; j++) {
116
             for(int j = 0; j < 5; j++) {
113
                 if(i == dicePlayer.getCup()[j].getValue()) {
117
                 if(i == dicePlayer.getCup()[j].getValue()) {
125
         ScoreSheet.ROW row = ScoreSheet.ROW.CHANCE;
129
         ScoreSheet.ROW row = ScoreSheet.ROW.CHANCE;
126
 
130
 
127
         while(validEntry) {
131
         while(validEntry) {
128
-            System.out.println("Which row would you like to apply your turn to on the scoresheet?.\n" +
129
-                    "Remember you can only use each row once!");
130
-            System.out.println();
131
             dicePlayer.getScoreSheet().printScoreCard();
132
             dicePlayer.getScoreSheet().printScoreCard();
132
             System.out.println();
133
             System.out.println();
134
+            System.out.println("Which row would you like to apply your turn to on the scoresheet?.\n" +
135
+                    "Remember you can only use each row once!");
136
+            System.out.print("Row:");
133
 
137
 
134
             Scanner scanner2 = new Scanner(System.in);
138
             Scanner scanner2 = new Scanner(System.in);
135
             choice = scanner2.nextInt();
139
             choice = scanner2.nextInt();