Kaynağa Gözat

merge resolved card game comments removed

Nick Satinover 6 yıl önce
ebeveyn
işleme
119c369000

+ 6
- 0
src/.idea/misc.xml Dosyayı Görüntüle

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="JavaScriptSettings">
4
+    <option name="languageLevel" value="ES6" />
5
+  </component>
6
+</project>

+ 8
- 0
src/.idea/modules.xml Dosyayı Görüntüle

@@ -0,0 +1,8 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ProjectModuleManager">
4
+    <modules>
5
+      <module fileurl="file://$PROJECT_DIR$/.idea/src.iml" filepath="$PROJECT_DIR$/.idea/src.iml" />
6
+    </modules>
7
+  </component>
8
+</project>

+ 6
- 0
src/.idea/vcs.xml Dosyayı Görüntüle

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="VcsDirectoryMappings">
4
+    <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
5
+  </component>
6
+</project>

+ 236
- 0
src/.idea/workspace.xml Dosyayı Görüntüle

@@ -0,0 +1,236 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ChangeListManager">
4
+    <list default="true" id="74cab72c-e027-4e61-ac26-2617cf8ce683" name="Default Changelist" comment="">
5
+      <change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
6
+      <change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
7
+      <change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
8
+      <change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
9
+      <change afterPath="$PROJECT_DIR$/test/java/io/zipcoder/casino/SlotTest.java" afterDir="false" />
10
+      <change beforePath="$PROJECT_DIR$/main/java/io/zipcoder/casino/Casino.java" beforeDir="false" afterPath="$PROJECT_DIR$/main/java/io/zipcoder/casino/Casino.java" afterDir="false" />
11
+      <change beforePath="$PROJECT_DIR$/main/java/io/zipcoder/casino/Game.java" beforeDir="false" afterPath="$PROJECT_DIR$/main/java/io/zipcoder/casino/Game.java" afterDir="false" />
12
+      <change beforePath="$PROJECT_DIR$/main/java/io/zipcoder/casino/Printer.java" beforeDir="false" afterPath="$PROJECT_DIR$/main/java/io/zipcoder/casino/Printer.java" afterDir="false" />
13
+      <change beforePath="$PROJECT_DIR$/main/java/io/zipcoder/casino/SlotMachine.java" beforeDir="false" afterPath="$PROJECT_DIR$/main/java/io/zipcoder/casino/SlotMachine.java" afterDir="false" />
14
+      <change beforePath="$PROJECT_DIR$/main/java/io/zipcoder/casino/Yahtzee.java" beforeDir="false" afterPath="$PROJECT_DIR$/main/java/io/zipcoder/casino/Yahtzee.java" afterDir="false" />
15
+      <change beforePath="$PROJECT_DIR$/test/java/io/zipcoder/casino/CardTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/test/java/io/zipcoder/casino/CardTest.java" afterDir="false" />
16
+    </list>
17
+    <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
18
+    <option name="SHOW_DIALOG" value="false" />
19
+    <option name="HIGHLIGHT_CONFLICTS" value="true" />
20
+    <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
21
+    <option name="LAST_RESOLUTION" value="IGNORE" />
22
+  </component>
23
+  <component name="FUSProjectUsageTrigger">
24
+    <session id="729355978">
25
+      <usages-collector id="statistics.lifecycle.project">
26
+        <counts>
27
+          <entry key="project.closed" value="1" />
28
+          <entry key="project.open.time.1" value="1" />
29
+          <entry key="project.opened" value="1" />
30
+        </counts>
31
+      </usages-collector>
32
+      <usages-collector id="statistics.file.extensions.open">
33
+        <counts>
34
+          <entry key="java" value="1" />
35
+        </counts>
36
+      </usages-collector>
37
+      <usages-collector id="statistics.file.types.open">
38
+        <counts>
39
+          <entry key="JAVA" value="1" />
40
+        </counts>
41
+      </usages-collector>
42
+    </session>
43
+  </component>
44
+  <component name="FileEditorManager">
45
+    <leaf>
46
+      <file pinned="false" current-in-tab="true">
47
+        <entry file="file://$PROJECT_DIR$/test/java/io/zipcoder/casino/CardTest.java">
48
+          <provider selected="true" editor-type-id="text-editor">
49
+            <state relative-caret-position="60">
50
+              <caret line="4" column="30" lean-forward="true" selection-start-line="4" selection-start-column="30" selection-end-line="4" selection-end-column="30" />
51
+              <folding>
52
+                <element signature="imports" expanded="true" />
53
+              </folding>
54
+            </state>
55
+          </provider>
56
+        </entry>
57
+      </file>
58
+    </leaf>
59
+  </component>
60
+  <component name="Git.Settings">
61
+    <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
62
+  </component>
63
+  <component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
64
+  <component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
65
+  <component name="JsGulpfileManager">
66
+    <detection-done>true</detection-done>
67
+    <sorting>DEFINITION_ORDER</sorting>
68
+  </component>
69
+  <component name="ProjectFrameBounds" extendedState="6" fullScreen="true">
70
+    <option name="y" value="23" />
71
+    <option name="width" value="1440" />
72
+    <option name="height" value="817" />
73
+  </component>
74
+  <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
75
+  <component name="ProjectView">
76
+    <navigator proportions="" version="1">
77
+      <foldersAlwaysOnTop value="true" />
78
+    </navigator>
79
+    <panes>
80
+      <pane id="ProjectPane">
81
+        <subPane>
82
+          <expand>
83
+            <path>
84
+              <item name="src" type="b2602c69:ProjectViewProjectNode" />
85
+              <item name="src" type="462c0819:PsiDirectoryNode" />
86
+            </path>
87
+            <path>
88
+              <item name="src" type="b2602c69:ProjectViewProjectNode" />
89
+              <item name="src" type="462c0819:PsiDirectoryNode" />
90
+              <item name="main" type="462c0819:PsiDirectoryNode" />
91
+            </path>
92
+            <path>
93
+              <item name="src" type="b2602c69:ProjectViewProjectNode" />
94
+              <item name="src" type="462c0819:PsiDirectoryNode" />
95
+              <item name="main" type="462c0819:PsiDirectoryNode" />
96
+              <item name="java" type="462c0819:PsiDirectoryNode" />
97
+            </path>
98
+            <path>
99
+              <item name="src" type="b2602c69:ProjectViewProjectNode" />
100
+              <item name="src" type="462c0819:PsiDirectoryNode" />
101
+              <item name="main" type="462c0819:PsiDirectoryNode" />
102
+              <item name="java" type="462c0819:PsiDirectoryNode" />
103
+              <item name="casino" type="462c0819:PsiDirectoryNode" />
104
+            </path>
105
+            <path>
106
+              <item name="src" type="b2602c69:ProjectViewProjectNode" />
107
+              <item name="src" type="462c0819:PsiDirectoryNode" />
108
+              <item name="test" type="462c0819:PsiDirectoryNode" />
109
+            </path>
110
+            <path>
111
+              <item name="src" type="b2602c69:ProjectViewProjectNode" />
112
+              <item name="src" type="462c0819:PsiDirectoryNode" />
113
+              <item name="test" type="462c0819:PsiDirectoryNode" />
114
+              <item name="java" type="462c0819:PsiDirectoryNode" />
115
+            </path>
116
+            <path>
117
+              <item name="src" type="b2602c69:ProjectViewProjectNode" />
118
+              <item name="src" type="462c0819:PsiDirectoryNode" />
119
+              <item name="test" type="462c0819:PsiDirectoryNode" />
120
+              <item name="java" type="462c0819:PsiDirectoryNode" />
121
+              <item name="casino" type="462c0819:PsiDirectoryNode" />
122
+            </path>
123
+          </expand>
124
+          <select />
125
+        </subPane>
126
+      </pane>
127
+      <pane id="PackagesPane" />
128
+      <pane id="Scope" />
129
+    </panes>
130
+  </component>
131
+  <component name="PropertiesComponent">
132
+    <property name="WebServerToolWindowFactoryState" value="false" />
133
+    <property name="aspect.path.notification.shown" value="true" />
134
+    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1541771782363" />
135
+    <property name="last_opened_file_path" value="$PROJECT_DIR$" />
136
+    <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
137
+    <property name="nodejs_npm_path_reset_for_default_project" value="true" />
138
+    <property name="settings.editor.selected.configurable" value="preferences.general" />
139
+  </component>
140
+  <component name="RunDashboard">
141
+    <option name="ruleStates">
142
+      <list>
143
+        <RuleState>
144
+          <option name="name" value="ConfigurationTypeDashboardGroupingRule" />
145
+        </RuleState>
146
+        <RuleState>
147
+          <option name="name" value="StatusDashboardGroupingRule" />
148
+        </RuleState>
149
+      </list>
150
+    </option>
151
+  </component>
152
+  <component name="SvnConfiguration">
153
+    <configuration />
154
+  </component>
155
+  <component name="TaskManager">
156
+    <task active="true" id="Default" summary="Default task">
157
+      <changelist id="74cab72c-e027-4e61-ac26-2617cf8ce683" name="Default Changelist" comment="" />
158
+      <created>1541771578720</created>
159
+      <option name="number" value="Default" />
160
+      <option name="presentableId" value="Default" />
161
+      <updated>1541771578720</updated>
162
+      <workItem from="1541771580200" duration="204000" />
163
+    </task>
164
+    <servers />
165
+  </component>
166
+  <component name="TimeTrackingManager">
167
+    <option name="totallyTimeSpent" value="204000" />
168
+  </component>
169
+  <component name="ToolWindowManager">
170
+    <frame x="0" y="0" width="1440" height="900" extended-state="6" />
171
+    <editor active="true" />
172
+    <layout>
173
+      <window_info id="Image Layers" />
174
+      <window_info id="Designer" />
175
+      <window_info id="UI Designer" />
176
+      <window_info id="Capture Tool" />
177
+      <window_info id="Favorites" side_tool="true" />
178
+      <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.24964234" />
179
+      <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
180
+      <window_info anchor="bottom" id="Database Changes" show_stripe_button="false" />
181
+      <window_info anchor="bottom" id="Version Control" show_stripe_button="false" />
182
+      <window_info anchor="bottom" id="Terminal" />
183
+      <window_info anchor="bottom" id="Event Log" side_tool="true" />
184
+      <window_info anchor="bottom" id="Message" order="0" />
185
+      <window_info anchor="bottom" id="Find" order="1" />
186
+      <window_info anchor="bottom" id="Run" order="2" />
187
+      <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
188
+      <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
189
+      <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
190
+      <window_info anchor="bottom" id="TODO" order="6" />
191
+      <window_info anchor="right" id="Palette" />
192
+      <window_info anchor="right" id="Theme Preview" />
193
+      <window_info anchor="right" id="Capture Analysis" />
194
+      <window_info anchor="right" id="Palette&#9;" />
195
+      <window_info anchor="right" id="Database" />
196
+      <window_info anchor="right" id="Maven Projects" />
197
+      <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
198
+      <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
199
+      <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
200
+    </layout>
201
+  </component>
202
+  <component name="TypeScriptGeneratedFilesManager">
203
+    <option name="version" value="1" />
204
+  </component>
205
+  <component name="VcsContentAnnotationSettings">
206
+    <option name="myLimit" value="2678400000" />
207
+  </component>
208
+  <component name="editorHistoryManager">
209
+    <entry file="file://$PROJECT_DIR$/test/java/io/zipcoder/casino/CardTest.java">
210
+      <provider selected="true" editor-type-id="text-editor">
211
+        <state relative-caret-position="60">
212
+          <caret line="4" column="30" lean-forward="true" selection-start-line="4" selection-start-column="30" selection-end-line="4" selection-end-column="30" />
213
+          <folding>
214
+            <element signature="imports" expanded="true" />
215
+          </folding>
216
+        </state>
217
+      </provider>
218
+    </entry>
219
+  </component>
220
+  <component name="masterDetails">
221
+    <states>
222
+      <state key="ProjectJDKs.UI">
223
+        <settings>
224
+          <last-edited>1.8</last-edited>
225
+          <splitter-proportions>
226
+            <option name="proportions">
227
+              <list>
228
+                <option value="0.2" />
229
+              </list>
230
+            </option>
231
+          </splitter-proportions>
232
+        </settings>
233
+      </state>
234
+    </states>
235
+  </component>
236
+</project>

+ 2
- 25
src/main/java/io/zipcoder/casino/Card.java Dosyayı Görüntüle

@@ -14,22 +14,15 @@ public class Card {
14 14
         this.name = cardValue + " of " + suit;
15 15
     }
16 16
 
17
+
17 18
     public String getName() {
18 19
         return name;
19 20
     }
20 21
 
21
-    public void setName(String name) {
22
-        this.name = name;
23
-    }
24
-
25 22
     public boolean isVisible() {
26 23
         return isVisible;
27 24
     }
28 25
 
29
-    public void setVisible(boolean visible) {
30
-        isVisible = visible;
31
-    }
32
-
33 26
     public void setVisibility(boolean visibility){
34 27
         isVisible = visibility;
35 28
     }
@@ -39,21 +32,11 @@ public class Card {
39 32
         return suit;
40 33
     }
41 34
 
42
-    public void setSuit(Suit suit)
43
-    {
44
-        this.suit = suit;
45
-    }
46
-
47 35
     public int getCardValue()
48 36
     {
49 37
         return cardValue.getCardValue();
50 38
     }
51 39
 
52
-    public void setCardValue(CardValue cardValue)
53
-    {
54
-        this.cardValue = cardValue;
55
-    }
56
-
57 40
     public enum CardValue
58 41
     {
59 42
         TWO(2),
@@ -94,11 +77,5 @@ public class Card {
94 77
         Suit (String suitValue)
95 78
         {
96 79
             this.suitValue = suitValue;
97
-        }
98
-
99
-        public String getSuitValue(){
100
-            return suitValue;
101
-        }
102
-
103
-    }
80
+        }}
104 81
 }

+ 11
- 2
src/main/java/io/zipcoder/casino/Casino.java Dosyayı Görüntüle

@@ -67,19 +67,25 @@ public class Casino {
67 67
 
68 68
                 case 4:
69 69
                     int slotBet1= console.getIntFromUser("Enter the amount you want to bet on Slot");
70
+                    if ((slotBet1 < 0) || (slotBet1 >100) )
71
+                    {
72
+                        Printer.printMessage("Invalid bet amount entered, min bet for slot is $1 and max $100 ");
73
+                        break;
74
+                    }
70 75
                     Game slot= new SlotMachine(slotBet1);
71
-                    slot.startGame();
72 76
                     game = slot;
77
+                    slot.startGame();
78
+                    ((SlotMachine) slot).slotResult();
73 79
                     ((SlotMachine) slot).payout();
74 80
                     break;
75 81
 
76 82
                 case 1:
77 83
                     Game yahtzee = new Yahtzee(player);
84
+                    game = yahtzee;
78 85
                     ((Yahtzee) yahtzee).startGame();
79 86
                     int betAmount = console.getIntFromUser("How much would you like to bet on this game?");
80 87
                     ((Yahtzee) yahtzee).setBid(betAmount);
81 88
                     ((Yahtzee) yahtzee).bet(betAmount);
82
-                    game = yahtzee;
83 89
                     yahtzee.startRound();
84 90
                     Printer.printMessage("You scored " + ((Yahtzee) yahtzee).getDicePlayer().getScoreSheet().getTotalScore() + " points.");
85 91
                     ((Yahtzee) yahtzee).payout();
@@ -132,4 +138,7 @@ public class Casino {
132 138
     public Game getGame() {
133 139
         return game;
134 140
     }
141
+    public boolean isRunning() {
142
+        return running;
143
+    }
135 144
 }

+ 70
- 74
src/main/java/io/zipcoder/casino/SlotMachine.java Dosyayı Görüntüle

@@ -1,13 +1,17 @@
1 1
 package io.zipcoder.casino;
2 2
 
3 3
 import java.util.Random;
4
-import java.util.Scanner;
5
-
6
-import static java.lang.Thread.sleep;
7 4
 
8 5
 public class SlotMachine implements Game, Gamble {
9 6
     private int betAmount;
10
-    private int payout=0;
7
+    private int payoutAmt=0;
8
+    String word="";
9
+    String outputword="";
10
+
11
+    String word1="";
12
+    String word2="";
13
+    String word3="";
14
+    double totalBet=0;
11 15
 
12 16
     public SlotMachine(int betAmount) {
13 17
         this.betAmount = betAmount;
@@ -16,12 +20,10 @@ public class SlotMachine implements Game, Gamble {
16 20
     @Override
17 21
     public void bet(int betAmount) {
18 22
         this.betAmount= betAmount;
19
-
20 23
     }
21 24
 
22
-    @Override
23 25
     public void payout(){
24
-        Printer.printMessage("Your payout amount for slot machine is: $" + payout + "\n");
26
+        Printer.printMessage("Your payout amount for slot machine is: $" + payoutAmt + "\n");
25 27
     }
26 28
 
27 29
     @Override
@@ -32,7 +34,7 @@ public class SlotMachine implements Game, Gamble {
32 34
         } catch (InterruptedException e) {
33 35
             e.printStackTrace();
34 36
         }
35
-        Printer.printMessage("Your slot is in progress"+"\n");
37
+        Printer.printMessage("Your slot is in progress" + "\n");
36 38
 
37 39
         try {
38 40
             Thread.sleep(3000);
@@ -40,85 +42,65 @@ public class SlotMachine implements Game, Gamble {
40 42
             e.printStackTrace();
41 43
         }
42 44
 
43
-        String word="";
44
-        String outputword="";
45
-        String word1="";
46
-        String word2="";
47
-        String word3="";
48
-        //int useramount=0;
49
-        char playAgain= 'y';
50
-        double totalBet=0;
51
-
52
-       // while(playAgain=='y'){
53
-
54
-            outputword="";
55
-
56
-            Random rand = new Random();
57
-
58
-            for(int i = 1; i <=3;i++){
59
-                int randnum = rand.nextInt(6);
60
-                //System.out.println(randnum);
61
-
62
-                if(randnum == 0) {
63
-                    word = "DOG";
64
-                  //  System.out.println("dog");
65
-                }
66
-                else if(randnum == 1) {
67
-                    word = "CAT";
68
-                  //  System.out.println("cat");
69
-                }
70
-                else if(randnum == 2) {
71
-                    word = "RABBIT";
72
-                  //  System.out.println("kjsd");
73
-                }
74
-                else if(randnum == 3) {
75
-                    word = "SQUIRREL";
76
-                  //  System.out.println("sq");
77
-                }
78
-                else if(randnum == 4) {
79
-                    word = "FISH";
80
-                  //  System.out.println("ff");
81
-                }
82
-                else if(randnum == 5) {
83
-                    word = "MOUSE";
84
-                  //  System.out.println("mm");
85
-                }
86
-                // outputword += word;
87
-
88
-                if(i == 1){
89
-                    word1= word;
90
-                //    System.out.println(i);
91
-                }
92
-
93
-                else if(i == 2){
94
-                    word2= word;
95
-                  //  System.out.println(i);
96
-                }
97
-
98
-                else if(i == 3){
99
-                    word3= word;
100
-                   // System.out.println(word3);
101
-                }
45
+
46
+        outputword = "";
47
+
48
+        Random rand = new Random();
49
+
50
+        for (int i = 1; i <= 3; i++) {
51
+            int randnum = rand.nextInt(6);
52
+
53
+
54
+            if (randnum == 0) {
55
+                word = "DOG";
56
+
57
+            } else if (randnum == 1) {
58
+                word = "CAT";
59
+
60
+            } else if (randnum == 2) {
61
+                word = "RABBIT";
62
+
63
+            } else if (randnum == 3) {
64
+                word = "SQUIRREL";
65
+
66
+            } else if (randnum == 4) {
67
+                word = "FISH";
68
+
69
+            } else if (randnum == 5) {
70
+                word = "MOUSE";
71
+
102 72
             }
73
+
74
+            if (i == 1) {
75
+                word1 = word;
76
+            } else if (i == 2) {
77
+                word2 = word;
78
+            } else if (i == 3) {
79
+                word3 = word;
80
+            }
81
+        }
82
+
83
+    }
84
+
85
+    public void slotResult()
86
+    {
103 87
             outputword= "[ " + word1+ " ]" + "   " + "[ " + word2 + " ]" + "   "+ "[ " + word3 + " ]" + "\n" ;
104 88
 
105 89
             if(((!word1.equals(word2)) )&& ((!word1.equals(word3))) && ((!word2.equals(word3)))){
106 90
 
107 91
                 outputword= outputword + "\n"+" You have won $0";
108
-                payout=0;
92
+                payoutAmt=0;
109 93
             }
110
-
111
-            else if( ((word1.equals(word2) == true) && (word1.equals(word3)== false )) || ((word1.equals(word3)== true) && (word1.equals(word2)==false)) || ( (word2.equals(word3)==true) && (word2.equals(word1))==false)){
94
+            else if( (word1.equals(word2) && (!word1.equals(word3))) || ((word1.equals(word3)) && (!word1.equals(word2))) || ((word2.equals(word3)) && (!word2.equals(word1)))){
112 95
 
113 96
                 outputword= outputword + "\n" +" You have won $" + (betAmount*2);
114
-                payout=betAmount*2;
97
+                payoutAmt=betAmount*2;
115 98
             }
116 99
 
117 100
 
118
-            else if( ((word1.equals(word2)==true) && (word1.equals(word3)==true) ) && ((word2.equals(word1)==true) && (word2.equals(word3)==true)) && ( (word3.equals(word1)==true) && (word3.equals(word2)==true))){
119
-
101
+            else if(word1.equals(word2) && word1.equals(word3)  /*&& ((word2.equals(word1)) && (word2.equals(word3))) && ( (word3.equals(word1)) && (word3.equals(word2)))*/){
120 102
                 outputword= outputword + "\n" + "You have won $" + (betAmount*3);
121
-                payout=betAmount*3;
103
+                payoutAmt=betAmount*3;
122 104
             }
123 105
 
124 106
             Printer.printMessage(( outputword + "\n" ));
@@ -134,5 +116,19 @@ public class SlotMachine implements Game, Gamble {
134 116
     public void startRound() {
135 117
 
136 118
     }
119
+    public int getPayoutAmt() {
120
+        return payoutAmt;
121
+    }
122
+    public void setWord1(String word1) {
123
+        this.word1 = word1;
124
+    }
125
+
126
+    public void setWord2(String word2) {
127
+        this.word2 = word2;
128
+    }
129
+
130
+    public void setWord3(String word3) {
131
+        this.word3 = word3;
132
+    }
137 133
 }
138 134
 

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

@@ -109,6 +109,7 @@ public class War extends CardGame implements Gamble, Game {
109 109
         }
110 110
     }
111 111
 
112
+
112 113
     public void startGame(){
113 114
         Printer.printMessage("Welcome to War!");
114 115
         super.chooseStartingPlayer();
@@ -117,6 +118,8 @@ public class War extends CardGame implements Gamble, Game {
117 118
         startRound();
118 119
     }
119 120
 
121
+
122
+
120 123
     public void startRound() {
121 124
         while(super.getLoser() == null) {
122 125
             String input = console.getCMDFromUser("Type 'FLIP' to play the card at the top of your pile");
@@ -151,4 +154,12 @@ public class War extends CardGame implements Gamble, Game {
151 154
         }
152 155
         Printer.printMessage(super.getPlayersTurn().getPlayer().getName() + "has: " + super.getPlayersTurn().getHand().size() + " cards.");
153 156
     }
157
+
158
+    public void setScanner(Scanner scanner) {
159
+        this.console.setScanner(scanner);
160
+    }
161
+
162
+    public ArrayList<CardPlayer> getWarMembers() {
163
+        return warMembers;
164
+    }
154 165
 }

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

@@ -1,7 +1,6 @@
1 1
 package io.zipcoder.casino;
2 2
 
3 3
 import java.util.ArrayList;
4
-import java.util.Scanner;
5 4
 
6 5
 public class Yahtzee extends DiceGame implements Game, Gamble {
7 6
 
@@ -46,7 +45,8 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
46 45
                 int rollChoice = console.getIntFromUser("Would you like to:\n1. Roll all dice again.\n2. Roll some dice again.\n3. Stop rolling and score.\nNumber of Selection: ");
47 46
                 String diceToRoll = "";
48 47
                 if(rollChoice == 2) {
49
-                    diceToRoll = console.getLineFromUser("Which numbers would you like to reroll? List the numbers separated by spaces.");
48
+                    Console console2 = new Console();
49
+                    diceToRoll = console2.getLineFromUser("Which numbers would you like to reroll? List the numbers separated by spaces.");
50 50
                 }
51 51
                 rollOptions(rollChoice, diceToRoll); }
52 52
 
@@ -194,7 +194,6 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
194 194
         Printer.printMessage("You won $" + payOut);
195 195
     }
196 196
 
197
-
198 197
     public DicePlayer getDicePlayer() {
199 198
         return dicePlayer;
200 199
     }

+ 27
- 7
src/test/java/io/zipcoder/casino/CardTest.java Dosyayı Görüntüle

@@ -1,21 +1,41 @@
1 1
 package io.zipcoder.casino;
2 2
 
3
+import org.junit.Assert;
3 4
 import org.junit.Test;
4 5
 
5 6
 public class CardTest {
6 7
 
7 8
     @Test
8
-    public void createCard(){
9
+    public void testCreateCard(){
9 10
         Card card = new Card(Card.CardValue.TWO, Card.Suit.CLUBS);
10
-        System.out.println(card.getName());
11
+        String expected = "TWO of CLUBS";
12
+        String actual = card.getName();
13
+        Assert.assertEquals(expected, actual);
11 14
     }
12 15
 
13 16
     @Test
14
-    public void createCard2(){
15
-        Card card = new Card(Card.CardValue.TWO, Card.Suit.CLUBS);
16
-        Card card1 = new Card(Card.CardValue.QUEEN, Card.Suit.HEARTS);
17
-        System.out.println(card.getName());
18
-        System.out.println(card1.getName());
17
+    public void testGetSuit(){
18
+        Card card = new Card(Card.CardValue.THREE, Card.Suit.DIAMONDS);
19
+        Card.Suit expected = Card.Suit.DIAMONDS;
20
+        Card.Suit actual = card.getSuit();
21
+        Assert.assertEquals(expected, actual);
22
+    }
23
+
24
+    @Test
25
+    public void testGetCardValue(){
26
+        Card card = new Card(Card.CardValue.ACE, Card.Suit.HEARTS);
27
+        int expected = 14;
28
+        int actual = card.getCardValue();
29
+        Assert.assertEquals(expected, actual);
30
+    }
31
+
32
+    @Test
33
+    public void testVisibility(){
34
+        Card card = new Card(Card.CardValue.KING, Card.Suit.SPADES);
35
+        boolean before = card.isVisible();
36
+        card.setVisibility(true);
37
+        boolean after = card.isVisible();
38
+        Assert.assertNotEquals(before, after);
19 39
     }
20 40
 
21 41
 }

+ 50
- 0
src/test/java/io/zipcoder/casino/CasinoTest.java Dosyayı Görüntüle

@@ -4,7 +4,57 @@ package io.zipcoder.casino;
4 4
 import org.junit.Assert;
5 5
 import org.junit.Test;
6 6
 
7
+import java.io.ByteArrayInputStream;
8
+import java.util.NoSuchElementException;
9
+import java.util.Scanner;
10
+
7 11
 public class CasinoTest {
8 12
 
13
+    @Test
14
+    public void testYahtzee(){
15
+        String test = "1";
16
+
17
+        Casino casino = new Casino();
18
+        Console console = new Console();
19
+
20
+        casino.getConsole().setScanner(new Scanner(new ByteArrayInputStream(test.getBytes())));
21
+        try {
22
+            casino.chooseGame();
23
+        }catch(NoSuchElementException e){
24
+
25
+        }
26
+
27
+        Assert.assertTrue(casino.getGame() instanceof Yahtzee);
28
+    }
29
+
30
+    @Test
31
+    public void testGetStudPlayer(){
32
+
33
+        int num = 0;
34
+        String test = "2";
35
+        Casino casino = new Casino();
36
+        Stud stud = new Stud(10);
37
+
38
+        casino.getConsole().setScanner(new Scanner(new ByteArrayInputStream(test.getBytes())));
39
+        try {
40
+            num = casino.getStudPlayers();
41
+        }catch(NoSuchElementException e){
42
+
43
+        }
44
+        System.out.println(num);
45
+        Assert.assertTrue(num == 2);
46
+    }
47
+
48
+    @Test
49
+    public void testWar(){
50
+        Casino casino = new Casino();
51
+        String input = "jon \n 100 \n 2 \n flip";
52
+
53
+        casino.getConsole().setScanner(new Scanner(new ByteArrayInputStream(input.getBytes())));
54
+        try {
55
+            casino.getConsole().createAccount();
56
+        }catch(NoSuchElementException e){
9 57
 
58
+        }
59
+    }
10 60
 }

+ 67
- 0
src/test/java/io/zipcoder/casino/SlotTest.java Dosyayı Görüntüle

@@ -0,0 +1,67 @@
1
+package io.zipcoder.casino;
2
+
3
+
4
+import org.junit.Test;
5
+import org.junit.Assert;
6
+
7
+
8
+public class SlotTest {
9
+
10
+    @Test
11
+    public void testSlotResult1(){
12
+        int betAmount=10;
13
+        String word1="MOUSE";
14
+        String word2="MOUSE";
15
+        String word3="MOUSE";
16
+        //given
17
+        SlotMachine slotmachine = new SlotMachine(betAmount);
18
+        slotmachine.setWord1(word1);
19
+        slotmachine.setWord2(word2);
20
+        slotmachine.setWord3(word3);
21
+
22
+        slotmachine.slotResult();
23
+        int payout = slotmachine.getPayoutAmt();
24
+        Assert.assertEquals(30,payout);
25
+    }
26
+
27
+
28
+    @Test
29
+    public void testSlotResult2(){
30
+        int betAmount=10;
31
+        String word1="MOUSE";
32
+        String word2="MOUSE";
33
+        String word3="CAT";
34
+
35
+
36
+        //given
37
+        SlotMachine slotmachine = new SlotMachine(betAmount);
38
+
39
+        slotmachine.setWord1(word1);
40
+        slotmachine.setWord2(word2);
41
+        slotmachine.setWord3(word3);
42
+
43
+        slotmachine.slotResult();
44
+        int payout=slotmachine.getPayoutAmt();
45
+        Assert.assertEquals(20,payout);
46
+
47
+    }
48
+
49
+    @Test
50
+    public void testSlotResult3(){
51
+        int betAmount=10;
52
+        String word1="MOUSE";
53
+        String word2="RABBIT";
54
+        String word3="CAT";
55
+
56
+        //given
57
+        SlotMachine slotmachine = new SlotMachine(betAmount);
58
+
59
+        slotmachine.setWord1(word1);
60
+        slotmachine.setWord2(word2);
61
+        slotmachine.setWord3(word3);
62
+
63
+        slotmachine.slotResult();
64
+        int payout=slotmachine.getPayoutAmt();
65
+        Assert.assertEquals(0,payout);
66
+    }
67
+}

+ 4
- 0
src/test/java/io/zipcoder/casino/StudTest.java Dosyayı Görüntüle

@@ -4,7 +4,10 @@ import org.junit.Assert;
4 4
 import org.junit.Before;
5 5
 import org.junit.Test;
6 6
 
7
+import java.io.ByteArrayInputStream;
7 8
 import java.util.ArrayList;
9
+import java.util.NoSuchElementException;
10
+import java.util.Scanner;
8 11
 
9 12
 public class StudTest {
10 13
 
@@ -241,6 +244,7 @@ public class StudTest {
241 244
     @Test //Either payAnte or Test is broken, Ante is not deducted. Test set to pass
242 245
     public void payAnteTest(){
243 246
         stud.payAnte(players);
247
+        System.out.println(players.get(0).getPlayer().getCurrentBalance());
244 248
         //WHEN @Before
245 249
         int expected = 0;
246 250
         //THEN

+ 117
- 0
src/test/java/io/zipcoder/casino/WarTest.java Dosyayı Görüntüle

@@ -3,6 +3,11 @@ package io.zipcoder.casino;
3 3
 import org.junit.Assert;
4 4
 import org.junit.Test;
5 5
 
6
+import java.io.ByteArrayInputStream;
7
+import java.util.ArrayList;
8
+import java.util.NoSuchElementException;
9
+import java.util.Scanner;
10
+
6 11
 public class WarTest {
7 12
 
8 13
     @Test
@@ -40,4 +45,116 @@ public class WarTest {
40 45
         Assert.assertEquals(war.getLoser(), player);
41 46
     }
42 47
 
48
+    @Test
49
+    public void warDealTest(){
50
+        War war = new War(10);
51
+        war.addPlayers(new Player("Jon", 100));
52
+        war.chooseStatingPlayer();
53
+        war.deal();
54
+
55
+        Assert.assertTrue(war.getPlayers().get(0).getHand().size() == 52);
56
+    }
57
+
58
+    @Test
59
+    public void warEachPlayerPlayCardTest(){
60
+        War war = new War(10);
61
+        war.addPlayers(new Player("Jon", 100), new Player("Jose", 200));
62
+
63
+        war.chooseStatingPlayer();
64
+        war.deal();
65
+        war.eachPlayerPlayCard();
66
+
67
+        int toalHand = 0;
68
+
69
+        for(CardPlayer player : war.getPlayers()){
70
+            toalHand += player.getHand().size();
71
+        }
72
+        Assert.assertTrue(toalHand == 50);
73
+    }
74
+
75
+    @Test
76
+    public void testWarStartGame(){
77
+        War war = new War(10);
78
+        Player player1 = new Player("Jose", 100);
79
+        Player player2 = new Player("Lauren", 200);
80
+        war.addPlayers(player1, player2);
81
+        war.chooseStatingPlayer();
82
+        war.deal();
83
+
84
+        String input = "flip \n";
85
+
86
+
87
+            war.setScanner(new Scanner(new ByteArrayInputStream(input.getBytes())));
88
+            try {
89
+                war.startGame();
90
+            } catch (NoSuchElementException e) {
91
+
92
+            }
93
+
94
+
95
+        Assert.assertTrue(war.getPlayersTurn() instanceof CardPlayer);
96
+    }
97
+
98
+    @Test
99
+    public void testWarQuit(){
100
+        War war = new War(10);
101
+        Player player1 = new Player("Jose", 100);
102
+        Player player2 = new Player("Lauren", 200);
103
+        war.addPlayers(player1, player2);
104
+        war.chooseStatingPlayer();
105
+        CardPlayer startPlayer = war.getPlayersTurn();
106
+        war.deal();
107
+
108
+        String input = "quit \n";
109
+
110
+
111
+        war.setScanner(new Scanner(new ByteArrayInputStream(input.getBytes())));
112
+        try {
113
+            war.startGame();
114
+        } catch (NoSuchElementException e) {
115
+
116
+        }
117
+
118
+
119
+       Assert.assertTrue(war.getPlayersTurn() == startPlayer);
120
+    }
121
+
122
+    @Test
123
+    public void testWarMethod(){
124
+        War war = new War(10);
125
+        Player player1 = new Player("Jose", 100);
126
+        Player player2 = new Player("Lauren", 200);
127
+        war.addPlayers(player1, player2);
128
+        war.chooseStatingPlayer();
129
+        CardPlayer startPlayer = war.getPlayersTurn();
130
+
131
+        ArrayList<Card> hand1 = new ArrayList<>();
132
+        hand1.add(new Card(Card.CardValue.FOUR, Card.Suit.HEARTS));
133
+        hand1.add(new Card(Card.CardValue.FOUR, Card.Suit.HEARTS));
134
+        hand1.add(new Card(Card.CardValue.THREE, Card.Suit.HEARTS));
135
+        hand1.add(new Card(Card.CardValue.TWO, Card.Suit.HEARTS));
136
+        hand1.add(new Card(Card.CardValue.ACE, Card.Suit.HEARTS));
137
+
138
+        ArrayList<Card> hand2 = new ArrayList<>();
139
+        hand2.add(new Card(Card.CardValue.FOUR, Card.Suit.HEARTS));
140
+        hand2.add(new Card(Card.CardValue.KING, Card.Suit.HEARTS));
141
+        hand2.add(new Card(Card.CardValue.JACK, Card.Suit.HEARTS));
142
+        hand2.add(new Card(Card.CardValue.QUEEN, Card.Suit.HEARTS));
143
+        hand2.add(new Card(Card.CardValue.KING, Card.Suit.HEARTS));
144
+
145
+        String input = "flip \n";
146
+
147
+        war.getPlayers().get(0).setHand(hand1);
148
+        war.getPlayers().get(1).setHand(hand2);
149
+
150
+        war.setScanner(new Scanner(new ByteArrayInputStream(input.getBytes())));
151
+        try {
152
+            war.startRound();
153
+        } catch (NoSuchElementException e) {
154
+
155
+        }
156
+
157
+        Assert.assertTrue(war.getPlayers().get(0).getHand().size() == 1);
158
+    }
159
+
43 160
 }