Ver código fonte

{final push for now at 9:19}

Jacqueline Joson 6 anos atrás
pai
commit
e609c574ad

+ 70
- 57
src/main/java/io/zipcoder/casino/cardgames/GoFish.java Ver arquivo

@@ -13,12 +13,7 @@ import java.util.ArrayList;
13 13
 public class GoFish extends CardGame {
14 14
     private static Deck drawPile = new Deck();
15 15
     private ArrayList<GoFishPlayer> goFishPlayers = new ArrayList<>();
16
-
17
-    public void goFish() {
18
-        readyPlayers();
19
-        dealCards(getNumberOfCards());
20
-        runGame();
21
-    }
16
+//    private int numberOfCards;
22 17
 
23 18
     public void readyPlayers() {
24 19
         for (Player player : Players.getInstance().getPlayers()) {
@@ -27,13 +22,15 @@ public class GoFish extends CardGame {
27 22
     }
28 23
 
29 24
     @Override
30
-    public void runGame() {                                 // run the game as longa s the drawPile is more than 0 cards
31
-        for (int i = drawPile.size(); i > 0; i++) {
32
-            playGoFish();
25
+    public void runGame() {                                 // run the game as long as the drawPile is more than 0 cards
26
+        while (drawPile.size() >= 0) {
27
+            for (int j = 0; j < goFishPlayers.size(); j++) {
28
+                playGoFish();
29
+            }
33 30
         }
34 31
     }
35 32
 
36
-    public int getNumberOfCards() {                 //generate numberOfCards param for below based on number of players
33
+    public int getStartingCards() {                 //generate numberOfCards param for below based on number of players
37 34
         int numberOfCards;
38 35
         if (goFishPlayers.size() <= 3) {            //RULES: For 3 players or less, deal each player 7 cards;
39 36
             numberOfCards = 7;
@@ -44,16 +41,18 @@ public class GoFish extends CardGame {
44 41
     }
45 42
 
46 43
     @Override
47
-    public void dealCards(Player player, int numberOfCards) {           //populate the cardHand of players
48
-        GoFishPlayer fishie = (GoFishPlayer) player;                    // depending on how many players
49
-        for (int i = 0; i < numberOfCards; i++) {
50
-            Card card = drawPile.removeFirst();
51
-            fishie.getHand().add(card);
52
-        }
44
+    public void dealCards(Player player, int numberOfCards) {
45
+//        numberOfCards = getStartingCards();
46
+//        GoFishPlayer fishie = (GoFishPlayer) player;                    // depending on how many players
47
+//        for (int i = 0; i < numberOfCards; i++) {
48
+//            Card card = drawPile.removeFirst();
49
+//            fishie.getHand().add(card);
50
+//        }
53 51
     }
54 52
 
55 53
     @Override
56 54
     public void dealCards(int numberOfCards) {
55
+        numberOfCards = getStartingCards();
57 56
         for (GoFishPlayer p : goFishPlayers) {
58 57
             for (int i = 0; i < numberOfCards; i++) {
59 58
                 Card card = drawPile.removeFirst();
@@ -62,17 +61,22 @@ public class GoFish extends CardGame {
62 61
         }
63 62
     }
64 63
 
64
+    public GoFish() {
65
+        readyPlayers();
66
+        dealCards(getStartingCards());
67
+        runGame();
68
+    }
69
+
65 70
     @Override
66 71
     public void promptContinue() {
67
-    }                                      //WHAT?
72
+    }                                     //WHAT??
68 73
 
69 74
 
70 75
     public void playGoFish() {
71
-        for (int i = 0; i < goFishPlayers.size(); i++) {
72
-        askForOpponent();
73
-        searchCard();
74
-        //matchCards();
75
-        }
76
+            askForOpponent();
77
+            searchCard();
78
+            checkCards();
79
+            checkSets();
76 80
     }
77 81
 
78 82
     public String askForOpponent() {
@@ -85,51 +89,60 @@ public class GoFish extends CardGame {
85 89
         return wantedCard;
86 90
     }
87 91
 
88
-    public void matchCards(GoFishPlayer opponent, Integer wantedCard) {
92
+    public void checkCards() {
93
+        String opponent = askForOpponent();
89 94
         GoFishPlayer fishie = new GoFishPlayer();
90 95
         for (int i = 0; i < goFishPlayers.size(); i++) {
91 96
             if (opponent.equals(goFishPlayers.get(i).getName())) {
92
-                for (int j = 0; j < opponent.getHand().size(); j++) {
93
-                    if (wantedCard.equals(opponent.getHand().get(i).getCardValue())) {
94
-                        fishie.getHand().add(opponent.getHand().get(i));
95
-                        opponent.getHand().remove(i);
96
-                    } else fishie.getHand().add(drawPile.removeFirst());
97
+                Console.println(fishie.getName() + " has " + fishie.getHand().display());  //hopefully this prints out
98
+                for (int j = 0; j < goFishPlayers.get(i).getHand().size(); j++) {
99
+                    while (searchCard().equals(goFishPlayers.get(i).getHand().get(j).getCardValue())) {
100
+                        Console.println("Nice job!");
101
+                        fishie.getHand().add(goFishPlayers.get(i).getHand().get(j));
102
+                        goFishPlayers.get(i).getHand().remove(j);
103
+                        askForOpponent();                                   //need this?
104
+                        searchCard();                                       //need this?
105
+                    }
106
+                    fish();
97 107
                 }
98 108
             }
99 109
         }
100 110
     }
101 111
 
102 112
 
113
+    public void fish() {
114
+        GoFishPlayer player = new GoFishPlayer();
115
+        player.getHand().add(drawPile.removeFirst());
116
+        Console.println("Lame. Go Fish loser \"\\uD83D\\uDC1F\"");
103 117
     }
104 118
 
105
-    //take userInput [console input?]
106
-    //askPlayerCard(); Prompt w/question of what card (rank) to look for [console output?]
107
-    //take userInput[console input?]
108
-    //for cardHand(chosen player)
109
-    //evalCards(userInput): If userInput.equals(card[i].cardGetValue)
110
-    //swap();
111
-    //repeat until userInput != cardGetValue
112
-
113
-
114
-    //else
115
-    //goFish(); draw a card from Deck - (deck - 1)
116
-    //move to next player;
117
-    //checkSets: run through each cardHand and looks for 4 of a kind;
118
-    //if found, setsCount++;
119
-
120
-
121
-//       public void evalCards() {
122
-//        //    if for cards in dealerHand:
123
-////        swap cards or go fish
124
-//    }
125
-//
126
-//    public void goFish() {
127
-//        //pull from top of deck
128
-//    }
129
-//
130
-//    public void checkSets() {
131
-//        // check if 4 in dealerHand have same value
132
-//    }
133
-}
119
+
120
+    public void checkSets() {                                               // help. lost. trying to set aside the sets
121
+//        GoFishPlayer player = new GoFishPlayer();
122
+        for (int i = 0; i < goFishPlayers.size(); i++) {
123
+            GoFishPlayer currentPlayer = goFishPlayers.get(i);
124
+            for (int j = 0; j < currentPlayer.getHand().size(); j++) {
125
+                int set = 0;
126
+                for (int k = 1; k < currentPlayer.getHand().size(); k++) {
127
+                    if (currentPlayer.getHand().get(j).getCardValue() == currentPlayer.getHand().get(k).getCardValue()) {
128
+                        set++;
129
+                    }
130
+                }
131
+                if (set>=4) {
132
+                    int setCount = currentPlayer.getSetCount();
133
+                    int newSetCount = setCount += 1;
134
+                    currentPlayer.setSetCount(newSetCount);
135
+                }
136
+//                    setCount.put();
137
+//                }
138
+//                goFishPlayers.get(i).getHand();
139
+//                if (setCount.containsKey(goFishPlayers.get(i).getHand().get().getCardValue())))
140
+            }
141
+            {
142
+
143
+            }
144
+        }
134 145
 
135 146
 
147
+    }
148
+}

+ 10
- 0
src/main/java/io/zipcoder/casino/player/GoFishPlayer.java Ver arquivo

@@ -4,11 +4,21 @@ import io.zipcoder.casino.utilities.containers.CardHand;
4 4
 
5 5
 public class GoFishPlayer extends Player{
6 6
     private CardHand hand;
7
+    int setCount = 0;
8
+
9
+    public int getSetCount() {
10
+        return setCount;
11
+    }
12
+
13
+    public void setSetCount(int setCount) {
14
+        this.setCount = setCount;
15
+    }
7 16
 
8 17
     Player goFishPlayer;
9 18
 
10 19
     public GoFishPlayer(Player player) {
11 20
         this.goFishPlayer = player;
21
+        this.hand = new CardHand();
12 22
     }
13 23
 
14 24
     public GoFishPlayer() {

+ 32
- 22
src/test/java/io/zipcoder/casino/GoFishTest.java Ver arquivo

@@ -1,16 +1,13 @@
1 1
 package io.zipcoder.casino;
2 2
 
3
+import io.zipcoder.casino.player.GoFishPlayer;
4
+import io.zipcoder.casino.player.Player;
5
+import org.junit.Assert;
3 6
 import org.junit.Test;
4 7
 
5
-public class GoFishTest {
6
-    @Test
7
-    public void GoFishTest(){
8
-        //given
8
+import java.util.ArrayList;
9 9
 
10
-        //when
11
-
12
-        //then
13
-    }
10
+public class GoFishTest {
14 11
 
15 12
     @Test
16 13
     public void goFish() {
@@ -22,12 +19,21 @@ public class GoFishTest {
22 19
     }
23 20
 
24 21
     @Test
25
-    public void readyPlayers() {
22
+    public void readyPlayersTest() {
26 23
         //given
27
-
24
+        ArrayList<GoFishPlayer> fishers = new ArrayList<>();
25
+        GoFishPlayer fisher1 = new GoFishPlayer(new Player("Jae", 0));
26
+        GoFishPlayer fisher2 = new GoFishPlayer(new Player("Thuy", 2));
27
+        GoFishPlayer fisher3 = new GoFishPlayer(new Player("Ned", 0));
28
+        int expectedOutput = 3;
28 29
         //when
29
-
30
+        fishers.add(fisher1);
31
+        fishers.add(fisher2);
32
+        fishers.add(fisher3);
30 33
         //then
34
+        int actualOutput = fishers.size();
35
+        Assert.assertEquals(expectedOutput, actualOutput);
36
+
31 37
     }
32 38
 
33 39
     @Test
@@ -40,25 +46,29 @@ public class GoFishTest {
40 46
     }
41 47
 
42 48
     @Test
43
-    public void getNumberOfCards() {
49
+    public void getStartingCardsTest() {
44 50
         //given
51
+        ArrayList<GoFishPlayer> fishers = new ArrayList<>();
52
+        GoFishPlayer fisher1 = new GoFishPlayer(new Player("Jae", 0));
53
+        GoFishPlayer fisher2 = new GoFishPlayer(new Player("Thuy", 2));
54
+        GoFishPlayer fisher3 = new GoFishPlayer(new Player("Ned", 0));
55
+        fishers.add(fisher1);
56
+        fishers.add(fisher2);
57
+        fishers.add(fisher3);
58
+        int expectOutput = 7;
59
+        int numberOfPlayers = fishers.size();
45 60
 
46 61
         //when
47 62
 
48
-        //then
49
-    }
50
-
51
-    @Test
52
-    public void dealCards() {
53
-        //given
54
-
55
-        //when
56 63
 
57 64
         //then
65
+        int actualOutput = fisher1.getHand().size();
66
+        Assert.assertEquals(expectOutput, actualOutput);
67
+
58 68
     }
59 69
 
60 70
     @Test
61
-    public void dealCards1() {
71
+    public void dealCards() {
62 72
         //given
63 73
 
64 74
         //when
@@ -103,7 +113,7 @@ public class GoFishTest {
103 113
     }
104 114
 
105 115
     @Test
106
-    public void matchCards() {
116
+    public void checkCards() {
107 117
         //given
108 118
 
109 119
         //when