Merge pull request #18 from abbychau/dev-1.1.0

Dev 1.1.0
This commit is contained in:
Nico
2018-11-15 13:24:50 +08:00
committed by GitHub
12 changed files with 57 additions and 32 deletions
@@ -50,9 +50,11 @@ public class SimpleClient {
for(int i = 0; i < serverAddressList.size(); i++) {
SimplePrinter.printNotice((i+1) + ". " + serverAddressList.get(i));
}
int serverPick = Integer.parseInt(SimpleWriter.write("option"));
int serverPick = 0;
while(serverPick<1 || serverPick>serverAddressList.size()){
SimplePrinter.printNotice("Invalid Option");
try {
serverPick = Integer.parseInt(SimpleWriter.write("option"));
}catch(NumberFormatException e){}
}
serverAddress = serverAddressList.get(serverPick-1);
String[] elements = serverAddress.split(":");
@@ -5,7 +5,6 @@ import java.util.Map;
import org.nico.noson.Noson;
import org.nico.noson.entity.NoType;
import org.nico.ratel.landlords.client.SimpleClient;
import org.nico.ratel.landlords.entity.Poker;
import org.nico.ratel.landlords.enums.ServerEventCode;
import org.nico.ratel.landlords.helper.MapHelper;
@@ -13,20 +13,11 @@ public class ClientEventListener_CODE_SHOW_OPTIONS_SETTING extends ClientEventLi
@Override
public void call(Channel channel, String data) {
SimplePrinter.printNotice("Setting: ");
/*
case 0:
return buildHandStringSharp(pokers);
case 1:
return buildHandStringRounded(pokers);
case 2:
return textOnly(pokers);
case 3:
return textOnlyNoType(pokers);
*/
SimplePrinter.printNotice("1. Card with shape edges (Default)");
SimplePrinter.printNotice("2. Card with rounded edges");
SimplePrinter.printNotice("3. Text Only with types");
SimplePrinter.printNotice("4. Text Only without types");
SimplePrinter.printNotice("5. Unicode Cards");
SimplePrinter.printNotice("Please enter the number of setting (enter [BACK] return options list)");
String line = SimpleWriter.write("setting");
@@ -40,7 +31,7 @@ public class ClientEventListener_CODE_SHOW_OPTIONS_SETTING extends ClientEventLi
}
int choose = Integer.valueOf(line);
if(choose > 0 && choose <= 4){
if(choose >=1 && choose <= PokerHelper.totalPrinters){
PokerHelper.pokerPrinterType = choose - 1;
get(ClientEventCode.CODE_SHOW_OPTIONS).call(channel, data);
} else {
@@ -2,12 +2,9 @@ package org.nico.ratel.landlords.client.event;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentSkipListMap;
import org.nico.noson.Noson;
import org.nico.noson.entity.NoType;
import org.nico.ratel.landlords.entity.Room;
import org.nico.ratel.landlords.enums.ClientEventCode;
import org.nico.ratel.landlords.print.SimplePrinter;
@@ -1,7 +1,5 @@
package org.nico.ratel.landlords.enums;
import java.io.Serializable;
public enum SellType {
ILLEGAL("非合法"),
@@ -5,6 +5,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import org.nico.ratel.landlords.entity.Poker;
import org.nico.ratel.landlords.entity.PokerSell;
@@ -18,6 +19,7 @@ public class PokerHelper {
* Print the type of poker style
*/
public static int pokerPrinterType = 0;
public static int totalPrinters = 5;
/**
* The list of all pokers, by 54
@@ -273,6 +275,8 @@ public class PokerHelper {
return textOnly(pokers);
case 3:
return textOnlyNoType(pokers);
case 4:
return playingCardUnicode(pokers);
default:
return buildHandStringSharp(pokers);
@@ -359,13 +363,44 @@ public class PokerHelper {
if(pokers != null && pokers.size() > 0) {
for(int index = 0; index < pokers.size(); index ++) {
String name = pokers.get(index).getLevel().getName();
String type = pokers.get(index).getType().getName();
builder.append(name + type);
builder.append(name+" ");
}
builder.append(System.lineSeparator());
for(int index = 0; index < pokers.size(); index ++) {
String type = pokers.get(index).getType().getName();
builder.append(type+" ".repeat(pokers.get(index).getLevel().getName().length()));
}
}
return builder.toString();
}
private static String playingCardUnicode(List<Poker> pokers){
return pokers.stream().map(
elt -> {
int level = elt.getLevel().getLevel();
if (level == 16){//s
return String.valueOf(Character.toChars(0x1F0DF));
}
if (level == 17){//x
return String.valueOf(Character.toChars(0x1F0CF));
}
if (level == 14 || level == 15){level = level - 13;}
level--;
switch (elt.getType()) {
case SPADE:
return String.valueOf(Character.toChars(0x1F0A1 + level));
case HEART:
return String.valueOf(Character.toChars(0x1F0B1 + level));
case DIAMOND:
return String.valueOf(Character.toChars(0x1F0C1 + level));
case CLUB:
return String.valueOf(Character.toChars(0x1F0D1 + level));
default:
return "";
}
}
).collect(Collectors.joining(""));
}
private static String textOnlyNoType(List<Poker> pokers){
StringBuilder builder = new StringBuilder();
if(pokers != null && pokers.size() > 0) {
@@ -1,5 +1,6 @@
package org.nico.ratel.landlords.server.event;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
@@ -22,7 +23,11 @@ public interface ServerEventListener {
}else{
String eventListener = LISTENER_PREFIX + code.name();
Class<ServerEventListener> listenerClass = (Class<ServerEventListener>) Class.forName(eventListener);
listener = listenerClass.newInstance();
try {
listener = listenerClass.getDeclaredConstructor().newInstance();
} catch (InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}
ServerEventListener.LISTENER_MAP.put(code, listener);
}
return listener;
@@ -1,8 +1,5 @@
package org.nico.ratel.landlords.server.event;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.nico.ratel.landlords.channel.ChannelUtils;
import org.nico.ratel.landlords.entity.ClientSide;
@@ -10,7 +7,6 @@ import org.nico.ratel.landlords.entity.Room;
import org.nico.ratel.landlords.enums.ClientEventCode;
import org.nico.ratel.landlords.enums.ClientRole;
import org.nico.ratel.landlords.enums.ClientType;
import org.nico.ratel.landlords.enums.RoomType;
import org.nico.ratel.landlords.enums.ServerEventCode;
import org.nico.ratel.landlords.helper.MapHelper;
import org.nico.ratel.landlords.helper.PokerHelper;
@@ -9,7 +9,6 @@ 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.helper.MapHelper;
import org.nico.ratel.landlords.helper.PokerHelper;
import org.nico.ratel.landlords.server.ServerContains;
public class ServerEventListener_CODE_GAME_POKER_PLAY_REDIRECT implements ServerEventListener{
@@ -11,7 +11,6 @@ import org.nico.ratel.landlords.enums.ClientEventCode;
import org.nico.ratel.landlords.enums.ClientRole;
import org.nico.ratel.landlords.enums.ClientType;
import org.nico.ratel.landlords.enums.RoomStatus;
import org.nico.ratel.landlords.enums.RoomType;
import org.nico.ratel.landlords.helper.MapHelper;
import org.nico.ratel.landlords.helper.PokerHelper;
import org.nico.ratel.landlords.server.ServerContains;
@@ -3,7 +3,6 @@ package org.nico.ratel.landlords.server.event;
import java.util.LinkedList;
import java.util.concurrent.ConcurrentSkipListMap;
import org.nico.noson.Noson;
import org.nico.ratel.landlords.channel.ChannelUtils;
import org.nico.ratel.landlords.entity.ClientSide;
import org.nico.ratel.landlords.entity.Room;
@@ -1,5 +1,6 @@
package org.nico.ratel.landlords.server.robot;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
@@ -13,7 +14,7 @@ public interface RobotEventListener {
public final static Map<ClientEventCode, RobotEventListener> LISTENER_MAP = new HashMap<>();
public void call(ClientSide robot, String data);
public static RobotEventListener get(ClientEventCode code) {
RobotEventListener listener = null;
try {
@@ -22,7 +23,11 @@ public interface RobotEventListener {
}else{
String eventListener = LISTENER_PREFIX + code.name();
Class<RobotEventListener> listenerClass = (Class<RobotEventListener>) Class.forName(eventListener);
listener = listenerClass.newInstance();
try {
listener = listenerClass.getDeclaredConstructor().newInstance();
} catch (NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
}
RobotEventListener.LISTENER_MAP.put(code, listener);
}
return listener;