|
@@ -0,0 +1,167 @@
|
|
1
|
+package io.zipcoder.casino;
|
|
2
|
+
|
|
3
|
+import java.util.Random;
|
|
4
|
+import java.util.Scanner;
|
|
5
|
+
|
|
6
|
+import static java.lang.Thread.sleep;
|
|
7
|
+
|
|
8
|
+public class SlotMachine implements Game, Gamble {
|
|
9
|
+ private int betAmount;
|
|
10
|
+ private int payout=0;
|
|
11
|
+
|
|
12
|
+ public SlotMachine(int betAmount) {
|
|
13
|
+ this.betAmount = betAmount;
|
|
14
|
+ }
|
|
15
|
+
|
|
16
|
+ // implemented from gamble
|
|
17
|
+ @Override
|
|
18
|
+ public void bet(int betAmount) {
|
|
19
|
+ this.betAmount= betAmount;
|
|
20
|
+
|
|
21
|
+ }
|
|
22
|
+
|
|
23
|
+ @Override
|
|
24
|
+ public void payout(){
|
|
25
|
+ System.out.println("Your payout amount for slot machine is: $" +payout +"\n");
|
|
26
|
+
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+ // implementd from game
|
|
31
|
+
|
|
32
|
+ @Override
|
|
33
|
+ public void quit() {
|
|
34
|
+
|
|
35
|
+ }
|
|
36
|
+
|
|
37
|
+ @Override
|
|
38
|
+ public void startGame() {
|
|
39
|
+ System.out.println("You are all set to play a new slot game..zrrr..!"+"\n");
|
|
40
|
+ try {
|
|
41
|
+ Thread.sleep(3000);
|
|
42
|
+ } catch (InterruptedException e) {
|
|
43
|
+ e.printStackTrace();
|
|
44
|
+ }
|
|
45
|
+ System.out.println("Your slot is in progress"+"\n");
|
|
46
|
+
|
|
47
|
+ try {
|
|
48
|
+ Thread.sleep(3000);
|
|
49
|
+ } catch (InterruptedException e) {
|
|
50
|
+ e.printStackTrace();
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+ String word="";
|
|
54
|
+ String outputword="";
|
|
55
|
+ String word1="";
|
|
56
|
+ String word2="";
|
|
57
|
+ String word3="";
|
|
58
|
+ //int useramount=0;
|
|
59
|
+ char playAgain= 'y';
|
|
60
|
+ double totalBet=0;
|
|
61
|
+
|
|
62
|
+ // while(playAgain=='y'){
|
|
63
|
+
|
|
64
|
+ outputword="";
|
|
65
|
+
|
|
66
|
+ Random rand = new Random();
|
|
67
|
+
|
|
68
|
+ for(int i = 1; i <=3;i++){
|
|
69
|
+ int randnum = rand.nextInt(6);
|
|
70
|
+ //System.out.println(randnum);
|
|
71
|
+
|
|
72
|
+ if(randnum == 0) {
|
|
73
|
+ word = "DOG";
|
|
74
|
+ // System.out.println("dog");
|
|
75
|
+ }
|
|
76
|
+ else if(randnum == 1) {
|
|
77
|
+ word = "CAT";
|
|
78
|
+ // System.out.println("cat");
|
|
79
|
+ }
|
|
80
|
+ else if(randnum == 2) {
|
|
81
|
+ word = "RABBIT";
|
|
82
|
+ // System.out.println("kjsd");
|
|
83
|
+ }
|
|
84
|
+ else if(randnum == 3) {
|
|
85
|
+ word = "SQUIRREL";
|
|
86
|
+ // System.out.println("sq");
|
|
87
|
+ }
|
|
88
|
+ else if(randnum == 4) {
|
|
89
|
+ word = "FISH";
|
|
90
|
+ // System.out.println("ff");
|
|
91
|
+ }
|
|
92
|
+ else if(randnum == 5) {
|
|
93
|
+ word = "MOUSE";
|
|
94
|
+ // System.out.println("mm");
|
|
95
|
+ }
|
|
96
|
+ // outputword += word;
|
|
97
|
+
|
|
98
|
+ if(i == 1){
|
|
99
|
+ word1= word;
|
|
100
|
+ // System.out.println(i);
|
|
101
|
+ }
|
|
102
|
+
|
|
103
|
+ else if(i == 2){
|
|
104
|
+ word2= word;
|
|
105
|
+ // System.out.println(i);
|
|
106
|
+ }
|
|
107
|
+
|
|
108
|
+ else if(i == 3){
|
|
109
|
+ word3= word;
|
|
110
|
+ // System.out.println(word3);
|
|
111
|
+ }
|
|
112
|
+ }
|
|
113
|
+ outputword= "[ " + word1+ " ]" + " " + "[ " + word2 + " ]" + " "+ "[ " + word3 + " ]" + "\n" ;
|
|
114
|
+ //System.out.println(outputword);
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+ if(((!word1.equals(word2)) )&& ((!word1.equals(word3))) && ((!word2.equals(word3)))){
|
|
118
|
+
|
|
119
|
+ outputword= outputword + "\n"+" You have won $0";
|
|
120
|
+ payout=0;
|
|
121
|
+ }
|
|
122
|
+
|
|
123
|
+ 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)){
|
|
124
|
+
|
|
125
|
+ outputword= outputword + "\n" +" You have won $" + (betAmount*2);
|
|
126
|
+ payout=betAmount*2;
|
|
127
|
+ }
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+ 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))){
|
|
131
|
+
|
|
132
|
+ outputword= outputword + "\n" + "You have won $" + (betAmount*3);
|
|
133
|
+ payout=betAmount*3;
|
|
134
|
+ }
|
|
135
|
+
|
|
136
|
+ System.out.println(( outputword + "\n" ));
|
|
137
|
+
|
|
138
|
+ try {
|
|
139
|
+ Thread.sleep(2000);
|
|
140
|
+ } catch (InterruptedException e) {
|
|
141
|
+ e.printStackTrace();
|
|
142
|
+ }
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+ }
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+ @Override
|
|
154
|
+ public void startRound() {
|
|
155
|
+
|
|
156
|
+ }
|
|
157
|
+
|
|
158
|
+ /* public void main(String[] args) {
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+ //System.out.println("Enter the amount of money you wan to enter into the slot machine");
|
|
162
|
+ //Scanner scanner = new Scanner(System.in);
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+ }*/
|
|
166
|
+}
|
|
167
|
+
|