添加记牌器功能

This commit is contained in:
yangweihome
2021-12-03 16:46:47 +08:00
parent 03c65f72ae
commit b0fc64efe8
8 changed files with 108 additions and 5 deletions
@@ -28,7 +28,7 @@ public class SimpleClient {
public static String protocol = "pb";
private final static String[] serverAddressSource = new String[]{
"https://raw.githubusercontent.com/ainilili/ratel/master/serverlist.json",
// "https://raw.githubusercontent.com/ainilili/ratel/master/serverlist.json",
"https://gitee.com/ainilili/ratel/raw/master/serverlist.json"
};
@@ -27,6 +27,8 @@ public class ClientEventListener_CODE_GAME_POKER_PLAY extends ClientEventListene
List<Poker> pokers = Noson.convert(map.get("pokers"), new NoType<List<Poker>>() {
});
SimplePrinter.printPokers(pokers);
SimplePrinter.printNotice("Last cards are");
SimplePrinter.printNotice(map.get("lastPokers").toString());
SimplePrinter.printNotice("Please enter the combination you came up with (enter [exit|e] to exit current room, enter [pass|p] to jump current round, enter [view|v] to show all valid combinations.)");
String line = SimpleWriter.write("combination");
@@ -25,6 +25,8 @@ public class ClientEventListener_CODE_GAME_STARTING extends ClientEventListener
SimplePrinter.printNotice("");
SimplePrinter.printNotice("Your cards are");
SimplePrinter.printPokers(pokers);
SimplePrinter.printNotice("Last cards are");
SimplePrinter.printNotice(map.get("lastPokers").toString());
get(ClientEventCode.CODE_GAME_LANDLORD_ELECT).call(channel, data);
}
@@ -0,0 +1,67 @@
package org.nico.ratel.landlords.utils;
import org.nico.ratel.landlords.entity.Poker;
import java.util.*;
public class LastCardsUtils {
public static String getLastCards(List<List<Poker>> pokers){
StringBuffer lastCards = new StringBuffer();
Map<String, Integer> lastCardMap = initLastCards();
for(int i = 0; i < pokers.size(); i++){
List<Poker> pokerList = pokers.get(i);
for(int a = 0; a < pokerList.size(); a++){
Poker poker = pokerList.get(a);
lastCardMap.put(poker.getLevel().getName(),(lastCardMap.get(poker.getLevel().getName())+1));
}
}
List<String> defSort = new ArrayList<>();
initDefSort(defSort);
for(int i = 0; i < defSort.size(); i++){
String key = defSort.get(i);
lastCards.append(key + "["+lastCardMap.get(key)+"] ");
}
return lastCards.toString();
}
private static void initDefSort(List<String> defSort){
defSort.add("3");
defSort.add("4");
defSort.add("5");
defSort.add("6");
defSort.add("7");
defSort.add("8");
defSort.add("9");
defSort.add("10");
defSort.add("J");
defSort.add("Q");
defSort.add("K");
defSort.add("A");
defSort.add("2");
defSort.add("S");
defSort.add("X");
}
private static Map<String, Integer> initLastCards(){
Map<String, Integer> lastCards = new HashMap<>();
lastCards.put("A",0);
lastCards.put("2",0);
lastCards.put("3",0);
lastCards.put("4",0);
lastCards.put("5",0);
lastCards.put("6",0);
lastCards.put("7",0);
lastCards.put("8",0);
lastCards.put("9",0);
lastCards.put("10",0);
lastCards.put("J",0);
lastCards.put("Q",0);
lastCards.put("K",0);
lastCards.put("S",0);
lastCards.put("X",0);
return lastCards;
}
}
@@ -16,6 +16,7 @@ import org.nico.ratel.landlords.helper.PokerHelper;
import org.nico.ratel.landlords.print.SimplePrinter;
import org.nico.ratel.landlords.server.ServerContains;
import org.nico.ratel.landlords.server.robot.RobotEventListener;
import org.nico.ratel.landlords.utils.LastCardsUtils;
public class ServerEventListener_CODE_GAME_POKER_PLAY implements ServerEventListener {
@@ -77,6 +78,14 @@ public class ServerEventListener_CODE_GAME_POKER_PLAY implements ServerEventList
room.setLastPokerShell(currentPokerSell);
room.setCurrentSellClient(next.getId());
List<List<Poker>> lastPokerList = new ArrayList<>();
for(int i = 0; i < room.getClientSideList().size(); i++){
if(room.getClientSideList().get(i).getId() != clientSide.getId()){
lastPokerList.add(room.getClientSideList().get(i).getPokers());
}
}
String lastPokers = LastCardsUtils.getLastCards(lastPokerList);
lastPokerList = new ArrayList<>();
clientSide.getPokers().removeAll(currentPokers);
MapHelper mapHelper = MapHelper.newInstance()
.put("clientId", clientSide.getId())
@@ -84,7 +93,8 @@ public class ServerEventListener_CODE_GAME_POKER_PLAY implements ServerEventList
.put("clientType", clientSide.getType())
.put("pokers", currentPokers)
.put("lastSellClientId", clientSide.getId())
.put("lastSellPokers", currentPokers);
.put("lastSellPokers", currentPokers)
.put("lastPokers",lastPokers);
if (!clientSide.getPokers().isEmpty()) {
mapHelper.put("sellClientNickname", next.getNickname());
@@ -9,10 +9,12 @@ import org.nico.noson.Noson;
import org.nico.noson.util.string.StringUtils;
import org.nico.ratel.landlords.channel.ChannelUtils;
import org.nico.ratel.landlords.entity.ClientSide;
import org.nico.ratel.landlords.entity.Poker;
import org.nico.ratel.landlords.entity.Room;
import org.nico.ratel.landlords.enums.ClientEventCode;
import org.nico.ratel.landlords.helper.MapHelper;
import org.nico.ratel.landlords.server.ServerContains;
import org.nico.ratel.landlords.utils.LastCardsUtils;
public class ServerEventListener_CODE_GAME_POKER_PLAY_REDIRECT implements ServerEventListener{
@@ -37,6 +39,14 @@ public class ServerEventListener_CODE_GAME_POKER_PLAY_REDIRECT implements Server
}
}
List<List<Poker>> lastPokerList = new ArrayList<>();
for(int i = 0; i < room.getClientSideList().size(); i++){
if(room.getClientSideList().get(i).getId() != clientSide.getId()){
lastPokerList.add(room.getClientSideList().get(i).getPokers());
}
}
String lastPokers = LastCardsUtils.getLastCards(lastPokerList);
lastPokerList = new ArrayList<>();
String result = MapHelper.newInstance()
.put("pokers", clientSide.getPokers())
.put("lastSellPokers", datas.get("lastSellPokers"))
@@ -44,6 +54,7 @@ public class ServerEventListener_CODE_GAME_POKER_PLAY_REDIRECT implements Server
.put("clientInfos", clientInfos)
.put("sellClientId", room.getCurrentSellClient())
.put("sellClientNickname", ServerContains.CLIENT_SIDE_MAP.get(room.getCurrentSellClient()).getNickname())
.put("lastPokers",lastPokers)
.json();
ChannelUtils.pushToClient(clientSide.getChannel(), ClientEventCode.CODE_GAME_POKER_PLAY_REDIRECT, result);
@@ -1,5 +1,6 @@
package org.nico.ratel.landlords.server.event;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
@@ -12,6 +13,8 @@ import org.nico.ratel.landlords.helper.MapHelper;
import org.nico.ratel.landlords.helper.PokerHelper;
import org.nico.ratel.landlords.server.ServerContains;
import org.nico.ratel.landlords.server.robot.RobotEventListener;
import org.nico.ratel.landlords.utils.JsonUtils;
import org.nico.ratel.landlords.utils.LastCardsUtils;
public class ServerEventListener_CODE_GAME_STARTING implements ServerEventListener {
@@ -42,11 +45,17 @@ public class ServerEventListener_CODE_GAME_STARTING implements ServerEventListen
// Record the first speaker
room.setFirstSellClient(startGrabClient.getId());
List<List<Poker>> otherPokers = new ArrayList<>();
for (ClientSide client : roomClientList) {
client.setType(ClientType.PEASANT);
client.setStatus(ClientStatus.PLAYING);
for(ClientSide otherClient : roomClientList){
if(otherClient.getId() != client.getId()){
otherPokers.add(otherClient.getPokers());
}
}
String lastCards = LastCardsUtils.getLastCards(otherPokers);
otherPokers = new ArrayList<>();
String result = MapHelper.newInstance()
.put("roomId", room.getId())
.put("roomOwner", room.getRoomOwner())
@@ -54,6 +63,7 @@ public class ServerEventListener_CODE_GAME_STARTING implements ServerEventListen
.put("nextClientNickname", startGrabClient.getNickname())
.put("nextClientId", startGrabClient.getId())
.put("pokers", client.getPokers())
.put("lastPokers",lastCards)
.json();
if (client.getRole() == ClientRole.PLAYER) {
+2 -1
View File
@@ -3,5 +3,6 @@
"47.103.16.48:1024:jsClient[v1.2.7]",
"s2.imlazy.ink:25020:FxCraft[v1.2.6]",
"47.240.60.124:6565:ChenCodeX[v1.2.6]",
"cmi.zerodream.net:1919:ZeroDream[v1.2.2]"
"cmi.zerodream.net:1919:ZeroDream[v1.2.2]",
"106.14.125.226:1024:jipaiqi[v1.3.0]"
]