mirror of
https://github.com/tiennm99/caro.git
synced 2026-08-11 16:24:47 +00:00
添加准备系统 游戏结束后不再自动退出房间
This commit is contained in:
+1
-2
@@ -13,7 +13,6 @@ public class ClientEventListener_CODE_GAME_OVER extends ClientEventListener {
|
||||
public void call(Channel channel, String data) {
|
||||
Map<String, Object> map = MapHelper.parser(data);
|
||||
SimplePrinter.printNotice("\nPlayer " + map.get("winnerNickname") + "[" + map.get("winnerType") + "]" + " won the game");
|
||||
SimplePrinter.printNotice("Game over, friendship first, competition second\n");
|
||||
ClientEventListener_CODE_GAME_READY.gameReady(channel);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ public class ClientEventListener_CODE_GAME_POKER_PLAY extends ClientEventListene
|
||||
List<Poker> lastSellPokers = Noson.convert(lastSellPokersObj, new NoType<List<Poker>>() {
|
||||
});
|
||||
List<PokerSell> sells = PokerHelper.validSells(PokerHelper.checkPokerType(lastSellPokers), pokers);
|
||||
if (sells == null || sells.size() == 0) {
|
||||
if (sells.size() == 0) {
|
||||
SimplePrinter.printNotice("It is a pity that, there is no winning combination...");
|
||||
call(channel, data);
|
||||
return;
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package org.nico.ratel.landlords.client.event;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import org.nico.ratel.landlords.channel.ChannelUtils;
|
||||
import org.nico.ratel.landlords.client.SimpleClient;
|
||||
import org.nico.ratel.landlords.enums.ServerEventCode;
|
||||
import org.nico.ratel.landlords.helper.MapHelper;
|
||||
import org.nico.ratel.landlords.print.SimplePrinter;
|
||||
import org.nico.ratel.landlords.print.SimpleWriter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ClientEventListener_CODE_GAME_READY extends ClientEventListener {
|
||||
@Override
|
||||
public void call(Channel channel, String data) {
|
||||
Map<String, Object> map = MapHelper.parser(data);
|
||||
if (SimpleClient.id == (int) map.get("clientId")) {
|
||||
SimplePrinter.printNotice("you are ready to play game.");
|
||||
return;
|
||||
}
|
||||
SimplePrinter.printNotice(map.get("clientNickName").toString() + " is ready to play game.");
|
||||
}
|
||||
|
||||
static void gameReady(Channel channel) {
|
||||
SimplePrinter.printNotice("\nPress any key to get ready(Press [exit|e] to exit the room)");
|
||||
String line = SimpleWriter.write("notReady");
|
||||
if (line.equals("")) {
|
||||
gameReady(channel);
|
||||
return;
|
||||
}
|
||||
if (line.equalsIgnoreCase("exit") || line.equalsIgnoreCase("e")) {
|
||||
ChannelUtils.pushToServer(channel, ServerEventCode.CODE_CLIENT_EXIT, "");
|
||||
return;
|
||||
}
|
||||
ChannelUtils.pushToServer(channel, ServerEventCode.CODE_GAME_READY, "");
|
||||
}
|
||||
}
|
||||
-1
@@ -135,7 +135,6 @@ public class ClientEventListener_CODE_GAME_WATCH extends ClientEventListener {
|
||||
Map<String, Object> map = MapHelper.parser(rawData.toString());
|
||||
|
||||
printNoticeWithTime("Player [" + map.get("winnerNickname") + "](" + map.get("winnerType") + ") won the game.");
|
||||
quitWatch(channel);
|
||||
}
|
||||
|
||||
private void printKickInfo(Object rawData) {
|
||||
|
||||
+2
@@ -17,6 +17,8 @@ public class ClientEventListener_CODE_ROOM_CREATE_SUCCESS extends ClientEventLis
|
||||
|
||||
SimplePrinter.printNotice("You have created a room with id " + room.getId());
|
||||
SimplePrinter.printNotice("Please wait for other players to join !");
|
||||
|
||||
ClientEventListener_CODE_GAME_READY.gameReady(channel);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
@@ -20,6 +20,7 @@ public class ClientEventListener_CODE_ROOM_JOIN_SUCCESS extends ClientEventListe
|
||||
if (SimpleClient.id == joinClientId) {
|
||||
SimplePrinter.printNotice("You have joined room:" + map.get("roomId") + ". There are " + map.get("roomClientCount") + " players in the room now.");
|
||||
SimplePrinter.printNotice("Please wait for other players to join. The game would start at three players!");
|
||||
ClientEventListener_CODE_GAME_READY.gameReady(channel);
|
||||
} else {
|
||||
SimplePrinter.printNotice(map.get("clientNickname") + " joined room, there are currently " + map.get("roomClientCount") + " in the room.");
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class Room {
|
||||
this.id = id;
|
||||
this.clientSideMap = new ConcurrentSkipListMap<>();
|
||||
this.clientSideList = new LinkedList<>();
|
||||
this.status = RoomStatus.BLANK;
|
||||
this.status = RoomStatus.WAIT;
|
||||
}
|
||||
|
||||
public final long getCreateTime() {
|
||||
|
||||
@@ -62,6 +62,8 @@ public enum ClientEventCode implements Serializable {
|
||||
|
||||
CODE_PVE_DIFFICULTY_NOT_SUPPORT("人机难度不支持"),
|
||||
|
||||
CODE_GAME_READY("准备开始游戏"),
|
||||
|
||||
CODE_GAME_WATCH("观战"),
|
||||
|
||||
CODE_GAME_WATCH_SUCCESSFUL("观战成功");
|
||||
|
||||
@@ -4,7 +4,7 @@ public enum ClientStatus {
|
||||
|
||||
TO_CHOOSE,
|
||||
|
||||
NO_READY,
|
||||
NOT_READY,
|
||||
|
||||
READY,
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ public enum ServerEventCode implements Serializable {
|
||||
|
||||
CODE_GAME_STARTING("游戏开始"),
|
||||
|
||||
CODE_GAME_READY("玩家准备"),
|
||||
|
||||
CODE_GAME_LANDLORD_ELECT("抢地主"),
|
||||
|
||||
CODE_GAME_POKER_PLAY("出牌环节"),
|
||||
|
||||
+2
-2
@@ -101,12 +101,12 @@ public class ServerEventListener_CODE_GAME_POKER_PLAY implements ServerEventList
|
||||
for(ClientSide client: room.getClientSideList()) {
|
||||
if(client.getRole() == ClientRole.PLAYER) {
|
||||
ChannelUtils.pushToClient(client.getChannel(), ClientEventCode.CODE_GAME_OVER, result);
|
||||
client.setStatus(ClientStatus.NOT_READY);
|
||||
}
|
||||
}
|
||||
room.setStatus(RoomStatus.WAIT);
|
||||
|
||||
notifyWatcherGameOver(room, result);
|
||||
|
||||
ServerEventListener.get(ServerEventCode.CODE_CLIENT_EXIT).call(clientSide, data);
|
||||
} else {
|
||||
if(next.getRole() == ClientRole.PLAYER) {
|
||||
ServerEventListener.get(ServerEventCode.CODE_GAME_POKER_PLAY_REDIRECT).call(next, result);
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package org.nico.ratel.landlords.server.event;
|
||||
|
||||
import org.nico.ratel.landlords.channel.ChannelUtils;
|
||||
import org.nico.ratel.landlords.entity.ClientSide;
|
||||
import org.nico.ratel.landlords.entity.Room;
|
||||
import org.nico.ratel.landlords.enums.*;
|
||||
import org.nico.ratel.landlords.helper.MapHelper;
|
||||
import org.nico.ratel.landlords.print.SimplePrinter;
|
||||
import org.nico.ratel.landlords.server.ServerContains;
|
||||
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
|
||||
public class ServerEventListener_CODE_GAME_READY implements ServerEventListener {
|
||||
@Override
|
||||
public void call(ClientSide clientSide, String data) {
|
||||
Room room = ServerContains.getRoom(clientSide.getRoomId());
|
||||
SimplePrinter.serverLog("房间状态:" + room.getStatus());
|
||||
SimplePrinter.serverLog("玩家状态:" + clientSide.getStatus());
|
||||
if (room.getStatus() == RoomStatus.STARTING) {
|
||||
return;
|
||||
}
|
||||
if (clientSide.getStatus() == ClientStatus.PLAYING || clientSide.getStatus() == ClientStatus.TO_CHOOSE || clientSide.getStatus() == ClientStatus.CALL_LANDLORD) {
|
||||
return;
|
||||
}
|
||||
clientSide.setStatus(clientSide.getStatus() == ClientStatus.READY ? ClientStatus.NOT_READY : ClientStatus.READY);
|
||||
String result = MapHelper.newInstance()
|
||||
.put("clientNickName", clientSide.getNickname())
|
||||
.put("status", clientSide.getStatus())
|
||||
.put("clientId", clientSide.getId())
|
||||
.json();
|
||||
boolean allReady = true;
|
||||
ConcurrentSkipListMap<Integer, ClientSide> roomClientMap = (ConcurrentSkipListMap<Integer, ClientSide>) room.getClientSideMap();
|
||||
if (roomClientMap.size() < 3) {
|
||||
allReady = false;
|
||||
} else {
|
||||
for (ClientSide client : room.getClientSideList()) {
|
||||
if (client.getRole() == ClientRole.PLAYER && client.getStatus() != ClientStatus.READY) {
|
||||
allReady = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (ClientSide client : room.getClientSideList()) {
|
||||
if (client.getRole() == ClientRole.PLAYER) {
|
||||
ChannelUtils.pushToClient(client.getChannel(), ClientEventCode.CODE_GAME_READY, result);
|
||||
}
|
||||
}
|
||||
|
||||
if (allReady) {
|
||||
ServerEventListener.get(ServerEventCode.CODE_GAME_STARTING).call(clientSide, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
@@ -43,6 +43,7 @@ public class ServerEventListener_CODE_GAME_STARTING implements ServerEventListen
|
||||
|
||||
for (ClientSide client : roomClientList) {
|
||||
client.setType(ClientType.PEASANT);
|
||||
client.setStatus(ClientStatus.PLAYING);
|
||||
|
||||
String result = MapHelper.newInstance()
|
||||
.put("roomId", room.getId())
|
||||
|
||||
+4
-1
@@ -5,6 +5,7 @@ import org.nico.ratel.landlords.channel.ChannelUtils;
|
||||
import org.nico.ratel.landlords.entity.ClientSide;
|
||||
import org.nico.ratel.landlords.entity.Room;
|
||||
import org.nico.ratel.landlords.enums.ClientEventCode;
|
||||
import org.nico.ratel.landlords.enums.ClientStatus;
|
||||
import org.nico.ratel.landlords.enums.RoomStatus;
|
||||
import org.nico.ratel.landlords.enums.RoomType;
|
||||
import org.nico.ratel.landlords.server.ServerContains;
|
||||
@@ -15,7 +16,7 @@ public class ServerEventListener_CODE_ROOM_CREATE implements ServerEventListener
|
||||
public void call(ClientSide clientSide, String data) {
|
||||
|
||||
Room room = new Room(ServerContains.getServerId());
|
||||
room.setStatus(RoomStatus.BLANK);
|
||||
room.setStatus(RoomStatus.WAIT);
|
||||
room.setType(RoomType.PVP);
|
||||
room.setRoomOwner(clientSide.getNickname());
|
||||
room.getClientSideMap().put(clientSide.getId(), clientSide);
|
||||
@@ -27,6 +28,8 @@ public class ServerEventListener_CODE_ROOM_CREATE implements ServerEventListener
|
||||
clientSide.setRoomId(room.getId());
|
||||
ServerContains.addRoom(room);
|
||||
|
||||
clientSide.setStatus(ClientStatus.NOT_READY);
|
||||
|
||||
ChannelUtils.pushToClient(clientSide.getChannel(), ClientEventCode.CODE_ROOM_CREATE_SUCCESS, Noson.reversal(room));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-4
@@ -9,7 +9,6 @@ import org.nico.ratel.landlords.entity.Room;
|
||||
import org.nico.ratel.landlords.enums.ClientEventCode;
|
||||
import org.nico.ratel.landlords.enums.ClientStatus;
|
||||
import org.nico.ratel.landlords.enums.RoomStatus;
|
||||
import org.nico.ratel.landlords.enums.ServerEventCode;
|
||||
import org.nico.ratel.landlords.helper.MapHelper;
|
||||
import org.nico.ratel.landlords.server.ServerContains;
|
||||
|
||||
@@ -52,12 +51,10 @@ public class ServerEventListener_CODE_ROOM_JOIN implements ServerEventListener {
|
||||
if (roomClientMap.size() == 3) {
|
||||
clientSide.setNext(roomClientList.getFirst());
|
||||
roomClientList.getFirst().setPre(clientSide);
|
||||
ServerEventListener.get(ServerEventCode.CODE_GAME_STARTING).call(clientSide, String.valueOf(room.getId()));
|
||||
return;
|
||||
}
|
||||
|
||||
room.setStatus(RoomStatus.WAIT);
|
||||
|
||||
clientSide.setStatus(ClientStatus.NOT_READY);
|
||||
String result = MapHelper.newInstance()
|
||||
.put("clientId", clientSide.getId())
|
||||
.put("clientNickname", clientSide.getNickname())
|
||||
|
||||
Reference in New Issue
Block a user