Simran Bhutani hace 6 años
padre
commit
ed58911dfc

+ 39
- 5
src/main/java/io/zipcoder/casino/Console.java Ver fichero

@@ -14,6 +14,7 @@ public class Console {
14 14
         gameLib.add("yahtzee");
15 15
         gameLib.add("war");
16 16
         gameLib.add("stud");
17
+        gameLib.add("slot");
17 18
         gameLib.add("quit");
18 19
     }
19 20
 
@@ -30,13 +31,17 @@ public class Console {
30 31
 
31 32
     public void chooseGame()
32 33
     {
34
+
35
+
33 36
         while(running) {
34 37
             System.out.println("Please choose a game to play!");
35
-            String command = getCommand();
38
+            getGameIndex();
39
+
40
+            int command = getIntFromUser();
36 41
 
37 42
             switch (command) {
38 43
 
39
-                case "war":
44
+                case 2:
40 45
                     int[] warMinMax = getMinMax();
41 46
                     Game war = new War(warMinMax[0], warMinMax[1], 10);
42 47
                     ((War) war).addPlayers(player);
@@ -44,7 +49,7 @@ public class Console {
44 49
                     war.startGame();
45 50
                     break;
46 51
 
47
-                case "three card stud":
52
+                case 3:
48 53
                     int[] studMinMax = getMinMax();
49 54
                     Game stud = new Stud(studMinMax[0], studMinMax[1], 10);
50 55
                     ((Stud) stud).addPlayers(player);
@@ -52,12 +57,22 @@ public class Console {
52 57
                     stud.startGame();
53 58
                     break;
54 59
 
55
-                case "yahtzee":
60
+                case 4:
61
+                    //call the function to get the bet amount
62
+                    int slotBet1= getSlotBet();
63
+                    // call slot machine constructor ie. create object
64
+                    Game slot= new SlotMachine(slotBet1);
65
+                    slot.startGame();
66
+                    // start game
67
+                    ((SlotMachine) slot).payout();
68
+                    break;
69
+
70
+                case 1:
56 71
                     Game yahtzee = new Yahtzee(player);
57 72
                     yahtzee.startGame();
58 73
                     break;
59 74
 
60
-                case "quit":
75
+                case 5:
61 76
                     System.out.println("Thanks for your money chump!");
62 77
                     running = false;
63 78
                     break;
@@ -102,6 +117,15 @@ public class Console {
102 117
         return minMax;
103 118
     }
104 119
 
120
+    //function to get the bet amount for slot game
121
+    public int getSlotBet(){
122
+        System.out.println("Enter the amount you want to bet on Slot");
123
+        int slotBet= scanner.nextInt();
124
+        return slotBet;
125
+
126
+    }
127
+
128
+
105 129
     public String getCommand() {
106 130
         String command = "";
107 131
         String input = scanner.next();
@@ -134,4 +158,14 @@ public class Console {
134 158
         }
135 159
         return command;
136 160
     }
161
+
162
+    public void getGameIndex(){
163
+        int i=1;
164
+
165
+        for (String s: gameLib) {
166
+            System.out.println("Enter "+i+ " for : " + s  );
167
+            i++;
168
+
169
+        }
170
+    }
137 171
 }

+ 112
- 75
src/main/java/io/zipcoder/casino/SlotMachine.java Ver fichero

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