Browse Source

Merge branch 'slots' of sambhutani/ZCW-OOP-Casino into working

jonathan-hinds 6 years ago
parent
commit
50dfc292d8

BIN
.DS_Store View File


+ 71
- 10
src/main/java/io/zipcoder/casino/Console.java View File

@@ -18,6 +18,7 @@ public class Console {
18 18
         gameLib.add("yahtzee");
19 19
         gameLib.add("war");
20 20
         gameLib.add("stud");
21
+        gameLib.add("slot");
21 22
         gameLib.add("quit");
22 23
 
23 24
     }
@@ -40,32 +41,50 @@ public class Console {
40 41
 
41 42
     public void chooseGame()
42 43
     {
44
+
45
+
43 46
         while(running) {
44 47
             System.out.println("Please choose a game to play!");
45
-            String command = getCommand();
48
+            getGameIndex();
49
+
50
+            int command = getIntFromUser();
46 51
 
47 52
             switch (command) {
48 53
 
49
-                case "war":
54
+
55
+                case 2:
56
+                    int[] warMinMax = getMinMax();
50 57
                     Game war = new War(10);
51
-                    ((War) war).addPlayers(players.get(0));
58
+                    ((War) war).addPlayers(player);
52 59
                     ((War) war).addNpc();
53 60
                     war.startGame();
54 61
                     break;
55 62
 
56
-                case "stud":
57
-                    Game stud = new Stud( 10);
58
-                    ((Stud) stud).addPlayers(players.get(0));
59
-                    addStudPlayers(stud);
63
+
64
+                case 3:
65
+                    int[] studMinMax = getMinMax();
66
+                    Game stud = new Stud(10);
67
+                    ((Stud) stud).addPlayers(player);
68
+                    ((Stud) stud).addNpc();
60 69
                     stud.startGame();
61 70
                     break;
62 71
 
63
-                case "yahtzee":
64
-                    Game yahtzee = new Yahtzee(players.get(0));
72
+                case 4:
73
+                    //call the function to get the bet amount
74
+                    int slotBet1= getSlotBet();
75
+                    // call slot machine constructor ie. create object
76
+                    Game slot= new SlotMachine(slotBet1);
77
+                    slot.startGame();
78
+                    // start game
79
+                    ((SlotMachine) slot).payout();
80
+                    break;
81
+
82
+                case 1:
83
+                    Game yahtzee = new Yahtzee(player);
65 84
                     yahtzee.startGame();
66 85
                     break;
67 86
 
68
-                case "quit":
87
+                case 5:
69 88
                     System.out.println("Thanks for your money chump!");
70 89
                     running = false;
71 90
                     break;
@@ -88,6 +107,38 @@ public class Console {
88 107
         return -1;
89 108
     }
90 109
 
110
+
111
+    public int[] getMinMax(){
112
+        Printer.getBet("minimum bet");
113
+        int min = 0;
114
+        while(min <= 0){
115
+            min = getIntFromUser();
116
+            if(min < 0){
117
+                Printer.unacceptableMinBet();
118
+            }
119
+        }
120
+
121
+        Printer.getBet("maximum bet");
122
+        int max = 0;
123
+        while(max < min) {
124
+            max = getIntFromUser();
125
+            if(max < min){
126
+                Printer.unacceptableMaxBet(min);
127
+            }
128
+        }
129
+        int[] minMax = {min, max};
130
+        return minMax;
131
+    }
132
+
133
+    //function to get the bet amount for slot game
134
+    public int getSlotBet(){
135
+        System.out.println("Enter the amount you want to bet on Slot");
136
+        int slotBet= scanner.nextInt();
137
+        return slotBet;
138
+
139
+    }
140
+
141
+
91 142
     public String getCommand() {
92 143
         String command = "";
93 144
         String input = scanner.next();
@@ -127,4 +178,14 @@ public class Console {
127 178
             ((Stud) game).addPlayers(players.get(i));
128 179
         }
129 180
     }
181
+
182
+    public void getGameIndex(){
183
+        int i=1;
184
+
185
+        for (String s: gameLib) {
186
+            System.out.println("Enter "+i+ " for : " + s  );
187
+            i++;
188
+
189
+        }
190
+    }
130 191
 }

+ 167
- 0
src/main/java/io/zipcoder/casino/SlotMachine.java View File

@@ -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
+

+ 1
- 0
src/main/java/io/zipcoder/casino/Stud.java View File

@@ -1,3 +1,4 @@
1
+
1 2
 package io.zipcoder.casino;
2 3
 import java.util.Scanner;
3 4