瀏覽代碼

Merge branch 'Working' of https://git.zipcode.rocks/nedredmond/ZCW-OOP-Casino into Working

pulling
Connor Dunnigan 6 年之前
父節點
當前提交
cd3e70c053

+ 83
- 8
src/main/java/io/zipcoder/casino/Casino.java 查看文件

@@ -1,35 +1,110 @@
1 1
 package io.zipcoder.casino;
2 2
 
3 3
 
4
+import io.zipcoder.casino.cardgames.BlackJack;
5
+import io.zipcoder.casino.cardgames.GoFish;
6
+import io.zipcoder.casino.dicegames.Craps;
7
+import io.zipcoder.casino.player.Player;
4 8
 import io.zipcoder.casino.player.Players;
9
+import io.zipcoder.casino.utilities.Console;
5 10
 import io.zipcoder.casino.utilities.Game;
6 11
 
7 12
 public class Casino {
8 13
     private Game game;
14
+    Players players = Players.getInstance();
15
+    Console console = new Console();
9 16
 
10
-    public void main() {
17
+    public static void main(String[] args) {
18
+        Casino casino = new Casino();
19
+
20
+//before game
21
+        casino.enterPlayers();
22
+        //ADD LOOP
23
+        casino.chooseTable();
24
+
25
+//after game
26
+        casino.printBalance();
27
+        casino.bootPlayer();
11 28
     }
12 29
 
13
-    public Players enterPlayers() {
14
-        return null;
30
+    public void enterPlayers() {
31
+      int numberOfPlayers = console.getIntegerInput("WELCOME TO EPSILON CASINO, CALLED \"ALMOST A CASINO\" ON YELP\n" +
32
+              "PLEASE ENTER A NUMBER OF PLAYERS.");
33
+      String playerNames = "";
34
+      for (int i = 1; i <= numberOfPlayers; i++) {
35
+        String nameOfPlayer = console.getStringInput("PLAYER " + i + ": WHAT IS YOUR NAME?\n");
36
+        players.addPlayer(new Player(nameOfPlayer));
37
+        playerNames += nameOfPlayer + ", ";
38
+      }
39
+      console.println(playerNames + "THANK YOU FOR JOINING US");
15 40
     }
16 41
 
17 42
     public void chooseTable() {
18
-        // runs game.runGame(game);
19
-    }
43
+
44
+      console.println("GAME LIST\n");
45
+      console.println("1. CRAPS\n");
46
+      console.println("2. BLACK JACK\n");
47
+      console.println("3. GO FISH\n");
48
+      console.println("CHOOSE TABLE\n");
49
+      Integer number=console.getIntegerInput("") ;
50
+       switch(number){
51
+         case 1:
52
+              console.println("WELCOME TO CRAPS\n") ;
53
+              game = new Craps();
54
+              break;
55
+        case 2:
56
+              console.println("WELCOME TO BLACK JACK\n") ;
57
+              game = new BlackJack();
58
+              break;
59
+        case 3:
60
+              console.println("WELCOME TO GO FISH\n");
61
+              game = new GoFish();
62
+              break;
63
+       }        
64
+     }
20 65
 
21 66
     public void confirmPlayers() {
67
+      boolean isConfirmed = false;
68
+      while(!isConfirmed){
69
+        console.println("Current Players: ");
70
+        for(Player player : players.getPlayers()){
71
+          console.println(player.getName());
72
+        }
73
+        Integer choice = console.getIntegerInput("Choose option:\n (1)Confirm Players\n (2)Add Player\n (3)Remove Player\n");
74
+        String name;
75
+        switch(choice){
76
+          case 1: isConfirmed = true;
77
+            break;
78
+          case 2: name = console.getStringInput("Enter name of player to add: ");
79
+                    players.addPlayer(new Player(name));
80
+            break;
81
+          case 3: name = console.getStringInput("Enter name of player to remove: ");
82
+                  for(Player player : players.getPlayers()){
83
+                    if(player.getName() == name)
84
+                      players.removePlayer(player);
85
+                  }
86
+            break;
87
+          default: break;
88
+        }
89
+      }
22 90
     }
23 91
 
24 92
     public void bootPlayer() {
25 93
         // If player balance is 0, player game over
94
+        for(Player player : players.getPlayers()) {
95
+          if(player.getChipBalance()<=0){
96
+            console.println(player.getName() + ", YOU ARE BROKE. GTFO, PEASANT.");
97
+            players.removePlayer(player);
98
+          }
99
+        }
26 100
     }
27 101
 
28 102
     public void printBalance() {
103
+      console.println("FYI guys:\n");
104
+      for (Player player : players.getPlayers()){
105
+        console.println(String.format(player.getName() + " has " + player.getChipBalance() + " chips.\n"));
106
+      }
29 107
     }
30 108
 
31
-    public static void main(String[] args) {
32
-        System.out.println("Hello");
33
-    }
34 109
 
35 110
 }

+ 3
- 2
src/main/java/io/zipcoder/casino/dicegames/dice/Dice.java 查看文件

@@ -5,10 +5,11 @@ package io.zipcoder.casino.dicegames.dice;
5 5
     public class Dice {
6 6
         public int dieCount;
7 7
 
8
-        Dice(int dieCount) {
8
+        public Dice(int dieCount) {
9 9
             this.dieCount = dieCount;
10 10
         }
11
-        Dice() {
11
+
12
+        public Dice() {
12 13
             this.dieCount = 1;
13 14
         }
14 15
 

+ 1
- 0
src/main/java/io/zipcoder/casino/player/BlackJackPlayer.java 查看文件

@@ -9,6 +9,7 @@ public class BlackJackPlayer {
9 9
 
10 10
     public BlackJackPlayer(Player player) {
11 11
         this.blackJackPlayer = player;
12
+        this.hand = new CardHand();
12 13
     }
13 14
 
14 15
     public void hit(Player player) {

+ 2
- 2
src/test/java/io/zipcoder/casino/PlayersTest.java 查看文件

@@ -20,12 +20,12 @@ public class PlayersTest {
20 20
 
21 21
     @Test
22 22
     public void addPlayer() {
23
-        Assert.assertTrue(Players.getInstance().playerList.size() == 3);
23
+        Assert.assertTrue(Players.getInstance().getPlayers().size() == 3);
24 24
     }
25 25
 
26 26
     @Test
27 27
     public void removePlayer() {
28 28
         Players.getInstance().removePlayer(player1);
29
-        Assert.assertTrue(Players.getInstance().playerList.size() == 2);
29
+        Assert.assertTrue(Players.getInstance().getPlayers().size() == 2);
30 30
     }
31 31
 }