Kaynağa Gözat

Caught a mistake in reRoll, all set now

Lauren Green 6 yıl önce
ebeveyn
işleme
da2e13d230

+ 6
- 0
src/main/java/io/zipcoder/casino/DicePlayer.java Dosyayı Görüntüle

@@ -29,4 +29,10 @@ public class DicePlayer {
29 29
     public Player getPlayer() {
30 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 Dosyayı Görüntüle

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

+ 39
- 39
src/main/java/io/zipcoder/casino/ScoreSheet.java Dosyayı Görüntüle

@@ -32,83 +32,83 @@ public class ScoreSheet {
32 32
 
33 33
 
34 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 36
         if(getScore(ScoreSheet.ROW.ACES) != null) {
37
-            System.out.println(getScore(ScoreSheet.ROW.ACES));
37
+            System.out.println("** " + getScore(ScoreSheet.ROW.ACES) + " **");
38 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 42
         if(getScore(ScoreSheet.ROW.TWOS) != null) {
43
-            System.out.println(getScore(ScoreSheet.ROW.TWOS));
43
+            System.out.println("** " + getScore(ScoreSheet.ROW.TWOS) + " **");
44 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 48
         if(getScore(ScoreSheet.ROW.THREES) != null) {
49
-            System.out.println(getScore(ScoreSheet.ROW.THREES));
49
+            System.out.println("** " + getScore(ScoreSheet.ROW.THREES) + " **");
50 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 54
         if(getScore(ScoreSheet.ROW.FOURS) != null) {
55
-            System.out.println(getScore(ScoreSheet.ROW.FOURS));
55
+            System.out.println("** " + getScore(ScoreSheet.ROW.FOURS) + " **");
56 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 60
         if(getScore(ScoreSheet.ROW.FIVES) != null) {
61
-            System.out.println(getScore(ScoreSheet.ROW.FIVES));
61
+            System.out.println("** " + getScore(ScoreSheet.ROW.FIVES) + " **");
62 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 66
         if(getScore(ScoreSheet.ROW.SIXES) != null) {
67
-            System.out.println(getScore(ScoreSheet.ROW.SIXES));
67
+            System.out.println("** " + getScore(ScoreSheet.ROW.SIXES) + " **");
68 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 72
         if(getScore(ScoreSheet.ROW.THREEOFAKIND) != null) {
73
-            System.out.println(getScore(ScoreSheet.ROW.THREEOFAKIND));
73
+            System.out.println("** " + getScore(ScoreSheet.ROW.THREEOFAKIND) + " **");
74 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 78
         if(getScore(ScoreSheet.ROW.FOUROFAKIND) != null) {
79
-            System.out.println(getScore(ScoreSheet.ROW.FOUROFAKIND));
79
+            System.out.println("** " + getScore(ScoreSheet.ROW.FOUROFAKIND) + " **");
80 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 84
         if(getScore(ScoreSheet.ROW.FULLHOUSE) != null) {
85
-            System.out.println(getScore(ScoreSheet.ROW.FULLHOUSE));
85
+            System.out.println("** " + getScore(ScoreSheet.ROW.FULLHOUSE) + " **");
86 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 90
         if(getScore(ScoreSheet.ROW.SMALLSTRAIGHT) != null) {
91
-            System.out.println(getScore(ScoreSheet.ROW.SMALLSTRAIGHT));
91
+            System.out.println("** " + getScore(ScoreSheet.ROW.SMALLSTRAIGHT) + " **");
92 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 96
         if(getScore(ScoreSheet.ROW.LARGESTRAIGHT) != null) {
97
-            System.out.println(getScore(ScoreSheet.ROW.LARGESTRAIGHT));
97
+            System.out.println("** " + getScore(ScoreSheet.ROW.LARGESTRAIGHT) + " **");
98 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 102
         if(getScore(ScoreSheet.ROW.YAHTZEE) != null) {
103
-            System.out.println(getScore(ScoreSheet.ROW.YAHTZEE));
103
+            System.out.println("** " + getScore(ScoreSheet.ROW.YAHTZEE) + " **");
104 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 108
         if(getScore(ScoreSheet.ROW.CHANCE) != null) {
109
-            System.out.println(getScore(ScoreSheet.ROW.CHANCE));
109
+            System.out.println("** " + getScore(ScoreSheet.ROW.CHANCE) + " **");
110 110
         } else {
111
-            System.out.println("open");
111
+            System.out.println("** open **");
112 112
         }
113 113
         System.out.println();
114 114
     }

+ 10
- 6
src/main/java/io/zipcoder/casino/Yahtzee.java Dosyayı Görüntüle

@@ -1,6 +1,8 @@
1 1
 package io.zipcoder.casino;
2 2
 
3
+import java.lang.reflect.Array;
3 4
 import java.util.ArrayList;
5
+import java.util.Arrays;
4 6
 import java.util.Scanner;
5 7
 
6 8
 public class Yahtzee extends DiceGame implements Game, Gamble{
@@ -43,6 +45,7 @@ public class Yahtzee extends DiceGame implements Game, Gamble{
43 45
         startRound();
44 46
         System.out.println("You scored " + dicePlayer.getScoreSheet().getTotalScore() + " points.");
45 47
         payout();
48
+        dicePlayer.printBalanceAtEnd();
46 49
         //Return to console.
47 50
     }
48 51
 
@@ -71,7 +74,7 @@ public class Yahtzee extends DiceGame implements Game, Gamble{
71 74
 
72 75
     public void giveOptions() {
73 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 79
         Scanner in = new Scanner(System.in);
77 80
         choice = in.nextInt();
@@ -89,7 +92,7 @@ public class Yahtzee extends DiceGame implements Game, Gamble{
89 92
             case 2:
90 93
                 System.out.println("Which numbers would you like to reroll? List the numbers separated by spaces.");
91 94
                 Scanner in2 = new Scanner(System.in);
92
-                String diceToRoll = in2.next();
95
+                String diceToRoll = in2.nextLine();
93 96
                 reRoll(diceToRoll);
94 97
                 System.out.println("\nYou rolled:");
95 98
                 dicePlayer.printCup();
@@ -103,11 +106,12 @@ public class Yahtzee extends DiceGame implements Game, Gamble{
103 106
 
104 107
     public void reRoll(String diceToRoll){
105 108
 
106
-        String[] numbersString = diceToRoll.replace(",", "").split(" ");
109
+        String[] numbersString = diceToRoll.split(" ");
107 110
         ArrayList<Integer> numbers = new ArrayList<>();
108 111
         for(String s: numbersString) {
109 112
             numbers.add(Integer.parseInt(s));
110 113
         }
114
+
111 115
         for(Integer i : numbers) {
112 116
             for(int j = 0; j < 5; j++) {
113 117
                 if(i == dicePlayer.getCup()[j].getValue()) {
@@ -125,11 +129,11 @@ public class Yahtzee extends DiceGame implements Game, Gamble{
125 129
         ScoreSheet.ROW row = ScoreSheet.ROW.CHANCE;
126 130
 
127 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 132
             dicePlayer.getScoreSheet().printScoreCard();
132 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 138
             Scanner scanner2 = new Scanner(System.in);
135 139
             choice = scanner2.nextInt();