Procházet zdrojové kódy

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

jonathan-hinds před 6 roky
rodič
revize
15b68cedaa
1 změnil soubory, kde provedl 74 přidání a 70 odebrání
  1. 74
    70
      src/main/java/io/zipcoder/casino/ScoreSheet.java

+ 74
- 70
src/main/java/io/zipcoder/casino/ScoreSheet.java Zobrazit soubor

@@ -45,76 +45,80 @@ public class ScoreSheet {
45 45
 
46 46
     public void setRow(ROW row, Dice[] cup){
47 47
 
48
-        ArrayList<Integer> numbers = new ArrayList<>();
49
-        for(Dice d : cup) {
50
-            numbers.add(d.getValue());
51
-        }
52
-        Collections.sort(numbers);
53
-
54
-        switch(row) {
55
-            case ACES:
56
-                scores.put(ROW.ACES, scoreNumbers(numbers, 1));
57
-                break;
58
-            case TWOS:
59
-                scores.put(ROW.TWOS, scoreNumbers(numbers, 2));
60
-                break;
61
-            case THREES:
62
-                scores.put(ROW.THREES, scoreNumbers(numbers, 3));
63
-                break;
64
-            case FOURS:
65
-                scores.put(ROW.FOURS, scoreNumbers(numbers, 4));
66
-                break;
67
-            case FIVES:
68
-                scores.put(ROW.FIVES, scoreNumbers(numbers, 5));
69
-                break;
70
-            case SIXES:
71
-                scores.put(ROW.SIXES, scoreNumbers(numbers, 6));
72
-                break;
73
-            case THREEOFAKIND:
74
-                if(checkOfaKind(numbers, 3)) {
75
-                scores.put(ROW.THREEOFAKIND, scoreTotalDice(numbers));
76
-                } else {
77
-                    scores.put(ROW.THREEOFAKIND, 0); 
78
-                }
79
-                break;
80
-            case FOUROFAKIND:
81
-                if(checkOfaKind(numbers, 4)) {
82
-                    scores.put(ROW.FOUROFAKIND, scoreTotalDice(numbers));
83
-                } else {
84
-                    scores.put(ROW.FOUROFAKIND, 0);
85
-                }
86
-                break;
87
-            case FULLHOUSE:
88
-                if(checkOfaKind(numbers,5) || checkFullHouse(numbers)) {
89
-                    scores.put(ROW.FULLHOUSE, 25);
90
-                } else {
91
-                    scores.put(ROW.FULLHOUSE, 0);
92
-                }
93
-                break;
94
-            case SMALLSTRAIGHT:
95
-                if(checkSmallStraight(numbers)) {
96
-                    scores.put(ROW.SMALLSTRAIGHT, 30);
97
-                } else {
98
-                    scores.put(ROW.SMALLSTRAIGHT, 0);
99
-                }
100
-                break;
101
-            case LARGESTRAIGHT:
102
-                if(checkLargeStraight(numbers)) {
103
-                    scores.put(ROW.LARGESTRAIGHT, 40);
104
-                } else {
105
-                    scores.put(ROW.LARGESTRAIGHT, 0);
106
-                }
107
-                break;
108
-            case YAHTZEE:
109
-                if(checkOfaKind(numbers, 5)) {
110
-                    scores.put(ROW.YAHTZEE, 50);
111
-                } else {
112
-                    scores.put(ROW.YAHTZEE, 0);
113
-                }
114
-                break;
115
-            case CHANCE:
116
-                scores.put(ROW.CHANCE, scoreTotalDice(numbers));
117
-                break;
48
+        if(scores.get(row) != null) {
49
+            System.out.println("Error, you have already filled that row");
50
+        } else {
51
+            ArrayList<Integer> numbers = new ArrayList<>();
52
+            for (Dice d : cup) {
53
+                numbers.add(d.getValue());
54
+            }
55
+            Collections.sort(numbers);
56
+
57
+            switch (row) {
58
+                case ACES:
59
+                    scores.put(ROW.ACES, scoreNumbers(numbers, 1));
60
+                    break;
61
+                case TWOS:
62
+                    scores.put(ROW.TWOS, scoreNumbers(numbers, 2));
63
+                    break;
64
+                case THREES:
65
+                    scores.put(ROW.THREES, scoreNumbers(numbers, 3));
66
+                    break;
67
+                case FOURS:
68
+                    scores.put(ROW.FOURS, scoreNumbers(numbers, 4));
69
+                    break;
70
+                case FIVES:
71
+                    scores.put(ROW.FIVES, scoreNumbers(numbers, 5));
72
+                    break;
73
+                case SIXES:
74
+                    scores.put(ROW.SIXES, scoreNumbers(numbers, 6));
75
+                    break;
76
+                case THREEOFAKIND:
77
+                    if (checkOfaKind(numbers, 3)) {
78
+                        scores.put(ROW.THREEOFAKIND, scoreTotalDice(numbers));
79
+                    } else {
80
+                        scores.put(ROW.THREEOFAKIND, 0);
81
+                    }
82
+                    break;
83
+                case FOUROFAKIND:
84
+                    if (checkOfaKind(numbers, 4)) {
85
+                        scores.put(ROW.FOUROFAKIND, scoreTotalDice(numbers));
86
+                    } else {
87
+                        scores.put(ROW.FOUROFAKIND, 0);
88
+                    }
89
+                    break;
90
+                case FULLHOUSE:
91
+                    if (checkOfaKind(numbers, 5) || checkFullHouse(numbers)) {
92
+                        scores.put(ROW.FULLHOUSE, 25);
93
+                    } else {
94
+                        scores.put(ROW.FULLHOUSE, 0);
95
+                    }
96
+                    break;
97
+                case SMALLSTRAIGHT:
98
+                    if (checkSmallStraight(numbers)) {
99
+                        scores.put(ROW.SMALLSTRAIGHT, 30);
100
+                    } else {
101
+                        scores.put(ROW.SMALLSTRAIGHT, 0);
102
+                    }
103
+                    break;
104
+                case LARGESTRAIGHT:
105
+                    if (checkLargeStraight(numbers)) {
106
+                        scores.put(ROW.LARGESTRAIGHT, 40);
107
+                    } else {
108
+                        scores.put(ROW.LARGESTRAIGHT, 0);
109
+                    }
110
+                    break;
111
+                case YAHTZEE:
112
+                    if (checkOfaKind(numbers, 5)) {
113
+                        scores.put(ROW.YAHTZEE, 50);
114
+                    } else {
115
+                        scores.put(ROW.YAHTZEE, 0);
116
+                    }
117
+                    break;
118
+                case CHANCE:
119
+                    scores.put(ROW.CHANCE, scoreTotalDice(numbers));
120
+                    break;
121
+            }
118 122
         }
119 123
 
120 124
     }