Skip to content

Commit

Permalink
sequel
Browse files Browse the repository at this point in the history
  • Loading branch information
Kloping committed Mar 15, 2022
1 parent 161d9f2 commit 46d2f08
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 43 deletions.
24 changes: 13 additions & 11 deletions src/main/java/com/hrs/kloping/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

/**
* @author github-kloping
*/
public class Command {
public static boolean isStarted = false;
public static boolean isCreated = false;
Expand All @@ -35,19 +38,18 @@ public static synchronized void exec(String text, long qq, Group group) {
break;
case "不抢":
case "不抢地主":
if (table != null)
result = table.noRob(qq);
if (table != null) result = table.noRob(qq);
break;
case "结束游戏":
if (isCreated && !isStarted)
destroy();
if (isCreated && !isStarted) destroy();
else tipsCantClose(group);
break;
case "强制结束游戏":
if (qq == HPlugin_Landlord.youQQ)
destroy();
if (qq == HPluginLandlord.youQQ) destroy();
else tipsCantClose(group);
break;
default:
break;
}
if (result != null)
group.sendMessage(result.toString());
Expand Down Expand Up @@ -75,21 +77,21 @@ public static synchronized String joinGame(long qq) {
} else return "游戏未创建或已开启";
}

public static final Map<Long, List<Card>> listImageMap = new ConcurrentHashMap<>();
public static final Map<Long, List<Card>> LIST_IMAGE_MAP = new ConcurrentHashMap<>();
public static Table table;

public static synchronized String InitTable(Group group) {
if (!isCreated) {
isCreated = true;
HPlugin_Landlord.threads.execute(() -> {
if (listImageMap.containsKey(group.getId())) {
table = new Table(group, listImageMap.get(group.getId()));
HPluginLandlord.threads.execute(() -> {
if (LIST_IMAGE_MAP.containsKey(group.getId())) {
table = new Table(group, LIST_IMAGE_MAP.get(group.getId()));
} else {
List<Card> map = new CopyOnWriteArrayList<>();
for (Card card : OCardSet.getCards()) {
map.add(card);
}
listImageMap.put(group.getId(), map);
LIST_IMAGE_MAP.put(group.getId(), map);
table = new Table(group, map);
}
group.sendMessage("创建完成!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
* @Date 21/9/14
* <p>
*/
public final class HPlugin_Landlord extends JavaPlugin {
public static final HPlugin_Landlord INSTANCE = new HPlugin_Landlord();
public final class HPluginLandlord extends JavaPlugin {
public static final HPluginLandlord INSTANCE = new HPluginLandlord();
/**
* 换成你的QQ 用来强制关闭游戏
*/
public static final Long youQQ = Utils.init("#这里写上你的QQ 用来强制关闭游戏", "host", 3474006766L, Long.class);

public static final ExecutorService threads = Executors.newFixedThreadPool(10);

private HPlugin_Landlord() {
super(new JvmPluginDescriptionBuilder("com.hrs.kloping.h_plugin_Landlord", "2.6-sequel")
private HPluginLandlord() {
super(new JvmPluginDescriptionBuilder("com.hrs.kloping.h_plugin_Landlord", "2.7-sequel")
.name("LandlordGame")
.info("斗地主游戏")
.author("HRS")
Expand Down
73 changes: 45 additions & 28 deletions src/main/java/com/hrs/kloping/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

import static com.hrs.kloping.HPlugin_Landlord.threads;
import static com.hrs.kloping.HPluginLandlord.threads;
import static com.hrs.kloping.Utils.*;

/**
Expand Down Expand Up @@ -61,15 +61,21 @@ public void addPlayer(long qq) {
playerEns.put(q, getEntry(group.get(q), new MessageChainBuilder().append(new At(players.get(i))).append("\r\n").build()));
}
group.sendMessage("开始发牌!");
startDeal();
try {
startDeal();
} catch (Throwable e) {
e.printStackTrace();
group.sendMessage("发牌异常出错,请重新开始游戏");
Command.destroy();
}
});
}
}

int r1 = -1, r2 = -1, r3 = -1;

private void startDeal() {
InitR();
private void startDeal() throws Throwable {
initR();
Dcards.add(ListCards.get(r1));
Dcards.add(ListCards.get(r2));
Dcards.add(ListCards.get(r3));
Expand Down Expand Up @@ -97,7 +103,7 @@ private void startDeal() {
startRob();
}

private synchronized void sendThisCards(final Map.Entry<Member, Message> kv, final long q) {
private synchronized void sendThisCards(final Map.Entry<Member, Message> kv, final long q) throws Exception{
kv.getKey().sendMessage(
new MessageChainBuilder()
.append("你这一局的牌是:\r\n")
Expand Down Expand Up @@ -179,7 +185,7 @@ public String noRob(long qq) {
}
}

private void InitR() {
private void initR() {
r1 = rand.nextInt(54);
do {
r2 = rand.nextInt(53);
Expand Down Expand Up @@ -403,14 +409,24 @@ private static boolean isBigger(List<Card> cards, List<Card> cards1) {
}
int vc1 = getMaxSameC(values);
int vc2 = getMaxSameC(value2s);
if (values.length == 4 && value2s.length == 4) {
if (vc2 < 4 && vc1 == 4) return true;
if (vc2 == 3 && vc1 == 3) {
int v2 = getMaxSameN(value2s);
int v1 = getMaxSameN(values);
return v1 > v2;
} else if (vc1 == 4 && vc2 == 4) {
return values[0] > value2s[0];
if (values.length == 4) {
if (value2s.length == 4) {
if (vc2 < 4 && vc1 == 4) return true;
if (vc2 == 3 && vc1 == 3) {
int v2 = getMaxSameN(value2s);
int v1 = getMaxSameN(values);
return v1 > v2;
} else if (vc1 == 4 && vc2 == 4) {
return values[0] > value2s[0];
}
} else if (value2s.length == 2) {
if (value2s[0] == 14 && value2s[1] == 15) {
return false;
} else {
return true;
}
} else {
return false;
}
}
if (values.length >= 5) {
Expand Down Expand Up @@ -478,7 +494,7 @@ public void tipsPool() {
} else {
group.sendMessage(new MessageChainBuilder()
.append(message)
.append(getNowCardsName())
.append(getNowCardsName(this_cards.cards))
.append(getImageFromFilePath(Drawer.createImage(cards2Images(this_cards.cards)), group))
.append("轮到你出牌了,这是你要打的牌")
.build()
Expand All @@ -487,8 +503,7 @@ public void tipsPool() {
}
}

private String getNowCardsName() {
List<Card> cards = this_cards.cards;
private static String getNowCardsName(List<Card> cards) {
final int[] values = cards2values(cards);
Arrays.sort(values);
if (values.length == 1) return "";
Expand All @@ -497,8 +512,10 @@ private String getNowCardsName() {
return getMaxSameC(values) == 3 ? "三个" : "";
}
if (values.length == 4) {
if (getMaxSameC(values) >= 3) {
if (getMaxSameC(values) == 3) {
return "三帯一";
} else if (getMaxSameC(values) == 4) {
return "炸弹";
} else if (values[0] == values[1] && values[2] == values[3] && values[1] == values[2]) {
return "炸弹";
} else return "";
Expand Down Expand Up @@ -582,24 +599,26 @@ private void testWin() {
}
}

private void tipsCivilianWin() {
public void tipsCivilianWin() {
MessageChainBuilder builder = new MessageChainBuilder();
long lq = players.get((int) landlord);
for (long q : players) {
if (q == landlord) {
if (q == lq) {
continue;
}
builder.append(new At(q).plus(new Face(Face.DE_YI))).append("\n");
}
builder.append(new At(landlord).plus(new Face(Face.SHUAI))).append("\n");
builder.append(new At(lq).plus(new Face(Face.SHUAI))).append("\n");
builder.append("平民胜利!!!");
group.sendMessage(builder.build());
}

private void tipsLandlordWin() {
MessageChainBuilder builder = new MessageChainBuilder();
builder.append(new At(landlord).plus(new Face(Face.DE_YI))).append("\n");
long lq = players.get((int) landlord);
builder.append(new At(lq).plus(new Face(Face.DE_YI))).append("\n");
for (long q : players) {
if (q != landlord) {
if (q != lq) {
continue;
}
builder.append(new At(q).plus(new Face(Face.SHUAI))).append("\n");
Expand Down Expand Up @@ -643,14 +662,12 @@ public static void main(String[] args) {
l1.add(new Card(Card.En._4, Card.Type._V));
l1.add(new Card(Card.En._4, Card.Type._W));
l1.add(new Card(Card.En._4, Card.Type._A));
l1.add(new Card(Card.En._5, Card.Type._X));
l1.add(new Card(Card.En._4, Card.Type._X));

l2.add(new Card(Card.En._3, Card.Type._V));
l2.add(new Card(Card.En._3, Card.Type._W));
l2.add(new Card(Card.En._3, Card.Type._A));
l2.add(new Card(Card.En._4, Card.Type._X));
l2.add(new Card(Card.En._4, Card.Type._X));

System.out.println(isBigger(l1, l2));
l2.add(new Card(Card.En._3, Card.Type._X));
System.out.println(isBigger(l2, l1));
}
}

0 comments on commit 46d2f08

Please sign in to comment.