Bläddra i källkod

优化复式掼蛋打同一幅牌

johnclot69 2 månader sedan
förälder
incheckning
c3caa357ae

+ 55 - 2
incubator-game/src/main/java/com/incubator/game/room/FSGDRoom.java

@@ -5,6 +5,7 @@ import com.incubator.common.log4j.Log;
 import com.incubator.common.util.RandomUtil;
 import com.incubator.game.data.po.RoomPO;
 import com.incubator.game.player.Player;
+import com.incubator.game.util.CardUtils;
 import com.incubator.game.util.FSGDUtil;
 import com.incubator.game.util.GDUtils;
 import com.incubator.game.util.Struct;
@@ -20,6 +21,8 @@ public class FSGDRoom extends Room {
 
     /** 复式掼蛋桌子 **/
     public Map<Integer, FSGDTable> tableMap;
+    /** 复式掼蛋 座位上的牌 **/
+    public Map<Integer, int[]> cardMap;
 
     public FSGDRoom() {}
 
@@ -48,6 +51,13 @@ public class FSGDRoom extends Room {
             table.init(jsonData);
             this.tableMap.put(i, table);
         }
+        // 初始化牌库
+        this.initCardList();
+        // 初始化座位上的牌
+        this.cardMap = new HashMap<>();
+        for (int i = 0; i < 4; i++) {
+            this.cardMap.put(i, new int[]{});
+        }
     }
 
     /**
@@ -140,6 +150,27 @@ public class FSGDRoom extends Room {
         }
     }
 
+    /**
+     * 给玩家发牌,每人27张
+     */
+    @Override
+    public synchronized void doSendCard() {
+        // 发牌
+        for (int i = 0; i < 4; i++) {
+            int[] remainCards = this.cardMap.getOrDefault(i, new int[]{});
+            for (int k = 0; k < 27; k++) {
+                int card = this.data.cardList.get(0);
+                // 设置当前赖子
+                if (GDUtils.isWildCard(card, this.data.curLevelPoint)) {
+                    this.data.wildCard = card;
+                }
+                remainCards = CardUtils.add(remainCards, card);
+                this.data.cardList.remove(0);
+            }
+            this.cardMap.put(i, remainCards);
+        }
+    }
+
     /**
      * 主线程逻辑
      */
@@ -189,7 +220,10 @@ public class FSGDRoom extends Room {
                 case 2:
                     // 进行中
                     if (!this.flag) {
-                        Log.debug("检测2桌是否结束...");
+                        if (this.checkAllOver()) {
+                            this.settlement();
+                            this.gameOver();
+                        }
                     }
                     break;
                 case 3:
@@ -274,6 +308,10 @@ public class FSGDRoom extends Room {
     public synchronized void doStart() {
         lock.lock();
         try {
+            this.data.curRound += 1;
+            // 发牌
+            this.doSendCard();
+
             for (FSGDTable table : this.tableMap.values()) {
                 if (table != null && !table.actors.isEmpty()) {
                     // 开启定时任务
@@ -288,6 +326,21 @@ public class FSGDRoom extends Room {
         }
     }
 
+    /**
+     * 检测所有桌子是否已结束
+     *
+     * @return
+     */
+    public synchronized boolean checkAllOver() {
+        int cnt = 0;
+        for (FSGDTable table : this.tableMap.values()) {
+            if (table != null && table.state == 3) {
+                cnt += 1;
+            }
+        }
+        return cnt >= this.tableMap.size();
+    }
+
     /**
      * 玩家出牌
      *
@@ -449,7 +502,7 @@ public class FSGDRoom extends Room {
      */
     private synchronized void gameOver() {
         this.state = 3;
-        this.time = 60;
+        this.time = 0;
         this.flag = false;
         Log.debug("牌局结束...roomId : {}", this.data.roomId);
     }

+ 23 - 26
incubator-game/src/main/java/com/incubator/game/room/FSGDTable.java

@@ -196,14 +196,9 @@ public class FSGDTable {
                     }
                 }
                 // 发牌
-                for (int i = 0; i < 27; i++) {
-                    int card = this.data.cardList.get(0);
-                    // 设置当前赖子
-                    if (GDUtils.isWildCard(card, this.data.curLevelPoint)) {
-                        this.data.wildCard = card;
-                    }
-                    player.data.remainCards = CardUtils.add(player.data.remainCards, card);
-                    this.data.cardList.remove(0);
+                int[] remainCards = this.room.cardMap.getOrDefault(player.data.pos, new int[]{});
+                if (remainCards != null && remainCards.length > 0) {
+                    player.data.remainCards = remainCards;
                 }
             }
         }
@@ -290,24 +285,26 @@ public class FSGDTable {
                         this.time = 0;
                         Log.debug("游戏结束: 房间号 : {}, 房间人数 : {}, 当前局数 : {}", this.room.data.roomId, this.actors.size(), this.data.curRound);
                     } else {
-                        // 小于最大局数,切等待状态
-                        if (this.data.curRound < this.data.maxRound) {
-                            this.resetNextRoom();
-                            this.state = 0;
-                            this.flag = false;
-                            this.time = 0;
-                        } else {
-                            // 120秒未开始直接解散
-//                            if (this.time >= 120 && this.type != 1) {
-//                                // 广播
-//                                for (Player tmPlayer : this.actors.values()) {
-//                                    if (tmPlayer != null) {
-//                                        tmPlayer.receive(CommonProto.Cmd.DisbandRoom_VALUE, new HashMap<>());
-//                                    }
-//                                }
-//                                this.destroy();
-//                            }
-                        }
+                        // 等待另一桌结束
+
+//                        // 小于最大局数,切等待状态
+//                        if (this.data.curRound < this.data.maxRound) {
+//                            this.resetNextRoom();
+//                            this.state = 0;
+//                            this.flag = false;
+//                            this.time = 0;
+//                        } else {
+//                            // 120秒未开始直接解散
+////                            if (this.time >= 120 && this.type != 1) {
+////                                // 广播
+////                                for (Player tmPlayer : this.actors.values()) {
+////                                    if (tmPlayer != null) {
+////                                        tmPlayer.receive(CommonProto.Cmd.DisbandRoom_VALUE, new HashMap<>());
+////                                    }
+////                                }
+////                                this.destroy();
+////                            }
+//                        }
                     }
                     break;
             }