|
@@ -1,10 +1,15 @@
|
|
|
package com.incubator.game.room;
|
|
|
|
|
|
import com.incubator.common.log4j.Log4jUtil;
|
|
|
+import com.incubator.core.net.ws.Message;
|
|
|
import com.incubator.game.data.model.RoomPO;
|
|
|
import com.incubator.game.player.Player;
|
|
|
+import com.incubator.game.util.MsgUtil;
|
|
|
+import com.incubator.message.proto.CommonProto;
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.concurrent.Executors;
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -62,4 +67,68 @@ public class Room {
|
|
|
this.scheduler.shutdownNow();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检测是否可以开始 3秒倒计时开始
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean checkReadyStart() {
|
|
|
+ if (!this.isStart() || this.data.state != 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 广播3秒倒计时
|
|
|
+ for (Player tmPlayer : this.data.playerMap.values()) {
|
|
|
+ if (tmPlayer != null) {
|
|
|
+ Message msg = new Message();
|
|
|
+ msg.setCmd(CommonProto.Cmd.GameStateChange_VALUE);
|
|
|
+ Map<String, Object> data = MsgUtil.roomToMessage(this, tmPlayer, null);
|
|
|
+ data.put("time", 3);
|
|
|
+ msg.setData(data);
|
|
|
+ tmPlayer.receive(msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否玩家都已准备,可开始
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean isStart() {
|
|
|
+ int cnt = 0;
|
|
|
+ for (Player player : this.data.playerMap.values()) {
|
|
|
+ if (player != null && player.data.state == 1) {
|
|
|
+ cnt += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return cnt >= this.data.maxNum;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 游戏开局
|
|
|
+ */
|
|
|
+ public void doStart() {
|
|
|
+ this.data.curRound += 1;
|
|
|
+ // 定庄
|
|
|
+ this.data.zhuangPos = 0;
|
|
|
+ // 设置当前操作玩家
|
|
|
+
|
|
|
+ // 发牌
|
|
|
+
|
|
|
+ // 广播
|
|
|
+ for (Player tmPlayer : this.data.playerMap.values()) {
|
|
|
+ if (tmPlayer != null) {
|
|
|
+ Message msg = new Message();
|
|
|
+ msg.setCmd(CommonProto.Cmd.GameStateChange_VALUE);
|
|
|
+ Map<String, Object> data = MsgUtil.roomToMessage(this, tmPlayer, null);
|
|
|
+ data.put("time", 20);
|
|
|
+ msg.setData(data);
|
|
|
+ tmPlayer.receive(msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|