瀏覽代碼

Merge branch 'yahtzee' of laurengreen/ZCW-OOP-Casino into yahtzee

jonathan-hinds 6 年之前
父節點
當前提交
571b5c1650

+ 25
- 4
src/main/java/io/zipcoder/casino/ScoreSheet.java 查看文件

@@ -6,10 +6,11 @@ import java.util.*;
6 6
 
7 7
 public class ScoreSheet {
8 8
 
9
-    private enum ROW{
9
+    public enum ROW{
10 10
         ACES, TWOS, THREES, FOURS, FIVES, SIXES, THREEOFAKIND, FOUROFAKIND, FULLHOUSE, SMALLSTRAIGHT, LARGESTRAIGHT, YAHTZEE, CHANCE;
11 11
     }
12 12
     private Map<ROW, Integer> scores = new EnumMap<>(ROW.class);
13
+    private static final int size = ROW.values().length;
13 14
 
14 15
     ScoreSheet(){
15 16
 
@@ -37,9 +38,21 @@ public class ScoreSheet {
37 38
         }
38 39
 
39 40
     public void printScoreCard(){
40
-        for(ROW r : ROW.values()) {
41
-            System.out.println(r + ": " + scores.get(r));
42
-        }
41
+        System.out.println(
42
+                "1. Aces: Totals all Ones ** Score **" + getScore(ScoreSheet.ROW.ACES) + "\n" +
43
+                "2. Twos: Totals all Twos ** Score **" + getScore(ScoreSheet.ROW.TWOS) + "\n" +
44
+                "3. Threes: Totals all Threes ** Score **" + getScore(ScoreSheet.ROW.THREES) + "\n" +
45
+                "4. Fours: Totals all Fours ** Score **" + getScore(ScoreSheet.ROW.FOURS) + "\n" +
46
+                "5. Fives: Totals all Fives ** Score **" + getScore(ScoreSheet.ROW.FIVES) + "\n" +
47
+                "6. Sixes: Totals all Sixes ** Score **" + getScore(ScoreSheet.ROW.SIXES) + "\n" +
48
+                "7. 3 of a Kind ** Score **" + getScore(ScoreSheet.ROW.THREEOFAKIND) + "\n" +
49
+                "8. 4 of a Kind ** Score **" + getScore(ScoreSheet.ROW.FOUROFAKIND) + "\n" +
50
+                "9. Full House ** Score **" + getScore(ScoreSheet.ROW.FULLHOUSE) + "\n" +
51
+                "10. Small Straight: Sequence of 4 ** Score **" + getScore(ScoreSheet.ROW.SMALLSTRAIGHT) + "\n" +
52
+                "11. Large Striaght: Sequence of 5 ** Score **" + getScore(ScoreSheet.ROW.LARGESTRAIGHT) + "\n" +
53
+                "12. Yahtzee: 5 of a Kind ** Score **" + getScore(ScoreSheet.ROW.YAHTZEE) + "\n" +
54
+                "13. Chance: Sum of Dice ** Score **" + getScore(ScoreSheet.ROW.CHANCE) + "\n" +
55
+                "****************** TOTAL SCORE ******************" + getTotalScore());
43 56
 
44 57
     }
45 58
 
@@ -204,4 +217,12 @@ public class ScoreSheet {
204 217
         }
205 218
         return score;
206 219
     }
220
+
221
+    public static int getSize() {
222
+        return size;
223
+    }
224
+
225
+    public Integer getScore(ROW row) {
226
+        return this.scores.get(row);
227
+    }
207 228
 }

+ 88
- 18
src/main/java/io/zipcoder/casino/Yahtzee.java 查看文件

@@ -1,9 +1,13 @@
1 1
 package io.zipcoder.casino;
2 2
 
3
+import java.util.ArrayList;
4
+import java.util.Scanner;
5
+
3 6
 public class Yahtzee extends DiceGame implements Game{
4 7
 
5 8
     private Dice[] cup;
6 9
     DicePlayer dicePlayer;
10
+    private Scanner scanner = new Scanner(System.in);
7 11
 
8 12
     public Yahtzee(Player player) {
9 13
         this.dicePlayer = new DicePlayer(player);
@@ -14,12 +18,21 @@ public class Yahtzee extends DiceGame implements Game{
14 18
         player1.getScoreSheet().getTotalScore();
15 19
     }
16 20
 
17
-    public void reRoll(){
18
-
19
-    }
20
-
21
-    public void stopRoll(){
21
+    public void reRoll(String diceToRoll){
22 22
 
23
+        String[] numbersString = diceToRoll.replace(",", "").split(" ");
24
+        ArrayList<Integer> numbers = new ArrayList<>();
25
+        for(String s: numbersString) {
26
+            numbers.add(Integer.parseInt(s));
27
+        }
28
+        for(Integer i : numbers) {
29
+            for(int j = 0; j < 5; j++) {
30
+                if(i == dicePlayer.getCup()[j].getValue()) {
31
+                    dicePlayer.getCup()[j].roll();
32
+                    break;
33
+                }
34
+            }
35
+        }
23 36
     }
24 37
 
25 38
     /**
@@ -44,26 +57,83 @@ public class Yahtzee extends DiceGame implements Game{
44 57
     }
45 58
 
46 59
     public void StartRound() {
47
-        for(Dice d : dicePlayer.getCup()) {
48
-            d.roll();
49
-        }
50
-        dicePlayer.printCup();
51 60
 
52
-        //roundRoutine();
61
+        for(int i = 0; i < ScoreSheet.getSize(); i++) {
62
+            for (Dice d : dicePlayer.getCup()) {
63
+                d.roll();
64
+            }
65
+            dicePlayer.printCup();
53 66
 
54
-    }
55
-
56
-    public void roundRoutine(){
67
+            roundRoutine();
68
+            recordingScore();
69
+        }
57 70
 
58
-        //ask if they want to score, or roll again?
71
+    }
59 72
 
60
-            //roll again if requested
73
+    public void recordingScore() {
74
+            System.out.println("Which row would you like to apply your turn to on the scoresheet?.\n" +
75
+                    "Remember you can only use each row once!");
76
+            dicePlayer.getScoreSheet().printScoreCard();
77
+
78
+            int choice = scanner.nextInt();
79
+            ScoreSheet.ROW row = ScoreSheet.ROW.CHANCE;
80
+            switch(choice) {
81
+                case 1: row = ScoreSheet.ROW.ACES;
82
+                    break;
83
+                case 2: row = ScoreSheet.ROW.TWOS;
84
+                    break;
85
+                case 3: row = ScoreSheet.ROW.THREES;
86
+                    break;
87
+                case 4: row = ScoreSheet.ROW.FOURS;
88
+                    break;
89
+                case 5: row = ScoreSheet.ROW.FIVES;
90
+                    break;
91
+                case 6: row = ScoreSheet.ROW.SIXES;
92
+                    break;
93
+                case 7: row = ScoreSheet.ROW.THREEOFAKIND;
94
+                    break;
95
+                case 8: row = ScoreSheet.ROW.FOUROFAKIND;
96
+                    break;
97
+                case 9: row = ScoreSheet.ROW.FULLHOUSE;
98
+                    break;
99
+                case 10: row = ScoreSheet.ROW.SMALLSTRAIGHT;
100
+                    break;
101
+                case 11: row = ScoreSheet.ROW.LARGESTRAIGHT;
102
+                    break;
103
+                case 12: row = ScoreSheet.ROW.YAHTZEE;
104
+                    break;
105
+                case 13: row = ScoreSheet.ROW.CHANCE;
106
+                    break;
107
+            }
108
+            dicePlayer.getScoreSheet().setRow(row, dicePlayer.getCup());
109
+        }
61 110
 
62
-                //continue to roll until no more rolls are left
63 111
 
64
-        //ask user how they would like to score
112
+    public void roundRoutine(){
65 113
 
66
-        //calculate the users score
114
+        for(int i = 0; i < 2; i++) {
115
+            System.out.println("Would you like to:\n1. Roll all dice again.\n2. Roll some dice again.\n3.Stop rolling and score.");
116
+            int choice = scanner.nextInt();
117
+
118
+            switch (choice) {
119
+                case 1:
120
+                    for (Dice d : dicePlayer.getCup()) {
121
+                        d.roll();
122
+                    }
123
+                    dicePlayer.printCup();
124
+                    break;
125
+
126
+                case 2:
127
+                    System.out.println("Which numbers would you like to reroll?");
128
+                    String diceToRoll = scanner.next();
129
+                    reRoll(diceToRoll);
130
+                    dicePlayer.printCup();
131
+                    break;
132
+
133
+                case 3:
134
+                    break;
135
+            }
136
+        }
67 137
 
68 138
     }
69 139
 }

+ 1
- 2
src/test/java/io/zipcoder/casino/ScoreSheetTest.java 查看文件

@@ -3,9 +3,8 @@ package io.zipcoder.casino;
3 3
 import org.junit.Assert;
4 4
 import org.junit.Test;
5 5
 
6
-import java.lang.reflect.Array;
6
+
7 7
 import java.util.ArrayList;
8
-import java.util.Arrays;
9 8
 import java.util.Collections;
10 9
 
11 10
 public class ScoreSheetTest {