소스 검색

Merge branch 'Working' of jaejoson/ZCW-OOP-Casino into Working

nedredmond 6 년 전
부모
커밋
d3e39fe681

+ 111
- 63
src/main/java/io/zipcoder/casino/cardgames/GoFish.java 파일 보기

@@ -1,31 +1,19 @@
1 1
 package io.zipcoder.casino.cardgames;
2 2
 
3
-import io.zipcoder.casino.utilities.abstracts.CardGame;
4
-import io.zipcoder.casino.utilities.containers.Deck;
5 3
 import io.zipcoder.casino.player.GoFishPlayer;
6 4
 import io.zipcoder.casino.player.Player;
7 5
 import io.zipcoder.casino.player.Players;
6
+import io.zipcoder.casino.utilities.Card;
7
+import io.zipcoder.casino.utilities.Console;
8
+import io.zipcoder.casino.utilities.abstracts.CardGame;
9
+import io.zipcoder.casino.utilities.containers.Deck;
8 10
 
9 11
 import java.util.ArrayList;
10 12
 
11 13
 public class GoFish extends CardGame {
12 14
     private static Deck drawPile = new Deck();
13
-    // Change Deck to deque;
14 15
     private ArrayList<GoFishPlayer> goFishPlayers = new ArrayList<>();
15
-
16
-    public static void main(String[] args) {
17
-        System.out.println();
18
-    }
19
-
20
-    public GoFish() {
21
-        readyPlayers();
22
-        runGame();
23
-    }
24
-
25
-    @Override
26
-    public void runGame(){
27
-
28
-    }
16
+//    private int numberOfCards;
29 17
 
30 18
     public void readyPlayers() {
31 19
         for (Player player : Players.getInstance().getPlayers()) {
@@ -33,11 +21,20 @@ public class GoFish extends CardGame {
33 21
         }
34 22
     }
35 23
 
36
-    public int getNumberOfCards() {      //generate numberOfCards param for below based on number of players
24
+    @Override
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
+            }
30
+        }
31
+    }
32
+
33
+    public int getStartingCards() {                 //generate numberOfCards param for below based on number of players
37 34
         int numberOfCards;
38
-        if (goFishPlayers.size() <= 3) {  //RULES: For 3 players or less, deal each player 7 cards;
35
+        if (goFishPlayers.size() <= 3) {            //RULES: For 3 players or less, deal each player 7 cards;
39 36
             numberOfCards = 7;
40
-        } else {                           //RULES contd: if more than three players, deal 5 cards each.
37
+        } else {                                    //RULES contd: if more than three players, deal 5 cards each.
41 38
             numberOfCards = 5;
42 39
         }
43 40
         return numberOfCards;
@@ -45,56 +42,107 @@ public class GoFish extends CardGame {
45 42
 
46 43
     @Override
47 44
     public void dealCards(Player player, int numberOfCards) {
48
-        // dealPile = dealPile - 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
+//        }
49 51
     }
50 52
 
51 53
     @Override
52 54
     public void dealCards(int numberOfCards) {
55
+        numberOfCards = getStartingCards();
56
+        for (GoFishPlayer p : goFishPlayers) {
57
+            for (int i = 0; i < numberOfCards; i++) {
58
+                Card card = drawPile.removeFirst();
59
+                p.getHand().add(card);
60
+            }
61
+        }
62
+    }
53 63
 
64
+    public GoFish() {
65
+        readyPlayers();
66
+        dealCards(getStartingCards());
67
+        runGame();
54 68
     }
55 69
 
56 70
     @Override
57
-    public void promptContinue(){};
58
-    //
59
-    public void updateDrawPile() {
60
-
61
-//    public void play() {
62
-//        for (int i = 0; i }
63
-
64
-//    int setsCount;
65
-
66
-
67
-        //while (drawPile > 0) {
68
-        //public void questionPlayer(String cardRank, Player player) {
69
-        //start w/ player
70
-        //for (deck.size aka (52 cards - numOfCards per player))
71
-        //askPlayerQuestion(); Prompt w/ question of who to ask [console output?]
72
-        //take userInput [console input?]
73
-        //askPlayerCard(); Prompt w/question of what card (rank) to look for [console output?]
74
-        //take userInput[console input?]
75
-        //for cardHand(chosen player)
76
-        //evalCards(userInput): If userInput.equals(card[i].cardGetValue)
77
-        //swap();
78
-        //repeat until userInput != cardGetValue
79
-        //else
80
-        //goFish(); draw a card from Deck - (deck - 1)
81
-        //move to next player;
82
-        //checkSets: run through each cardHand and looks for 4 of a kind;
83
-        //if found, setsCount++;
84
-
85
-
86
-//    public void evalCards() {
87
-//        //for cards in dealerHand:
88
-////        swap cards or go fish
89
-//    }
90
-//
91
-//    public void goFish() {
92
-//        //pull from top of deck
93
-//    }
94
-//
95
-//    public void checkSets() {
96
-//        // check if 4 in dealerHand have same value
97
-//    }
71
+    public void promptContinue() {
72
+    }                                     //WHAT??
73
+
74
+
75
+    public void playGoFish() {
76
+            askForOpponent();
77
+            searchCard();
78
+            checkCards();
79
+            checkSets();
80
+    }
81
+
82
+    public String askForOpponent() {
83
+        String opponent = Console.getStringInput("Which player would you like to question?");
84
+        return opponent;
85
+    }
86
+
87
+    public Integer searchCard() {
88
+        Integer wantedCard = Console.getIntegerInput("Which card would you like to request?");
89
+        return wantedCard;
90
+    }
91
+
92
+    public void checkCards() {
93
+        String opponent = askForOpponent();
94
+        GoFishPlayer fishie = new GoFishPlayer();
95
+        for (int i = 0; i < goFishPlayers.size(); i++) {
96
+            if (opponent.equals(goFishPlayers.get(i).getName())) {
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();
107
+                }
108
+            }
109
+        }
110
+    }
111
+
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\"");
117
+    }
118
+
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
+        }
145
+
98 146
 
99 147
     }
100
-}
148
+}

+ 14
- 0
src/main/java/io/zipcoder/casino/player/GoFishPlayer.java 파일 보기

@@ -4,11 +4,25 @@ 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();
22
+    }
23
+
24
+    public GoFishPlayer() {
25
+
12 26
     }
13 27
 
14 28
     public Player getP() {

+ 1
- 2
src/main/java/io/zipcoder/casino/utilities/Console.java 파일 보기

@@ -2,7 +2,6 @@ package io.zipcoder.casino.utilities;
2 2
 
3 3
 import io.zipcoder.casino.Casino;
4 4
 
5
-import java.awt.peer.SystemTrayPeer;
6 5
 import java.util.Scanner;
7 6
 
8 7
 public class Console {
@@ -114,7 +113,7 @@ public class Console {
114 113
         String userInput = scanner.nextLine();
115 114
         return userInput;
116 115
       }
117
-     public Integer getIntegerInput(String prompt){
116
+     public static Integer getIntegerInput(String prompt){
118 117
          Scanner scanner = new Scanner(System.in);
119 118
          println(prompt);
120 119
          int userInput = scanner.nextInt();

+ 0
- 3
src/main/java/io/zipcoder/casino/utilities/containers/CardHand.java 파일 보기

@@ -8,7 +8,6 @@ public class CardHand extends ArrayList<Card> {
8 8
 
9 9
     int numberOfCards = this.size();
10 10
 //    private java.util.ArrayList<Card> cardHand;
11
-//
12 11
 //    public CardHand(int numberOfCards) {
13 12
 //        this.numberOfCards = numberOfCards;
14 13
 //    }
@@ -20,10 +19,8 @@ public class CardHand extends ArrayList<Card> {
20 19
 //    public void addCard(Card card) {
21 20
 //        add(card);
22 21
 //    }
23
-//
24 22
 //    public void removeCard(Card card) {
25 23
 //        remove(card);
26
-//
27 24
 //    }
28 25
 
29 26
     public String display() {

+ 123
- 0
src/test/java/io/zipcoder/casino/GoFishTest.java 파일 보기

@@ -0,0 +1,123 @@
1
+package io.zipcoder.casino;
2
+
3
+import io.zipcoder.casino.player.GoFishPlayer;
4
+import io.zipcoder.casino.player.Player;
5
+import org.junit.Assert;
6
+import org.junit.Test;
7
+
8
+import java.util.ArrayList;
9
+
10
+public class GoFishTest {
11
+
12
+    @Test
13
+    public void goFish() {
14
+        //given
15
+
16
+        //when
17
+
18
+        //then
19
+    }
20
+
21
+    @Test
22
+    public void readyPlayersTest() {
23
+        //given
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;
29
+        //when
30
+        fishers.add(fisher1);
31
+        fishers.add(fisher2);
32
+        fishers.add(fisher3);
33
+        //then
34
+        int actualOutput = fishers.size();
35
+        Assert.assertEquals(expectedOutput, actualOutput);
36
+
37
+    }
38
+
39
+    @Test
40
+    public void runGame() {
41
+        //given
42
+
43
+        //when
44
+
45
+        //then
46
+    }
47
+
48
+    @Test
49
+    public void getStartingCardsTest() {
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();
60
+
61
+        //when
62
+
63
+
64
+        //then
65
+        int actualOutput = fisher1.getHand().size();
66
+        Assert.assertEquals(expectOutput, actualOutput);
67
+
68
+    }
69
+
70
+    @Test
71
+    public void dealCards() {
72
+        //given
73
+
74
+        //when
75
+
76
+        //then
77
+    }
78
+
79
+    @Test
80
+    public void promptContinue() {
81
+        //given
82
+
83
+        //when
84
+
85
+        //then
86
+    }
87
+
88
+    @Test
89
+    public void playGoFish() {
90
+        //given
91
+
92
+        //when
93
+
94
+        //then
95
+    }
96
+
97
+    @Test
98
+    public void askForOpponent() {
99
+        //given
100
+
101
+        //when
102
+
103
+        //then
104
+    }
105
+
106
+    @Test
107
+    public void searchCard() {
108
+        //given
109
+
110
+        //when
111
+
112
+        //then
113
+    }
114
+
115
+    @Test
116
+    public void checkCards() {
117
+        //given
118
+
119
+        //when
120
+
121
+        //then
122
+    }
123
+}