|
@@ -12,18 +12,23 @@ public class SlotMachine implements Game, Gamble {
|
12
|
12
|
String word2="";
|
13
|
13
|
String word3="";
|
14
|
14
|
double totalBet=0;
|
|
15
|
+ Player player;
|
|
16
|
+
|
|
17
|
+ public SlotMachine(int betAmount, Player player) {
|
15
|
18
|
|
16
|
|
- public SlotMachine(int betAmount) {
|
17
|
19
|
this.betAmount = betAmount;
|
|
20
|
+ this.player = player;
|
18
|
21
|
}
|
19
|
22
|
|
20
|
23
|
@Override
|
21
|
24
|
public void bet(int betAmount) {
|
22
|
|
- this.betAmount= betAmount;
|
|
25
|
+ player.changeBalance(-betAmount);
|
23
|
26
|
}
|
24
|
27
|
|
25
|
28
|
public void payout(){
|
|
29
|
+ getPlayer().changeBalance(payoutAmt);
|
26
|
30
|
Printer.printMessage("Your payout amount for slot machine is: $" + payoutAmt + "\n");
|
|
31
|
+
|
27
|
32
|
}
|
28
|
33
|
|
29
|
34
|
@Override
|
|
@@ -36,15 +41,10 @@ public class SlotMachine implements Game, Gamble {
|
36
|
41
|
}
|
37
|
42
|
Printer.printMessage("Your slot is in progress" + "\n");
|
38
|
43
|
|
39
|
|
- try {
|
40
|
|
- Thread.sleep(3000);
|
41
|
|
- } catch (InterruptedException e) {
|
42
|
|
- e.printStackTrace();
|
43
|
|
- }
|
44
|
|
-
|
45
|
|
-
|
46
|
|
- outputword = "";
|
|
44
|
+ startRound();
|
|
45
|
+ }
|
47
|
46
|
|
|
47
|
+ public void generateWords() {
|
48
|
48
|
Random rand = new Random();
|
49
|
49
|
|
50
|
50
|
for (int i = 1; i <= 3; i++) {
|
|
@@ -79,28 +79,26 @@ public class SlotMachine implements Game, Gamble {
|
79
|
79
|
word3 = word;
|
80
|
80
|
}
|
81
|
81
|
}
|
82
|
|
-
|
|
82
|
+ outputword= "[ " + word1+ " ]" + " " + "[ " + word2 + " ]" + " "+ "[ " + word3 + " ]" + "\n" ;
|
83
|
83
|
}
|
84
|
84
|
|
85
|
85
|
public void slotResult()
|
86
|
86
|
{
|
87
|
|
- outputword= "[ " + word1+ " ]" + " " + "[ " + word2 + " ]" + " "+ "[ " + word3 + " ]" + "\n" ;
|
88
|
|
-
|
89
|
87
|
if(((!word1.equals(word2)) )&& ((!word1.equals(word3))) && ((!word2.equals(word3)))){
|
90
|
88
|
|
91
|
89
|
outputword= outputword + "\n"+" You have won $0";
|
92
|
|
- payoutAmt=0;
|
|
90
|
+ setPayoutAmt(0);
|
93
|
91
|
}
|
94
|
92
|
else if( (word1.equals(word2) && (!word1.equals(word3))) || ((word1.equals(word3)) && (!word1.equals(word2))) || ((word2.equals(word3)) && (!word2.equals(word1)))){
|
95
|
93
|
|
96
|
94
|
outputword= outputword + "\n" +" You have won $" + (betAmount*2);
|
97
|
|
- payoutAmt=betAmount*2;
|
|
95
|
+ setPayoutAmt(betAmount*2);
|
98
|
96
|
}
|
99
|
97
|
|
100
|
98
|
|
101
|
|
- else if(word1.equals(word2) && word1.equals(word3) /*&& ((word2.equals(word1)) && (word2.equals(word3))) && ( (word3.equals(word1)) && (word3.equals(word2)))*/){
|
|
99
|
+ else if(word1.equals(word2) && word1.equals(word3)) {
|
102
|
100
|
outputword= outputword + "\n" + "You have won $" + (betAmount*3);
|
103
|
|
- payoutAmt=betAmount*3;
|
|
101
|
+ setPayoutAmt(betAmount*3);
|
104
|
102
|
}
|
105
|
103
|
|
106
|
104
|
Printer.printMessage(( outputword + "\n" ));
|
|
@@ -114,11 +112,23 @@ public class SlotMachine implements Game, Gamble {
|
114
|
112
|
|
115
|
113
|
@Override
|
116
|
114
|
public void startRound() {
|
|
115
|
+ try {
|
|
116
|
+ Thread.sleep(3000);
|
|
117
|
+ } catch (InterruptedException e) {
|
|
118
|
+ e.printStackTrace();
|
|
119
|
+ }
|
117
|
120
|
|
|
121
|
+ generateWords();
|
118
|
122
|
}
|
|
123
|
+
|
119
|
124
|
public int getPayoutAmt() {
|
120
|
125
|
return payoutAmt;
|
121
|
126
|
}
|
|
127
|
+
|
|
128
|
+ public void setPayoutAmt(int payoutAmt) {
|
|
129
|
+ this.payoutAmt = payoutAmt;
|
|
130
|
+ }
|
|
131
|
+
|
122
|
132
|
public void setWord1(String word1) {
|
123
|
133
|
this.word1 = word1;
|
124
|
134
|
}
|
|
@@ -130,5 +140,14 @@ public class SlotMachine implements Game, Gamble {
|
130
|
140
|
public void setWord3(String word3) {
|
131
|
141
|
this.word3 = word3;
|
132
|
142
|
}
|
|
143
|
+
|
|
144
|
+ public String getOutputword() {
|
|
145
|
+ return outputword;
|
|
146
|
+ }
|
|
147
|
+
|
|
148
|
+ public Player getPlayer() {
|
|
149
|
+ return player;
|
|
150
|
+ }
|
|
151
|
+
|
133
|
152
|
}
|
134
|
153
|
|