Skip to content

Commit

Permalink
Merge pull request #79 from woshidijia/master
Browse files Browse the repository at this point in the history
添加记牌器
  • Loading branch information
ainilili committed Dec 8, 2021
2 parents bb37c56 + d6fe593 commit 45c9877
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public void call(Channel channel, String data) {
List<Poker> pokers = Noson.convert(map.get("pokers"), new NoType<List<Poker>>() {
});
SimplePrinter.printPokers(pokers);
SimplePrinter.printNotice("Last cards are");
SimplePrinter.printNotice(map.containsKey("lastPokers")?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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public void call(Channel channel, String data) {
SimplePrinter.printNotice("");
SimplePrinter.printNotice("Your cards are");
SimplePrinter.printPokers(pokers);
SimplePrinter.printNotice("Last cards are");
SimplePrinter.printNotice(map.containsKey("lastPokers")?map.get("lastPokers").toString():"");

get(ClientEventCode.CODE_GAME_LANDLORD_ELECT).call(channel, data);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.nico.ratel.landlords.utils;

import org.nico.ratel.landlords.entity.Poker;

import java.util.*;

public class LastCardsUtils {

private static final List<String> defSort = new ArrayList(){{
add("3");
add("4");
add("5");
add("6");
add("7");
add("8");
add("9");
add("10");
add("J");
add("Q");
add("K");
add("A");
add("2");
add("S");
add("X");
}};

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));
}
}
for(int i = 0; i < defSort.size(); i++){
String key = defSort.get(i);
lastCards.append(key + "["+lastCardMap.get(key)+"] ");
}

return lastCards.toString();
}


private static Map<String, Integer> initLastCards(){
Map<String, Integer> lastCardMap = new HashMap<>();
lastCardMap.put("A",0);
lastCardMap.put("2",0);
lastCardMap.put("3",0);
lastCardMap.put("4",0);
lastCardMap.put("5",0);
lastCardMap.put("6",0);
lastCardMap.put("7",0);
lastCardMap.put("8",0);
lastCardMap.put("9",0);
lastCardMap.put("10",0);
lastCardMap.put("J",0);
lastCardMap.put("Q",0);
lastCardMap.put("K",0);
lastCardMap.put("S",0);
lastCardMap.put("X",0);
return lastCardMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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 {

Expand Down Expand Up @@ -77,14 +78,23 @@ public void call(ClientSide clientSide, String data) {
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())
.put("clientNickname", clientSide.getNickname())
.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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
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{

Expand All @@ -37,13 +39,22 @@ public void call(ClientSide clientSide, String data) {
}
}

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"))
.put("lastSellClientId", datas.get("lastSellClientId"))
.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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.nico.ratel.landlords.server.event;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

Expand All @@ -12,6 +13,8 @@
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 {

Expand Down Expand Up @@ -42,18 +45,25 @@ public void call(ClientSide clientSide, String data) {

// 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())
.put("roomClientCount", room.getClientSideList().size())
.put("nextClientNickname", startGrabClient.getNickname())
.put("nextClientId", startGrabClient.getId())
.put("pokers", client.getPokers())
.put("lastPokers",lastCards)
.json();

if (client.getRole() == ClientRole.PLAYER) {
Expand Down
3 changes: 2 additions & 1 deletion serverlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
]

0 comments on commit 45c9877

Please sign in to comment.