package com.xl.game;
import com.xl.domain.Poker;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Common {
//判断牌型
public static PokerType jugdeType(ArrayList<Poker> list) {
int len = list.size();
if (len <= 4) {
if (list.size() > 0 && Common.getValue(list.get(0)) == Common.getValue(list.get(len - 1))) {
switch (len) {
case 1:
return PokerType.c1;
case 2:
return PokerType.c2;
case 3:
return PokerType.c3;
case 4:
return PokerType.c4;
}
}
if (len == 2 && Common.getColor(list.get(1)) == 5)
return PokerType.c2;
if (len == 4 && ((Common.getValue(list.get(0)) == Common.getValue(list.get(len - 2)))
|| Common.getValue(list.get(1)) == Common.getValue(list.get(len - 1))))
return PokerType.c31;
else {
return PokerType.c0;
}
}
if (len >= 5) {
PokerIndex pokerIndex = new PokerIndex();
ArrayList<ArrayList<Integer>> indexList = pokerIndex.indexList;
for (int i = 0; i < 4; i++) {
indexList.add(new ArrayList<>());
}
Common.getMax(pokerIndex, list);
if (indexList.get(2).size() == 1 && indexList.get(1).size() == 1 && len == 5)
return PokerType.c32;
if (indexList.get(3).size() == 1 && len == 6)
return PokerType.c411;
if (indexList.get(3).size() == 1 && indexList.get(1).size() == 2 && len == 8)
return PokerType.c422;
if ((Common.getColor(list.get(0)) != 5) && (indexList.get(0).size() == len)
&& (Common.getValue(list.get(0)) - Common.getValue(list.get(len - 1)) == len - 1))
return PokerType.c123;
if (indexList.get(1).size() == len / 2 && len % 2 == 0 && len / 2 >= 3
&& (Common.getValue(list.get(0)) - Common.getValue(list.get(len - 1)) == (len / 2 - 1)))
return PokerType.c112233;
if (indexList.get(2).size() == len / 3 && (len % 3 == 0)
&& (Common.getValue(list.get(0)) - Common.getValue(list.get(len - 1)) == (len / 3 - 1)))
return PokerType.c111222;
if (indexList.get(2).size() == len / 4 && (indexList.get(2).get(len / 4 - 1)
- (indexList.get(2).get(0)) == len / 4 - 1))
return PokerType.c11122234;
if (indexList.get(2).size() == len / 5 && indexList.get(2).size() == len / 5
&& ((indexList.get(2).get(len / 5 - 1)) - (indexList.get(2).get(0)) == len / 5
- 1))
return PokerType.c1112223344;
}
return PokerType.c0;
}
//移动牌(有移动的动画效果)
public static void move(Poker poker, Point from, Point to) {
if (to.x != from.x) {
double k = (1.0) * (to.y - from.y) / (to.x - from.x);
double b = to.y - to.x * k;
int flag = 0;
if (from.x < to.x)
flag = 20;
else {
flag = -20;
}
for (int i = from.x; Math.abs(i - to.x) > 20; i += flag) {
double y = k * i + b;
poker.setLocation(i, (int) y);
try {
Thread.sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
poker.setLocation(to);
}
//利用牌的价值,将集合中的牌进行排序
public static void order(ArrayList<Poker> list) {
//此时可以改为lambda表达式
Collections.sort(list, new Comparator<Poker>() {
@Override
public int compare(Poker o1, Poker o2) {
//获取花色
//1-黑桃 2-红桃 3-梅花 4-方块 5-大小王
int a1 = Integer.parseInt(o1.getName().substring(0, 1));
int a2 = Integer.parseInt(o2.getName().substring(0, 1));
//获取牌上的数字,同时也是牌的价值
//1-A ... 11-J 12-Q 13-K
int b1 = Integer.parseInt(o1.getName().substring(2));
int b2 = Integer.parseInt(o2.getName().substring(2));
//计算牌的价值,利用牌的价值进行排序
//牌上的数字在3~10之间,价值就是3~10
//3:价值3
//...
//10:价值10
//J:价值11
//Q:价值12
//K:价值13
//A:1 + 20 = 21
//2:2 + 30 = 32
//小王:1 + 100 = 101
//大王:2 + 100 = 102
//计算大小王牌的价值
if (a1 == 5) {
b1 += 100;
}
if (a2 == 5) {
b2 += 100;
}
//计算A的价值
if (b1 == 1) {
b1 += 20;
}
if (b2 == 1) {
b2 += 20;
}
//计算2的价值
if (b1 == 2) {
b1 += 30;
}
if (b2 == 2) {
b2 += 30;
}
//倒序排列
int flag = b2 - b1;
//如果牌的价值一样,则按照花色排序
if (flag == 0) {
return a2 - a1;
} else {
return flag;
}
}
});
}
//重新摆放牌
public static void rePosition(GameJFrame m, ArrayList<Poker> list, int flag) {
Point p = new Point();
if (flag == 0) {
p.x = 50;
p.y = (450 / 2) - (list.size() + 1) * 15 / 2;
}
if (flag == 1) {
p.x = (800 / 2) - (list.size() + 1) * 21 / 2;
p.y = 450;
}
if (flag == 2) {
p.x = 700;
p.y = (450 / 2) - (list.size() + 1) * 15 / 2;
}
int len = list.size();
for (int i = 0; i < len; i++) {
Poker poker = list.get(i);
Common.move(poker, poker.getLocation(), p);
m.container.setComponentZOrder(poker, 0);
if (flag == 1)
p.x += 21;
else
p.y += 15;
}
}
public static int getScore(ArrayList<Poker> list) {
int count = 0;
for (int i = 0, len = list.size(); i < len; i++) {
Poker poker = list.get(i);
if (poker.getName().substring(0, 1).equals("5")) {
count += 5;
}
if (poker.getName().substring(2).equals("2")) {
count += 2;
}
}
return count;
}
public static int getColor(Poker poker) {
return Integer.parseInt(poker.getName().substring(0, 1));
}
public static int getValue(Poker poker) {
int i = Integer.parseInt(poker.getName().substring(2));
if (poker.getName().substring(2).equals("2"))
i += 13;
if (poker.getName().substring(2).equals("1"))
i += 13;
if (Common.getColor(poker) == 5)
i += 2;
return i;
}
public static void getMax(PokerIndex pokerIndex, ArrayList<Poker> list) {
int
没有合适的资源?快使用搜索试试~ 我知道了~
Java GUI斗地主完整功能实现
共89个文件
png:61个
class:12个
java:10个
2 下载量 15 浏览量
2023-07-07
16:24:20
上传
评论
收藏 491KB ZIP 举报
温馨提示
Java GUI斗地主
资源推荐
资源详情
资源评论
收起资源包目录
doudizhu.zip (89个子文件)
doudizhu
image
poker
2-6.png 544B
2-12.png 1KB
4-9.png 582B
2-8.png 606B
3-6.png 522B
1-1.png 522B
2-11.png 1KB
1-11.png 1KB
1-6.png 508B
3-2.png 417B
3-7.png 536B
4-12.png 1KB
1-7.png 526B
3-11.png 1KB
2-1.png 410B
rear.png 4KB
2-2.png 429B
3-5.png 490B
1-3.png 432B
4-1.png 402B
5-2.png 5KB
4-4.png 469B
3-9.png 587B
1-10.png 618B
2-13.png 1KB
1-2.png 474B
1-12.png 1KB
5-1.png 5KB
4-6.png 513B
2-7.png 570B
4-3.png 435B
2-3.png 452B
3-10.png 623B
4-10.png 621B
3-8.png 572B
4-5.png 498B
1-13.png 1KB
2-5.png 518B
1-8.png 562B
1-5.png 478B
2-10.png 661B
3-3.png 438B
4-2.png 417B
4-11.png 1KB
4-7.png 527B
3-12.png 1KB
2-9.png 623B
4-13.png 1KB
1-4.png 463B
1-9.png 581B
3-1.png 390B
3-13.png 1KB
2-4.png 492B
3-4.png 468B
4-8.png 565B
dizhu.png 3KB
login
注册按下.png 7KB
注册按钮.png 7KB
登录按钮.png 7KB
登录按下.png 8KB
background.png 355KB
src
App.java 137B
com
xl
game
Common.java 19KB
LoginJFrame.java 8KB
Model.java 534B
PokerType.java 355B
PlayerOperation.java 15KB
GameJFrame.java 11KB
util
CodeUtil.java 2KB
domain
Poker.java 3KB
User.java 1KB
doudizhu.iml 433B
out
production
doudizhu
App.class 397B
com
xl
game
PlayerOperation.class 14KB
PokerIndex.class 462B
GameJFrame.class 7KB
Model.class 742B
LoginJFrame.class 6KB
Common$1.class 1KB
Common.class 14KB
PokerType.class 2KB
util
CodeUtil.class 2KB
domain
User.class 2KB
Poker.class 4KB
.idea
workspace.xml 3KB
misc.xml 256B
compiler.xml 169B
modules.xml 263B
.gitignore 190B
共 89 条
- 1
资源评论
java夜潇筱
- 粉丝: 99
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功