Java四人网络斗地主游戏《客户端》swing界面

时间:2023-02-17 18:10:40

这是本人写的四人网络斗地主

河南南阳地区的玩法,一副牌没有大小王

Java四人网络斗地主游戏《客户端》swing界面

Client

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.net.*;
import ds.*;
import java.util.*;
public class Client extends JFrame implements ActionListener{
JLabel jl1,jl2,jl3;
JPanel jp1,jp2,jp3,jp4;
JTextField jtf1,jtf2;
JButton jb;
static Socket s;
static String userName;
static Client client;
static ArrayList<User> onlineUser=new ArrayList<User>();
static ArrayList<User> parter=new ArrayList<User>();
static User currUser;
static Game game;
public static void main(String[] args) {
client=new Client();
}
public Client(){
jl1=new JLabel(new ImageIcon("ico/login/ad.gif"));
jl2=new JLabel("用户名");
jl3=new JLabel("ip地址");
jtf1=new JTextField("hufan",10);
jtf2=new JTextField("127.0.0.1",10);
jp1=new JPanel();
jp2=new JPanel();
jp3=new JPanel(new BorderLayout());
jp4=new JPanel();
jb=new JButton("登陆");
jb.addActionListener(this);
jp1.add(jl2);
jp1.add(jtf1);
jp2.add(jl3);
jp2.add(jtf2);
jp3.add(jp1);
jp3.add(jp2,"South");
jp4.add(jb);
this.add(jl1,"North");
this.add(jp3);
this.add(jp4,"South");
this.setTitle("游戏登陆");
this.setSize(323, 200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==jb){
userName=jtf1.getText();
String ip=jtf2.getText();
try {
s=new Socket(ip,5555);
ClientThread ct=new ClientThread(s);
Thread t=new Thread(ct);
t.start();
PrintStream ps=new PrintStream(s.getOutputStream());
ps.println("登陆"+"拆"+userName+"拆"+"登陆");
} catch (UnknownHostException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}


ClientThread

import java.net.*;
import java.util.ArrayList;
import java.util.Collections;

import ds.*;

import java.io.*;
import javax.swing.*;
public class ClientThread implements Runnable{
Socket s;
static Room room;
static boolean tuiChu=true;
public ClientThread(Socket s){
this.s=s;
}
@Override
public synchronized void run() {
// TODO Auto-generated method stub
BufferedReader br=null;
try {
br=new BufferedReader(new InputStreamReader(s.getInputStream()));
String info=null;
while(tuiChu){
while((info=br.readLine())==null);
if(info.equals("姓名重复")){
JOptionPane.showMessageDialog(Client.client, "姓名重复");
}else if(info.equals("登陆成功")){
User user=new User(Client.userName);
Client.currUser=user;
Client.onlineUser.add(Client.currUser);
Client.client.setVisible(false);
room=new Room();
}else if(info.startsWith("广播")&&info.endsWith("广播")){
String arr[]=info.split("拆");
String userName=arr[1];
User user=new User(userName);
Client.onlineUser.add(user);
room.dp.repaint();
}else if(info.startsWith("所有")&&info.endsWith("所有")){
String arr[]=info.split("拆");
String userName=arr[1];
int desk=Integer.parseInt(arr[2]);
int site=Integer.parseInt(arr[3]);
User user=new User(userName,desk,site);
Client.onlineUser.add(user);
if(desk!=0){
int x=(desk+5)%6;
int y=(desk-1)/6;
room.siteCondition[x][y][site-1]=1;
}
room.dp.repaint();
}else if(info.startsWith("坐下")&&info.endsWith("坐下")){
String arr[]=info.split("拆");
String userName=arr[1];
//修改座位
for(User uu:Client.onlineUser){
if(uu.getUserName().equals(userName)){
int desk=Integer.parseInt(arr[2]);
int site=Integer.parseInt(arr[3]);
uu.setDesk(desk);
uu.setSite(site);
int x=(desk+5)%6;
int y=(desk-1)/6;
room.siteCondition[x][y][site-1]=1;
//是否和自己同桌
if(Client.parter.size() != 0){
if(uu.getDesk()==Client.currUser.getDesk()){
Client.parter.add(uu);
room.ddz.da.repaint();
}
}
break;
}
}
room.dp.repaint();
room.ddz.da.repaint();
}else if(info.startsWith("准备")&&info.endsWith("准备")){
String arr[]=info.split("拆");
String userName=arr[1];
//通过发来的userName来找partner里的自己,修改
for(User uu:Client.parter){
if(uu.getUserName().equals(userName)){
int site=uu.getSite();
Ddz.ready[site-1]=true;
break;
}
}
//同时刷新游戏画面,
//发送过去,对方可能给还没运行ddz
if(room.ddz != null){
room.ddz.da.repaint();
}
}else if(info.startsWith("开始")&&info.endsWith("开始")){
//初始化gameMsg
Client.game = new Game(Client.currUser.getUserName());
//同时设置一些必要的信息
Client.game.setReady(true);
Client.game.setStart(true);
//Room.isLive[Client.currUser.getDesk() - 1] = true;
Ddz.init();
Ddz.ready = new boolean[4];
Ddz.count = new int[4];
room.dp.repaint();
room.ddz.da.repaint();
}else if(info.startsWith("底牌")&&info.endsWith("底牌")){
String arr[]=info.split("拆");
for(int i=0;i<4;i++){
String[] poke = arr[i+1].split("分");
int pokeNum=Integer.parseInt(poke[0]);
int pokeColor=Integer.parseInt(poke[1]);
Poke p=new Poke(pokeNum,pokeColor);
Client.game.getBottomPoke().add(p);
}
room.ddz.da.repaint();
}else if(info.startsWith("发牌")&&info.endsWith("发牌")){
String arr[]=info.split("拆");
String poke[]=arr[1].split("分");
int pokeNum=Integer.parseInt(poke[0]);
int pokeColor=Integer.parseInt(poke[1]);
Poke p=new Poke(pokeNum,pokeColor);
Client.game.getCurrentPoke().add(p);
Collections.sort(Client.game.getCurrentPoke());
for(int i=0;i<4;i++){
Ddz.count[i]=Client.game.getCurrentPoke().size();
}
room.ddz.da.repaint();
}else if(info.startsWith("叫地主")&&info.endsWith("叫地主")){
String arr[]=info.split("拆");
int site=Integer.parseInt(arr[1]);
//记录是谁先叫地主的
Client.game.setOrder(site);
room.ddz.da.repaint();
}else if(info.startsWith("游戏开始")&&info.endsWith("游戏开始")){
String arr[]=info.split("拆");
String usrName=arr[1];
int site=Integer.parseInt(arr[2]);
if(site==Client.currUser.getSite()){
Client.game.currentPoke.addAll(Client.game.bottomPoke);
Collections.sort(Client.game.currentPoke);
}
Client.game.setDdzName(usrName);
Client.game.setTurnBanker(site);
Client.game.setOrder(site);
Ddz.count[site-1]+=4;
room.ddz.da.repaint();
}else if(info.startsWith("不叫")&&info.endsWith("不叫")){
String arr[]=info.split("拆");
int site=Integer.parseInt(arr[1]);
Client.game.setOrder(site);
room.ddz.da.repaint();
}else if(info.startsWith("出牌")&&info.endsWith("出牌")){
String[] arr = info.split("拆");
int site = Integer.parseInt(arr[1]);
Client.game.poke.clear();
for (int i = 2; i < arr.length - 1 ; i++){
String[] poke = arr[i].split("分");
int pokeNum = Integer.parseInt(poke[0]);
int pokeColor = Integer.parseInt(poke[1]);
Poke p = new Poke(pokeNum,pokeColor);
Client.game.poke.add(p);
Collections.sort(Client.game.poke);
}
//对收到的牌
Ddz.turnPoke[site - 1] = new ArrayList<Poke>();
Ddz.turnPoke[site - 1].addAll(Client.game.poke);
//修改对应的消息
Client.game.setOrder(site%4+1);
DdzArea.showPoke=true;//可以显示出的牌
//对收到的牌进行下分析,看看是否是炸弹
Ddz.hatPut +=1;
//同时修改时间
//刷新游戏画面
Ddz.count[site - 1] -= Ddz.turnPoke[site - 1].size();
room.ddz.da.repaint();
}else if(info.startsWith("不出")&&info.endsWith("不出")){
String[] arr = info.split("拆");
int site = Integer.parseInt(arr[1]);
Ddz.turnPoke[site - 1].clear();
Client.game.setOrder(site %4 +1);
Ddz.hatPut += 1;
DdzArea.daShow=false;
room.ddz.da.repaint();
}else if(info.startsWith("最大")&&info.endsWith("最大")){
String[] arr = info.split("拆");
int site = Integer.parseInt(arr[1]);
//修改信息
Client.game.setOrder(site);
Client.game.setTurnBanker(site);
Client.game.poke.clear();
int hu=0;
if(site==1){
hu=4;
}else{
hu=site-1;
}
Ddz.turnPoke[hu-1].clear();//最后加的
//初始化必要的信息
Ddz.hatPut +=1;
DdzArea.daShow=true;
room.ddz.da.repaint();
System.out.println(Client.game.getTurnBanker()+" 最大");
}else if((info.startsWith("游戏结束")&& info.endsWith("游戏结束"))){
String[] arr = info.split("拆");
int site = Integer.parseInt(arr[1]);
//查看是誰贏了
//先獲得地主地主
String[] str = new String[4];
for (int i = 0; i<4;i++ ){
str[i] = Client.parter.get(i).getUserName();
}
int dzSite = Client.parter.get(Client.parter.indexOf(
new User(Client.game.getDdzName()))).getSite();
//所得分数
//查看是否是地主贏了
//像其他用戶發送自己分数变化的情况
String strs = "本局得分情况: \n";
for (int i = 0; i<4; i++){
strs += str[i] + "\n";
}
JOptionPane.showMessageDialog(room.ddz,strs,
"本局得分",JOptionPane.INFORMATION_MESSAGE);
//同時修改必要的數據
Client.game = new Game(Client.currUser.getUserName());
Ddz.ready = new boolean[4];
Ddz.init();
DdzArea.daShow=false;
DdzArea.showPoke=false;
Client.game.currentPoke.clear();
Client.game.poke.clear();
Client.game.bottomPoke.clear();
//初始化
room.ddz.da.repaint();
//修改当前用户面板信息
//修改游戏用户的积分信息
//同时用户在修改大厅的消息
}else if((info.startsWith("退出")&& info.endsWith("退出"))){
String[] arr = info.split("拆");
int deskNum = Integer.parseInt(arr[1]);
int site = Integer.parseInt(arr[2]);
String userName = arr[3];
//如果它与自己同桌
User um = new User(userName);
if(deskNum == Client.currUser.getDesk()){
um = Client.parter.get(Client.parter.indexOf(um));
if(Client.game.isStart()){
JOptionPane.showMessageDialog(null, "对手强行退出了" , "通知" ,
JOptionPane.INFORMATION_MESSAGE);
}
Ddz ddz = room.ddz;
//删除对应的占座信息
//清除游戏信息
Client.game = new Game(Client.currUser.getUserName());
//删除用户
Client.parter.remove(um);
Ddz.init();
room.ddz.da.repaint();
Ddz.ready = new boolean[4];
}
//重新设置它的座位
for (User uu : Client.onlineUser ){
if(uu.getUserName().equals(userName)){
uu.setDesk(0);
uu.setSite(0);
break;
}
}
int x = (deskNum+5)%6;
int y = (deskNum-1) /6;
room.siteCondition[x][y][site-1] = 0;
//Room.isLive[deskNum - 1] = false;
//room.getDeskPanel().repaint();
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showMessageDialog(Client.client, "连接服务器中断");
System.exit(1);
}
}

}


Ddz

import javax.swing.*;

import java.io.*;
import java.awt.*;
import ds.*;

import java.util.*;
import java.awt.Cursor;
import java.awt.event.*;

public class Ddz extends JFrame implements MouseListener, MouseMotionListener,WindowListener {
DdzArea da;
static boolean ready[] = new boolean[4];
static int count[] = new int[4];
static Point THREE_BN = new Point(330, 490);
static Point BJ_BN = new Point(420, 490);
static Point CP_BN1 = new Point(370, 490);
static Point CP_BN2 = new Point(330, 490);
static Point BC_BN = new Point(420, 490);
static int hatPut = 0;
static boolean[] pokePop = new boolean[16];
static ArrayList<Poke>[] turnPoke = new ArrayList[4];
static boolean[] hufan=new boolean[4];//记录用户开始出牌了
public static void main(String[] args) {
new Ddz();
}

public Ddz() {
this.init();
// 初始化游戏数据
Client.game = new Game();
da = new DdzArea();
da.addMouseListener(this);
da.addMouseMotionListener(this);
this.addWindowListener(this);
this.add(da);
this.setTitle("斗地主");
this.setSize(900, 740);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setVisible(true);
}

public static void init() {
for (int i = 0; i < 4; i++) {
if (turnPoke[i] == null) {
turnPoke[i] = new ArrayList<Poke>();
} else {
turnPoke[i].clear();
}
}
//PokeAnalyze currPa = new PokeAnalyze();
hatPut = 0;
}
@Override
public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub
int x = e.getX();
int y = e.getY();
if (!Client.game.isStart()) {
// 监听开始按钮
if (x >= 570 && x <= 630 && y >= 550 && y <= 580) {
da.setCursor(new Cursor(Cursor.HAND_CURSOR));
da.setPos(x, y);
} else {
da.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
da.setPos(0, 0);
}
} else {
if (Client.game.getDdzName() == null) {

if (Client.game.getOrder() == Client.currUser.getSite()) {
boolean flag = false;
// 不叫
int X2 = (int) this.BJ_BN.getX();
int Y2 = (int) this.BJ_BN.getY();
if (x >= X2 && x <= X2 + 60 && y >= Y2 && y <= Y2 + 30) {
da.setCursor(new Cursor(Cursor.HAND_CURSOR));
da.setPos(X2, Y2);
flag = true;
}
// 三分
int X1 = (int) this.THREE_BN.getX();
int Y1 = (int) this.THREE_BN.getY();
if (x >= X1 && x <= X1 + 60 && y >= Y1 && y <= Y1 + 30) {
da.setCursor(new Cursor(Cursor.HAND_CURSOR));
da.setPos(X1, Y1);
flag = true;
}
if (!flag) {
da.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
da.setPos(0, 0);
}
}
} else {// 地主名不为空
if (Client.game.getOrder() == Client.currUser.getSite())
{
if ((Client.game.getTurnBanker() ==Client.game.getOrder()&& Ddz.hatPut == 0)
||(Client.game.getTurnBanker()==Client.game.getOrder()&& DdzArea.daShow)) {
// 出牌
int X1 = (int) this.CP_BN2.getX();
int Y1 = (int) this.CP_BN2.getY();
if (x >= X1 && x <= X1 + 60 && y >= Y1 && y <= Y1 + 30) {
da.setCursor(new Cursor(Cursor.HAND_CURSOR));
da.setPos(X1, Y1);
}else{
da.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
da.setPos(0, 0);
}
}else{
boolean flag = false;
// 不出
int X2 = (int) this.BC_BN.getX();
int Y2 = (int) this.BC_BN.getY();
if (x >= X2 && x <= X2 + 60 && y >= Y2 && y <= Y2 + 30) {
da.setCursor(new Cursor(Cursor.HAND_CURSOR));
da.setPos(X2, Y2);
flag = true;
}
// 出牌
int X1 = (int) this.CP_BN2.getX();
int Y1 = (int) this.CP_BN2.getY();
if (x >= X1 && x <= X1 + 60 && y >= Y1 && y <= Y1 + 30) {
da.setCursor(new Cursor(Cursor.HAND_CURSOR));
da.setPos(X1, Y1);
flag = true;
}
if (!flag) {
da.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
da.setPos(0, 0);
}
}
}
}
}
}

@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
int x = e.getX();
int y = e.getY();
if (!Client.game.isStart()) {
if (!Client.game.isReady()) {
// 点击开始按钮,发送准备信息
if (x >= 570 && x <= 630 && y >= 550 && y <= 580) {
Client.game.setReady(true);
this.ready[Client.currUser.getSite() - 1] = true;
try {
PrintStream ps = new PrintStream(
Client.s.getOutputStream());
ps.println("准备" + "拆" + Client.currUser.getUserName()
+ "拆" + Client.currUser.getDesk() + "拆"
+ Client.currUser.getSite() + "拆" + "准备");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
} else {// 开始
// 监听点击牌
int pokeCount = Client.game.currentPoke.size();
int length = 71 + 15 * (pokeCount - 1);
int xStart = (816 - length) / 2;
if (y >= 550 - 15 && y <= 550 + 96 && x >= xStart
&& x <= xStart + length) {
int x_len = x - xStart;
int index = pokeCount - 1 - x_len / 15;
if (index < 0)
index = 0;
if (pokePop[index]) {
if (y >= 550 - 15 && y <= 550 + 96 - 15) {
pokePop[index] = false;
}
} else {
if (y >= 550) {
pokePop[index] = true;
} else
// 单击的弹出区,需要查看前四张是否有弹出,有的话,需要缩回去
if (y >= 550 - 15) {
for (int i = 1; i < pokeCount - index; i++) {
if (pokePop[index + i] == true) {
pokePop[index + i] = false;
break;
}
}
}
}
da.repaint();
}

if (Client.game.getOrder() == Client.currUser.getSite()) {
if (Client.game.getDdzName() == null) {
// 点三分
int X1 = (int) this.THREE_BN.getX();
int Y1 = (int) this.THREE_BN.getY();
if (x >= X1 && x <= X1 + 60 && y >= Y1 && y <= Y1 + 30) {
try {
PrintStream ps = new PrintStream(
Client.s.getOutputStream());
ps.println("游戏开始" + "拆"
+ Client.currUser.getUserName() + "拆"
+ Client.currUser.getSite() + "拆" + "游戏开始");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
// 不叫
int X2 = (int) this.BJ_BN.getX();
int Y2 = (int) this.BJ_BN.getY();
if (x >= X2 && x <= X2 + 60 && y >= Y2 && y <= Y2 + 30) {
PrintStream ps;
try {
ps = new PrintStream(Client.s.getOutputStream());
if(Client.game.getTurnBanker()==Client.game.getOrder()%4+1){
ps.println("重新发牌"+"重新发牌");
}else{
ps.println("不叫" + "拆"
+ Client.currUser.getUserName() + "拆"
+ Client.currUser.getSite() + "拆" + "不叫");
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

}
} else {// 地主名不为空
if (Client.game.getOrder() == Client.currUser.getSite()) {
if ((Client.game.getTurnBanker() == Client.game.getOrder()&& hatPut == 0)
||(Client.game.getTurnBanker() == Client.game.getOrder()&& DdzArea.daShow)) {
// 出牌
int X2 = (int) this.CP_BN2.getX();
int Y2 = (int) this.CP_BN2.getY();
if (x >= X2 && x <= X2 + 60 && y >= Y2&& y <= Y2 + 30) {
int site = Client.currUser.getSite();
ArrayList<Poke> popList=cpBn();
PokeAnalyze po = new PokeAnalyze(popList);
if(po.analyze()){
PrintStream ps = null;
try{
ps = new PrintStream(Client.s.getOutputStream());
}catch (Exception ex){
ex.printStackTrace();
}
String str = "";
//牌成String
for (int i = 0; i <popList.size();i++ ){
str += popList.get(i) + "拆";
}
turnPoke[site - 1].clear();
turnPoke[site - 1].addAll(popList);
Client.game.poke.clear();
Client.game.poke.addAll(popList);

//Client.game.poke.addAll(turnPoke[site -1]);
//发送消息
ps.println("出牌"+"拆"+site + "拆" +str +"出牌");
//修改必要的信息
hatPut += 1;//因为hadPut,所以没有必要写hadPut += 1
Client.game.setOrder(site%4 + 1);
DdzArea.showPoke=true;//可以显示出的牌
//翻倍
//初始化
pokePop = new boolean[16];
//删除对应的牌
Client.game.currentPoke.removeAll(popList);
da.repaint();
//接着检查是否游戏结束的消息
if(Client.game.currentPoke.size() == 0)
sendGameOVer(site);
}else{
JOptionPane.showMessageDialog(this,"你选的牌不合规则");
}
}
}else{
// 出牌
int X1 = (int) this.CP_BN2.getX();
int Y1 = (int) this.CP_BN2.getY();
if( x >= X1&& x <= X1 + 60&& y >=Y1&& y <= Y1 + 30){
//获得牌
int site =Client.currUser.getSite();
turnPoke[site-1] = cpBn();
PokeAnalyze po = new PokeAnalyze(turnPoke[site-1]);
if(po.analyze()){
//分析现有的牌
PokeAnalyze currPo = new PokeAnalyze(Client.game.poke);
//先对牌先分析一下
currPo.analyze();
//可以出牌
if(currPo.getType() == PokeAnalyze.BOOM){
if(po.getType() == PokeAnalyze.BOOM &&
po.getBigPoke().compareTo(currPo.getBigPoke()) > 0)
{
outPoke(po);
}else{
JOptionPane.showMessageDialog(this,"你选的牌不合规则");
}
}else if((currPo.getNum() == po.getNum() &&
currPo.getType() == po.getType() &&
po.getBigPoke().compareTo(currPo.getBigPoke()) > 0)||
(po.getType() == PokeAnalyze.BOOM))
{
outPoke(po);
}else{
JOptionPane.showMessageDialog(this,"你选的牌不合规则");
}
}else{
JOptionPane.showMessageDialog(this,"你选的牌不合规则");
}
}else if( x >= (int)BC_BN.getX()
&& x <= (int)BC_BN.getX() + 60
&& y >=(int)BC_BN.getY()
&& y <= (int)BC_BN.getY() + 30)
{
PrintStream ps = null;
try{
ps = new PrintStream(Client.s.getOutputStream());
}catch (Exception ex){
ex.printStackTrace();
}
int site = Client.currUser.getSite();
//初始化
pokePop = new boolean[16];
hatPut += 1;
//判断这轮谁大
//上家
int preSite;
if(site - 1 == 0)
preSite = 4;
else
preSite = site - 1;
//下家
int backSite;
if(site == 4)
backSite = 1;
else
backSite = site + 1;
//下下家
int backbackSite;
if(backSite == 4)
backbackSite = 1;
else
backbackSite = backSite + 1;
//不出,而且上家也是不出,那么就认为时下家的牌最大,为turnBanker
if(hatPut >= 4 && turnPoke[preSite - 1].size()== 0&& turnPoke[backbackSite - 1].size()== 0){
//自己不出,还有自己的上一家也是不出,那么就认为这轮是下家大
//这轮最大牌的就是下家
ps.println("最大" +"拆" +backSite +"拆" +"最大");
//修改信息
Client.game.setOrder(backSite);
Client.game.setTurnBanker(backSite);
Client.game.poke.clear();
turnPoke[site - 1].clear();//最后加的
//初始化化必要的信息
hatPut +=1;
DdzArea.daShow=true;
}else{
//发送不出的消息
ps.println("不出"+"拆"+site+"拆"+"不出" );
//同时修改必要信息
DdzArea.daShow=false;
turnPoke[site - 1].clear();
Client.game.setOrder(site%4 +1);
}
da.repaint();
}
}
}
}
}
}
}
private void outPoke(PokeAnalyze po){
int site =Client.currUser.getSite();
PrintStream ps = null;
try{
ps = new PrintStream(Client.s.getOutputStream());
}catch (Exception ex){
ex.printStackTrace();
}
String str = "";
//牌排成String
for (int i = 0; i <turnPoke[site-1].size();i++ ){
str += turnPoke[site-1].get(i) + "拆";
}
Client.game.poke.clear();
Client.game.poke.addAll(turnPoke[site -1]);
//发送消息
ps.println("出牌" + "拆"+site + "拆" +str +"出牌");
//修改必要的信息
hatPut += 1;
Client.game.setOrder(site%4 + 1);
//翻倍
//初始化
pokePop = new boolean[16];
//删除对应的牌
Client.game.currentPoke.removeAll(turnPoke[site - 1]);
//接着检查是否游戏结束的消息
if(Client.game.currentPoke.size() == 0){
sendGameOVer(site);
}
da.repaint();
}
private ArrayList cpBn() {
ArrayList<Poke> list = new ArrayList<Poke>();
for (int i = 0; i < Client.game.currentPoke.size(); i++) {
// 得到要出的牌
if (pokePop[i])
list.add(Client.game.currentPoke.get(i));
}
return list;
}
public static void sendGameOVer(int site){
try{
PrintStream ps = new PrintStream(Client.s.getOutputStream());
ps.println("游戏结束" + "拆" +site + "拆" +"游戏结束");
}catch (Exception ex){
ex.printStackTrace();
}
}
public void mouseEntered(MouseEvent arg0) {}
public void mouseExited(MouseEvent arg0) {}
public void mousePressed(MouseEvent e) {
int xPre = e.getX();
int yPre = e.getY();
// 监听点击牌
}
public void mouseReleased(MouseEvent e) {
int xRel = e.getX();
int yRel = e.getY();
}
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
int deskNum = Client.currUser.getDesk();
int site = Client.currUser.getSite();
try{
PrintStream p = new PrintStream(Client.s.getOutputStream());
p.println("退出"+"拆"+deskNum+"拆"+site+"拆"+
Client.currUser.getUserName()+"拆"+"退出");
}catch (Exception ex){
ex.printStackTrace();
}
//修改在服务器列表中的消息
for (User uu : Client.onlineUser){
if(uu.getUserName().equals(Client.currUser.getUserName())){
uu.setDesk(0);
uu.setSite(0);
break;
}
}
//Room.isLive[deskNum - 1] = false;
int x = (deskNum+5)%6;
int y = (deskNum-1) /6;
Room.siteCondition[x][y][site - 1] = 0;
Client.currUser.setDesk(0);
Client.currUser.setSite(0);
Client.parter.clear();
Ddz.ready = new boolean[4];
ClientThread.room.setVisible(true);
//frame.setVisible(false);
ClientThread.tuiChu=false;
}
public void mouseDragged(MouseEvent arg0) {}
public void windowActivated(WindowEvent arg0) {}
public void windowClosed(WindowEvent arg0) {}
public void windowDeactivated(WindowEvent arg0) {}
public void windowDeiconified(WindowEvent arg0) {}
public void windowIconified(WindowEvent arg0) {}
public void windowOpened(WindowEvent arg0) {}
}


DeskPanel

import javax.imageio.*;
import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import ds.*;
public class DeskPanel extends JPanel{
int x,y;
BufferedImage desk;
BufferedImage select;
public DeskPanel(){
try {
desk=ImageIO.read(new File("ico/deskPane/desk.bmp"));
select=ImageIO.read(new File("ico/deskPane/select.png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void getPos(int x,int y){
this.x=x;
this.y=y;
}
public void paint(Graphics g){
super.paint(g);
for(int i=0;i<6;i++){
for(int j=0;j<6;j++){
g.drawImage(desk, j*150, i*150, null);
}
}
//画"选择图片"
if (x != 0 && y != 0) {
g.drawImage(select, x, y, null);
x = 0 ;
y = 0;
}
//画坐下的
for(User uu:Client.onlineUser){
int desk=uu.getDesk();
if(desk!=0){
int site=uu.getSite();
int xPos=(desk+5)%6*150;
int yPos=(desk-1)/6*150;
//int xPos=(desk%6-1)*150;
//int yPos=(desk/6)-1*150;
int xName = 0;
int yName=0;
switch(site){
case 1:
xPos+=60;
yPos+=5;
xName=xPos+30;
yName=yPos+30;
break;
case 2:
xPos+=5;
yPos+=40;
xName=xPos;
yName=yPos+45;
break;
case 3:
xPos+=60;
yPos+=90;
xName=xPos+30;
yName=yPos+30;
break;
case 4:
xPos+=110;
yPos+=40;
xName=xPos;
yName=yPos+45;
break;
}
g.drawImage(select, xPos, yPos, null);
g.setColor(Color.white);
g.setFont(new Font("宋体",Font.BOLD,15));
g.drawString(uu.getUserName(), xName, yName);
}
}
}
}


PokeAnalyze


import ds.*;
import java.util.*;

public class PokeAnalyze{
//炸弹 --- 四条 一对鬼
static final int BOOM = 2;
//飞机 --- 连着的三不带
static final int PLANE = 3;
//顺子
static final int SHUNZI = 4;
//连对
static final int CONN_PAIR = 5;
//四条带两个
static final int FOUR_TWO = 6;
//三带
static final int THREE = 7;
//一对
static final int PAIR = 8;
//一个
static final int SINGAL = 9;
//用于记录每种牌型中的主牌
//比如顺子就记录最大的牌
private Poke bigPoke = new Poke();
//记录牌型
private int type = 0;
//记录牌的长度
private int num = 0;
//初始化数据
List<Poke> poke;

public PokeAnalyze(List<Poke> poke){
this.poke = poke;
init();
}
public PokeAnalyze(){}
private void init(){
num = 0;
type = 0;
bigPoke = new Poke();
}
public Poke getBigPoke(){
return bigPoke;
}
public int getType(){
return type;
}
public int getNum(){
return num;
}
//返回是否符合规则,如果符合,保存主牌 和 牌型
public boolean analyze(){
int size = poke.size();
switch(size){
case 0 :
return false;
//一张牌
case 1:
type = SINGAL;
bigPoke = poke.get(0);
num = size;
return true;
//两张牌
case 2:
if(isPair()){
num = size;
bigPoke = poke.get(0);
return true;
}else
return false;
//三不带
case 3:
if(isSame(poke)){
num = size;
bigPoke = poke.get(0);
type = THREE;
return true;
}
return false;
case 4:
if (isBoom()){
bigPoke = poke.get(0);
num = size;
type = BOOM;
return true;
}else if (isThree(size)){
//是否三带一
num = size;
type = THREE;
return true;
}else if(isShunZi()){
//是否是顺子
num = size;
type = SHUNZI;
return true;
}else if(isConn_Pair(size)){
//连对
num = size;
type = CONN_PAIR;
return true;
}else
return false;
case 5:
//是否三条带一对
//if(isThree(size))
//{
//num = size;
//type = THREE;
//return true;
//}
//else
//是否是顺子
if(isShunZi()){
num = size;
type = SHUNZI;
return true;
}else
return false;
case 6:
//是否是顺子
if (isShunZi()){
num = size;
type = SHUNZI;
return true;
}
else
//四条带一对
if(isFour_Two(size)){
num = size;
type = FOUR_TWO;
return true;
}
//连对
else if(isConn_Pair(size)){
num = size;
type = CONN_PAIR;
return true;
}else
//不带牌的飞机
if(isSame(poke.subList(0,3)) && isSame(poke.subList(3,6))){
num = size;
type = PLANE;
bigPoke = poke.get(3);
return true;
}else
return false;
//是否是3连对

case 8 :
//四条带两对
//if(isFour_Two(size)){
//num = size;
//type = FOUR_TWO;
//return true;
//}else
//四连对
if(isConn_Pair(size)){
num = size;
type = CONN_PAIR;
return true;
}
//顺子
else if(isShunZi()){
num = size;
type = SHUNZI;
return true;
}else
// 飞机 (个)
if(isPlane(size)){
num = size;
type = PLANE;
return true;
}else
return false;
case 10 :
if(isShunZi()){
num = size;
type = SHUNZI;
return true;
}
//else if(isPlane(size)){
//num = size;
//type = PLANE;
//return true;
//}
else
return false;
case 7 :
case 9 :
case 11 :
case 12 :
if(isShunZi()){
num = size;
type = SHUNZI;
return true;
}
//多连对
if(isConn_Pair(size)){
num = size;
type = CONN_PAIR;
return true;
}else
return false;
//else
//if()
//{}
//是否是四条带两对
}
return true;
}
//对子
private boolean isPair(){
//一对鬼 或者 对子
if(poke.get(0).getPokeNum() == poke.get(1).getPokeNum()){
if(poke.get(0).getPokeNum() == 13)
type = BOOM;
else
type = PAIR;
return true;
}else
return false;
}
//检查是否相同
private boolean isSame(List<Poke> poke){
int pokeNum = poke.get(0).getPokeNum();
for (int i = 1 ; i < poke.size() ; i++){
if(pokeNum != poke.get(i).getPokeNum())
return false;
}
return true;
}
//炸弹
private boolean isBoom(){
return isSame(poke);
}
//三带一
private boolean isThree(int size){
int tmp = poke.get(0).getPokeNum();
//三条带一个
//if(size == 4){
boolean flag = isSame(poke.subList(0,3));
if(flag){
bigPoke = poke.get(0);
return true;
}else{
flag = isSame(poke.subList(1,4));
if(flag){
bigPoke = poke.get(1);
return true;
}else
return false;
}
//}
//else{
//boolean flag1 = isSame(poke.subList(0,3));
//boolean flag2 = isSame(poke.subList(3,5));
//if(flag1 && flag2){
//bigPoke = poke.get(0);
//return true;
//}else{
//flag1 = isSame(poke.subList(0,2));
//flag2 = isSame(poke.subList(2,5));
//if(flag1 && flag2){
//bigPoke = poke.get(2);
//return true;
//}else
//return false;
//}
//}
}
// 顺子(2 与 鬼不能作为顺子)
private boolean isShunZi(){
int size = poke.size();
Poke p = poke.get(size - 1);
if(p.getPokeNum() < 12 && poke.get(0).getPokeNum() + size - 1 == p.getPokeNum()){
bigPoke = poke.get(size -1);
return true;
}else
return false;
}
// 四带二
private boolean isFour_Two(int size){
//if(size == 6){
boolean flag1 = isSame(poke.subList(0,4));
boolean flag2 = isSame(poke.subList(1,5));
boolean flag3 = isSame(poke.subList(2,6));
if(flag1){
bigPoke = poke.get(0);
}else if(flag2)
{
bigPoke = poke.get(1);
}else if(flag3){
bigPoke = poke.get(2);
}else
return false;
return true;
//}
//else{
//boolean flag1 = isSame(poke.subList(0,4));
//boolean flag2 = isSame(poke.subList(2,6));
//boolean flag3 = isSame(poke.subList(4,8));
//
//if(flag1 && isSame(poke.subList(4,6)) && isSame(poke.subList(6,8))){
//bigPoke = poke.get(0);
//return true;
//}else if(flag2 && isSame(poke.subList(0,2)) && isSame(poke.subList(6,8)))
//{
//bigPoke = poke.get(2);
//return true;
//}else if(flag3 && isSame(poke.subList(0,2)) && isSame(poke.subList(2,4)))
//{
//bigPoke = poke.get(4);
//return true;
//}else
//return false;
//}
}
//判断是否连对
private boolean isConn_Pair(int size){
boolean flag = true;
//判断是否是都是一对一对的
for (int i= 0; i < size/2 ; i++){
flag = flag && isSame(poke.subList(i*2,i*2+2));
}
if(flag){
if(poke.get(0).getPokeNum() == poke.get(size - 1).getPokeNum() - size/2 +1
&& poke.get(size -1).getPokeNum() < 12)
{
bigPoke = poke.get(size - 1);
return true;
}else
return false;
}else
return false;
}
//飞机
private boolean isPlane(int size){
//if(size == 8){
boolean flag1 = isSame(poke.subList(0,3));
boolean flag2 = isSame(poke.subList(3,6));
if(flag1 && flag2 &&
poke.get(0).getPokeNum() + 1 == poke.get(3).getPokeNum()
&& poke.get(3).getPokeNum() < 12)
{
bigPoke = poke.get(3);
return true;
}
flag1 = isSame(poke.subList(1,4));
flag2 = isSame(poke.subList(4,7));
if(flag1 && flag2 &&
poke.get(1).getPokeNum() + 1 == poke.get(4).getPokeNum()
&& poke.get(4).getPokeNum() < 12)
{
bigPoke = poke.get(4);
return true;
}
flag1 = isSame(poke.subList(2,5));
flag2 = isSame(poke.subList(5,8));
if(flag1 && flag2 &&
poke.get(2).getPokeNum() + 1 == poke.get(5).getPokeNum()
&& poke.get(5).getPokeNum() < 12)
{
bigPoke = poke.get(5);
return true;
}
return false;
//}
//else{
//boolean flag1 = isSame(poke.subList(0,3));
//boolean flag2 = isSame(poke.subList(3,6));
//boolean flag3 = isSame(poke.subList(6,8));
//boolean flag4 = isSame(poke.subList(8,10));
//if(flag1 && flag2 && flag3 && flag4 &&
//poke.get(0).getPokeNum() + 1 == poke.get(3).getPokeNum())
//{
//bigPoke = poke.get(3);
//return true;
//}
//flag1 = isSame(poke.subList(0,2));
//flag2 = isSame(poke.subList(2,5));
//flag1 = isSame(poke.subList(5,8));
//flag2 = isSame(poke.subList(8,10));
//if(flag1 && flag2 && flag3 && flag4 &&
//poke.get(2).getPokeNum() + 1 == poke.get(5).getPokeNum())
//{
//bigPoke = poke.get(5);
//return true;
//}
//flag1 = isSame(poke.subList(0,2));
//flag2 = isSame(poke.subList(2,4));
//flag1 = isSame(poke.subList(4,7));
//flag2 = isSame(poke.subList(7,10));
//if(flag1 && flag2 && flag3 && flag4 &&
//poke.get(4).getPokeNum() + 1 == poke.get(7).getPokeNum())
//{
//bigPoke = poke.get(7);
//return true;
//}
//return false;
//}
//else
//if(size == 12)
//{
//for(int i = 0; i< 3 ;i ++)
//{
//flag = isSame(poke.subList(i,i+3));
//if (flag)
//{
//break;
//}
////if(flag)
//}
//}
}
public String toString(){
return "type = " + type + " bigPoke = "+bigPoke;
}
public static void main(String[] args){
ArrayList<Poke> list = new ArrayList();
Poke poke = new Poke(1,0);
list.add(poke);
poke = new Poke(1,0);
list.add(poke);
poke = new Poke(2,0);
list.add(poke);
poke = new Poke(2,0);
list.add(poke);
poke = new Poke(2,0);
list.add(poke);
poke = new Poke(3,0);
list.add(poke);
poke = new Poke(3,0);
list.add(poke);
poke = new Poke(3,0);
list.add(poke);
PokeAnalyze po = new PokeAnalyze(list);
if(po.analyze()){
System.out.println("true");
System.out.println(po);
}else
System.out.println("false");
}
}


Room

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import ds.*;
public class Room extends JFrame implements MouseListener,MouseMotionListener{
DeskPanel dp;
static Ddz ddz;
static int siteCondition[][][]=new int[6][6][4];
public static void main(String[] args) {
new Room();
}
public Room(){
dp=new DeskPanel();
dp.addMouseListener(this);
dp.addMouseMotionListener(this);
this.add(dp);
this.setTitle("游戏房间");
this.setSize(900, 700);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
@Override
public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub
int x=e.getX();
int y=e.getY();
check(x,y);
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
int x=e.getX();
int y=e.getY();
int temp=check(x,y);
if(temp!=-1){
int desk=x/150+y/150*6;
this.siteCondition[x/150][y/150][temp]=1;
Client.currUser.setDesk(desk+1);
Client.currUser.setSite(temp+1);
//加入同桌
Client.parter.add(Client.currUser);
//找有没有和自己同桌
for(User uu:Client.onlineUser){
if(uu.getDesk()==Client.currUser.getDesk()
&&!uu.getUserName().equals(Client.currUser.getUserName())){
Client.parter.add(uu);
}
}
for(User uu:Client.parter){
int s=uu.getSite();
}
PrintStream ps;
try {
ps = new PrintStream(Client.s.getOutputStream());
ps.println("坐下" + "拆"
+ Client.currUser.getUserName() + "拆"
+ Client.currUser.getDesk() + "拆"
+ Client.currUser.getSite() + "拆" + "坐下");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ddz=new Ddz();
this.setVisible(false);
}
}
public int check(int x,int y){
int X=x/150*150;
int Y=y/150*150;
for(int i=0;i<4;i++){
//如果该位置上有人,则不判断
//if(this.siteCondition[x/150][y/150][i]!=0)
//continue;
if(siteCondition[x/150][y/150][i] != 0)
continue;
Point p=getPoint(X,Y,i);
if(x>=p.getX()&&x<=p.getX()+30&&y>=p.getY()&&y<=p.getY()+30){
dp.setCursor(new Cursor(Cursor.HAND_CURSOR));
dp.getPos((int)p.getX(), (int)p.getY());
dp.repaint();
return i;
}else{
dp.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
dp.getPos(0,0);
dp.repaint();
}
}
return -1;
}
public Point getPoint(int x,int y,int i){
switch(i){
case 0:
return new Point(x+60,y+5);
case 1:
return new Point(x+5,y+40);
case 2:
return new Point(x+60,y+90);
case 3:
return new Point(x+110,y+40);
}
return null;
}
public void mouseEntered(MouseEvent arg0) {}
public void mouseExited(MouseEvent arg0) {}
public void mousePressed(MouseEvent arg0) {}
public void mouseReleased(MouseEvent arg0) {}
public void mouseDragged(MouseEvent arg0) {}
}

 

DdzArea

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.image.*;
import java.awt.*;
import java.io.*;
import ds.*;
public class DdzArea extends JPanel{
 BufferedImage backGround;
 BufferedImage playerBack;
 BufferedImage playerImage;
 BufferedImage[] start;
 BufferedImage ready;
 BufferedImage poke[][];
 BufferedImage back;
 BufferedImage three[];
 BufferedImage bj[];
 BufferedImage cp[];
 BufferedImage bc[];
 BufferedImage bcz;
 BufferedImage dz;
 int x,y;
 static boolean showPoke;
 static boolean daShow;
 String pokeValue[]={"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
 public DdzArea(){
  try {
   backGround=ImageIO.read(new File("ico/ddz/background.png"));
   playerBack=ImageIO.read(new File("ico/ddz/playerBack.png"));
   playerImage=ImageIO.read(new File("ico/ddz/player/1_g.gif"));
   start = new BufferedImage[2];
   for (int i = 0; i<2 ;i++ )
   {
    start[i] = ImageIO.read(new File("ico/ddz/start"+i+".png"));
   }
   ready = ImageIO.read(new File("ico/ddz/ready.png"));
   poke=new BufferedImage[13][4];
   for(int i=0;i<13;i++){
    for(int j=0;j<4;j++){
     poke[i][j]=ImageIO.read(new File("ico/ddz/poke/"+pokeValue[i]+j+".GIF"));
    }
   }
   back = ImageIO.read(new File("ico/ddz/poke/back.gif"));
   three=new BufferedImage[2];
   for(int i=0;i<2;i++){
    three[i]=ImageIO.read(new File("ico/ddz/three"+i+".png"));
   }
   bj=new BufferedImage[2];
   for(int i=0;i<2;i++){
    bj[i]=ImageIO.read(new File("ico/ddz/bj"+i+".png"));
   }
   cp=new BufferedImage[2];
   for(int i=0;i<2;i++){
    cp[i]=ImageIO.read(new File("ico/ddz/cp"+i+".png"));
   }
   bc=new BufferedImage[2];
   for(int i=0;i<2;i++){
    bc[i]=ImageIO.read(new File("ico/ddz/bc"+i+".png"));
   }
   bcz = ImageIO.read(new File("ico/ddz/bcz.png"));
   dz = ImageIO.read(new File("ico/ddz/dz.png"));
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
 public void setPos(int x,int y){
  this.x=x;
  this.y=y;
  this.repaint();
 }
 public void paint(Graphics g){
  super.paint(g);
  g.drawImage(backGround, 0, 0, null);
  //游戏没有开始
  if(!Client.game.isStart()){
   g.drawImage(playerBack, 320, 40, null);//上
   g.drawImage(playerBack, 320, 400, null);//下
   g.drawImage(playerBack, 140, 220, null);//左
   g.drawImage(playerBack, 500, 220, null);//右
   //画用户
   for(User uu:Client.parter){
    int site=uu.getSite();
    Point p=getSite(site);
    g.drawImage(playerImage, (int)p.getX(), (int)p.getY(), null);
    g.setColor(Color.white);
    g.setFont(new Font("宋体",Font.BOLD,15));
    g.drawString(uu.getUserName(), (int)p.getX(), (int)p.getY()+200);
   }
   //画准备
   for(int i=0;i<4;i++){
    Point pp=getSite(i+1);
    if(Ddz.ready[i]){
     g.drawImage(ready, (int)pp.getX()+50, (int)pp.getY()+100, null);
    }
   }
   //如果没准备
   if(!Client.game.isReady()){
    int site=Client.currUser.getSite();
    Point p=getSite(site);
    //监听开始按钮
    if(x>=570&&x<=630&&y>=550&&y<=580){
     g.drawImage(start[0], (int)p.getX()+250, (int)p.getY()+150,null);
    }else{
     g.drawImage(start[1], (int)p.getX()+250, (int)p.getY()+150,null);
    }
   }
  }
  //游戏开始了
  else{
   //画游戏人物
   for(User uu:Client.parter){
    int site=uu.getSite();
    Point p=getSite(site);
    int x=(int)p.getX();
    int y=(int)p.getY();
    if(x==320&&y==400){
     x = 80;
     y = 530;
    }else if(x==500){
     x = 690;
     y = 200;
    }else if(x==320&&y==40){
     x = 80;
     y = 10;
    }else{
     x = 0;
     y = 200;
    }
    g.drawImage(playerImage, x, y, null);
    g.setColor(Color.white);
    g.setFont(new Font("宋体",Font.BOLD,15));
    g.drawString(uu.getUserName(), x+30, y+175);
   }
   //地主还没有确定
   if(Client.game.getDdzName() == null){
    //底牌背面
    for(int i=0;i<4;i++){
     g.drawImage(back, 700+16*i, 0, null);
    }
    //画叫地主按钮
    if(Client.game.getOrder()==Client.currUser.getSite()){
     //三分
     if(x==(int)Ddz.THREE_BN.getX()&&y==(int)Ddz.THREE_BN.getY()){
      g.drawImage(three[1], (int)Ddz.THREE_BN.getX(), (int)Ddz.THREE_BN.getY(), null);
     }else{
      g.drawImage(three[0], (int)Ddz.THREE_BN.getX(), (int)Ddz.THREE_BN.getY(), null);
     }
     //不叫
     if(x == (int)Ddz.BJ_BN.getX() && y == (int)Ddz.BJ_BN.getY()){
      g.drawImage(bj[1], (int)Ddz.BJ_BN.getX(), (int)Ddz.BJ_BN.getY(), null);
     }else{
      g.drawImage(bj[0], (int)Ddz.BJ_BN.getX(), (int)Ddz.BJ_BN.getY(), null);
     }
     
    }
   }else{//确定了地主
    //画底牌
    for(int i=0;i<4;i++){
     Poke p=Client.game.getBottomPoke().get(i);
     g.drawImage(poke[p.getPokeNum()][p.getPokeColor()], 700+16*i, 0, null);
    }
    //画地主头像
    int playerSite = 0;
    playerSite = Client.parter.get(Client.parter.indexOf(new User(Client.game.getDdzName()))).getSite();
    Point pt = getSite(playerSite);
    int x = (int)pt.getX();
    int y = (int)pt.getY();
    if(x == 320&&y==400)
     g.drawImage(dz,50,550,null);
    else if(x == 500&&y==220)
     g.drawImage(dz,780,200,null);
    else if(x==320&&y==40)
     g.drawImage(dz,200,50,null);
    else if(x==140&&y==220)
     g.drawImage(dz,80,200,null);
    //画出牌,不出
    if(Client.game.getOrder()==Client.currUser.getSite()){
     
     if((Client.game.getTurnBanker()==Client.game.getOrder()&& Ddz.hatPut == 0)
       ||(Client.game.getTurnBanker()==Client.game.getOrder()&& daShow)){
      if(x==(int)Ddz.CP_BN2.getX()&&y==(int)Ddz.CP_BN2.getY()){
       g.drawImage(cp[0], (int)Ddz.CP_BN2.getX() , (int)Ddz.CP_BN2.getY(),null);
      }else{
       g.drawImage(cp[1], (int)Ddz.CP_BN2.getX() , (int)Ddz.CP_BN2.getY(),null);
      }
     }else{
      if(x==(int)Ddz.CP_BN2.getX()&&y==(int)Ddz.CP_BN2.getY()){
       g.drawImage(cp[0], (int)Ddz.CP_BN2.getX() , (int)Ddz.CP_BN2.getY(),null);
      }else{
       g.drawImage(cp[1], (int)Ddz.CP_BN2.getX() , (int)Ddz.CP_BN2.getY(),null);
      }
      //不出
      if(x==(int)Ddz.BC_BN.getX()&&y==(int)Ddz.BC_BN.getY()){
       g.drawImage(bc[0], (int)Ddz.BC_BN.getX() , (int)Ddz.BC_BN.getY(),null);
      }else{
       g.drawImage(bc[1], (int)Ddz.BC_BN.getX() , (int)Ddz.BC_BN.getY(),null);
      }
     }
    }
    //画用户出的牌
    int site = Client.currUser.getSite();
    //上家
    int preSite;
    if(site - 1 == 0)
     preSite = 4;
    else
     preSite = site - 1;
    //下家
    int backSite;
    if(site  == 4)
     backSite = 1;
    else
     backSite = site + 1;
    //下下家
    int backbackSite;
    if(backSite  == 4)
     backbackSite = 1;
    else
     backbackSite = backSite + 1;
    ////////////////////
//    if(Client.game.getOrder() == Client.currUser.getSite()){
//     for(int i=0;i<4;i++){
//      Point p=getSite(i+1);
//      int xPoke=0;
//      int yPoke=0;
//      xPoke=(int)p.getX();
//      yPoke=(int)p.getY();
//      if(xPoke==320&&yPoke==400){
//       
//      }
//      if(i!=Client.currUser.getSite()){
//       
//      }
//      
//     }
//    }else{
//     
//    }
    ////////////////////
    if(this.showPoke){
     if(Client.game.getOrder() == Client.currUser.getSite()){
      //上家的牌
      if(Ddz.hatPut == 1){
       int size = Ddz.turnPoke[preSite - 1].size();
       for (int i=0; i < size ; i++){
        Poke pk = Ddz.turnPoke[preSite - 1].get(i);
        g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
         210+i*15,230,null);
       }
      }else if(Ddz.hatPut == 2){
       //上家的牌
       int size = Ddz.turnPoke[preSite - 1].size();
       if(size == 0){
        g.drawImage(bcz,210,260,null);
       }else{
        for (int i=0; i < size ; i++)
        {
         Poke pk = Ddz.turnPoke[preSite - 1].get(i);
         g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
          210+i*15,230,null);
        }
       }
       //下下家
       size = Ddz.turnPoke[backbackSite - 1].size();
       if(size == 0){
        g.drawImage(bcz,370,150,null);
       }else{
        int length = 71 + 15 * (size -1);
        int xStart = (816 - length)/2;
        for (int i=0; i < size  ; i++){
         Poke pk = Ddz.turnPoke[backbackSite - 1].get(i);
         g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
          xStart + i * 15,150,null);
        }
       }
      }else{
       //上家的牌
       int size = Ddz.turnPoke[preSite - 1].size();
       if(size == 0){
        g.drawImage(bcz,210,260,null);
       }else{
        for (int i=0; i < size ; i++)
        {
         Poke pk = Ddz.turnPoke[preSite - 1].get(i);
         g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
          210+i*15,230,null);
        }
       }
       //下家的牌
       size = Ddz.turnPoke[backSite - 1].size();
       if(size == 0){
        g.drawImage(bcz,540,260,null);
       }else{
        int length = 71 + 15 * (size -1);
        int xStart = 610 - length;
        for (int i=0; i < size ; i++){
         Poke pk = Ddz.turnPoke[backSite - 1].get(i);
         g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
          xStart + i * 15,230,null);
        }
       }
       //下下家
       size = Ddz.turnPoke[backbackSite - 1].size();
       if(size == 0){
        g.drawImage(bcz,370,150,null);
       }else{
        int length = 71 + 15 * (size -1);
        int xStart = (816 - length)/2;
        for (int i=0; i < size  ; i++){
         Poke pk = Ddz.turnPoke[backbackSite - 1].get(i);
         g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
          xStart + i * 15,150,null);
        }
       }
      }
     }else{
      //不轮到自己
      if(Ddz.hatPut == 1){
       //这个时候是自己先出牌的,所以只画自己出的牌
       if(Client.game.getTurnBanker() == Client.currUser.getSite()){
        int size = Client.game.poke.size();
        int length = 71 + 15 * (size -1);
        int xStart = (816 - length)/2;
        for (int j = size -1;j >=0 ; j--){
         Poke pk = Client.game.poke.get(j);
         g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
           xStart + ( size -1 - j) *15,550 - 140 ,null);
        }
       }else{//不是自己的turnBanker 那就是其他人出的牌
        Point point = getSite(Client.game.getTurnBanker());
        int posX = (int)point.getX();
        int posY = (int)point.getY();
        if(posX == 140){
         int size = Ddz.turnPoke[preSite- 1].size();
         for (int i=0; i < size ; i++){
          Poke pk = Ddz.turnPoke[preSite- 1].get(i);
          g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
           210+i*15,230,null);
         }
        }else if(posX == 500){
         int size = Ddz.turnPoke[backSite - 1].size();
         int length = 71 + 15 * (size -1);
         int xStart = 610 - length;
         for (int i=0; i < size  ; i++){
          Poke pk = Ddz.turnPoke[backSite - 1].get(i);
          g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
           xStart + i * 15,240,null);
         }
        }else if(posX == 320&&posY==40){
         int size = Ddz.turnPoke[backbackSite - 1].size();
         int length = 71 + 15 * (size -1);
         int xStart = (816 - length)/2;
         for (int i=0; i < size  ; i++){
          Poke pk = Ddz.turnPoke[backbackSite - 1].get(i);
          g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
           xStart + i * 15,150,null);
         }
        }
       }
      }else if(Ddz.hatPut == 2){
       //hatPut是2
       int size = Ddz.turnPoke[site - 1].size();
       //另外一家的牌
       //如果轮到下家,则画上家的牌,自己家的牌
       if (Client.game.getOrder() == backSite){
        //自己
        if(size == 0){
         g.drawImage(bcz,370,450,null);
        }else{
         int length = 71 + 15 * (size -1);
         int xStart = (816 - length)/2;
         for (int j = size -1;j >=0 ; j--){
          Poke pk = Ddz.turnPoke[site - 1].get(j);
          g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
            xStart + ( size -1 - j) *15,550 - 140 ,null);
         }
        }
        //上家
        size = Ddz.turnPoke[preSite-1].size();
        if(size == 0){
         g.drawImage(bcz,210,260,null);
        }else{
         for (int i=0; i < size ; i++){
          Poke pk = Ddz.turnPoke[preSite- 1].get(i);
          g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
           210+i*15,230,null);
         }
        }
       }
       //如果轮到上家,画下家,下下家
       else if(Client.game.getOrder() == preSite){
        //下家
        size = Ddz.turnPoke[backSite-1].size();
        if(size == 0){
         g.drawImage(bcz,540,260,null);
        }else{
         int length = 71 + 15 * (size -1);
         int xStart = 610 - length;
         for (int i=0; i < size  ; i++){
          Poke pk = Ddz.turnPoke[backSite - 1].get(i);
          g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
           xStart + i * 15,230,null);
         }
        }
        //下下家
        size = Ddz.turnPoke[backbackSite-1].size();
        if(size == 0){
         g.drawImage(bcz,370,150,null);
        }else{
         int length = 71 + 15 * (size -1);
         int xStart = (816 - length)/2;;
         for (int i=0; i < size  ; i++){
          Poke pk = Ddz.turnPoke[backbackSite - 1].get(i);
          g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
           xStart + i * 15,150,null);
         }
        }
       }//轮到下下家,画自己家,下家
       else if(Client.game.getOrder() == backbackSite){
        //自己
        if(size == 0){
         g.drawImage(bcz,370,450,null);
        }else{
         int length = 71 + 15 * (size -1);
         int xStart = (816 - length)/2;
         for (int j = size -1;j >=0 ; j--){
          Poke pk = Ddz.turnPoke[site - 1].get(j);
          g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
            xStart + ( size -1 - j) *15,550 - 140 ,null);
         }
        }
        //下家
        size = Ddz.turnPoke[backSite-1].size();
        if(size == 0){
         g.drawImage(bcz,540,260,null);
        }else{
         int length = 71 + 15 * (size -1);
         int xStart = 610 - length;
         for (int i=0; i < size  ; i++){
          Poke pk = Ddz.turnPoke[backSite - 1].get(i);
          g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
           xStart + i * 15,230,null);
         }
        }
       }
      }else{
       //hatPut是3,画自己的牌
       int size = Ddz.turnPoke[site - 1].size();
       if(size == 0){
        g.drawImage(bcz,370,450,null);
       }else{
        int length = 71 + 15 * (size -1);
        int xStart = (816 - length)/2;
        for (int j = size -1;j >=0 ; j--){
         Poke pk = Ddz.turnPoke[site - 1].get(j);
         g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
           xStart + ( size -1 - j) *15,550 - 140 ,null);
        }
       }
       //另外一家的牌
       //如果轮到下家,则画上家的牌,下下家的牌
       if (Client.game.getOrder() == backSite){
        //上家
        size = Ddz.turnPoke[preSite-1].size();
        if(size == 0){
         g.drawImage(bcz,210,260,null);
        }else{
         for (int i=0; i < size ; i++){
          Poke pk = Ddz.turnPoke[preSite- 1].get(i);
          g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
           210+i*15,230,null);
         }
        }
        //下下家
        size = Ddz.turnPoke[backbackSite-1].size();
        if(size == 0){
         g.drawImage(bcz,370,150,null);
        }else{
         int length = 71 + 15 * (size -1);
         int xStart = (816 - length)/2;;
         for (int i=0; i < size  ; i++){
          Poke pk = Ddz.turnPoke[backbackSite - 1].get(i);
          g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
           xStart + i * 15,150,null);
         }
        }
       }
       //如果轮到上家,画下家,下下家
       else if(Client.game.getOrder() == preSite){
        //下家
        size = Ddz.turnPoke[backSite-1].size();
        if(size == 0){
         g.drawImage(bcz,540,260,null);
        }else{
         int length = 71 + 15 * (size -1);
         int xStart = 610 - length;
         for (int i=0; i < size  ; i++){
          Poke pk = Ddz.turnPoke[backSite - 1].get(i);
          g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
           xStart + i * 15,230,null);
         }
        }
        //下下家
        size = Ddz.turnPoke[backbackSite-1].size();
        if(size == 0){
         g.drawImage(bcz,370,150,null);
        }else{
         int length = 71 + 15 * (size -1);
         int xStart = (816 - length)/2;;
         for (int i=0; i < size  ; i++){
          Poke pk = Ddz.turnPoke[backbackSite - 1].get(i);
          g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
           xStart + i * 15,150,null);
         }
        }
       }//轮到下下家,画上家,下家
       else if(Client.game.getOrder() == backbackSite){
        //上家
        size = Ddz.turnPoke[preSite-1].size();
        if(size == 0){
         g.drawImage(bcz,210,260,null);
        }else{
         for (int i=0; i < size ; i++){
          Poke pk = Ddz.turnPoke[preSite- 1].get(i);
          g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
           210+i*15,230,null);
         }
        }
        //下家
        size = Ddz.turnPoke[backSite-1].size();
        if(size == 0){
         g.drawImage(bcz,540,260,null);
        }else{
         int length = 71 + 15 * (size -1);
         int xStart = 610 - length;
         for (int i=0; i < size  ; i++){
          Poke pk = Ddz.turnPoke[backSite - 1].get(i);
          g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
           xStart + i * 15,230,null);
         }
        }
       }
      }
     }
    }
   }
   //画用户的牌
   for(int i=0;i<4;i++){
    Point pp=getSite(i+1);
    int yStart=0;
    int xStart=0;
    int xPoke=0;
    int yPoke=0;
    xPoke=(int)pp.getX();
    yPoke=(int)pp.getY();
    if(i!=Client.currUser.getSite()-1){
     int length2=71+15*(Ddz.count[i]-1);
     xStart=(816-length2)/2;
     int length=96+15*(Ddz.count[i]-1);
     yStart=(700-length)/2;
    }else{
     int length=71+15*(Client.game.getCurrentPoke().size()-1);
     xStart=(816-length)/2;
    }
    //自己的牌
    if(xPoke==320&&yPoke==400){
     int num=Client.game.getCurrentPoke().size();
     for(int j=num-1;j>=0;j--){
      Poke pk = Client.game.getCurrentPoke().get(j);
      if(Ddz.pokePop[j]){
       g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
         xStart+(num-1-j)*15,550-20,null);
      }else{
       g.drawImage(poke[pk.getPokeNum()][pk.getPokeColor()],
         xStart+(num-1-j)*15,550,null);
      }
     }
    }else if(xPoke==500){//下家的牌
     for(int j=0;j<Ddz.count[i];j++){
      g.drawImage(back, 620, yStart+16*j, null);
     }
    }else if(xPoke==320&&yPoke==40){//下下家的牌
     for(int j=0;j<Ddz.count[i];j++){
      g.drawImage(back, xStart+(Ddz.count[i]-1-j) *15, 10, null);
     }
    }else{//上家的牌
     for(int j=0;j<Ddz.count[i];j++){
      g.drawImage(back, 130, yStart+16*j, null);
     }
    }
   }
  }
 }
 //座位信息
 public Point getSite(int site){
  int ss=Client.currUser.getSite();
  if(ss==1){
   switch(site){
   case 1:
    return new Point(320,400);
   case 2:
    return new Point(500,220);
   case 3:
    return new Point(320,40);
   case 4:
    return new Point(140,220);
   }
  }else if(ss==2){
   switch(site){
   case 1:
    return new Point(140, 220);
   case 2:
    return new Point(320,400);
   case 3:
    return new Point(500, 220);
   case 4:
    return new Point(320, 40);
   }
  }else if(ss==3){
   switch(site){
   case 1:
    return new Point(320,40);
   case 2:
    return new Point(140, 220);
   case 3:
    return new Point(320,400);
   case 4:
    return new Point(500, 220);
   }
  }else{
   switch(site){
   case 1:
    return new Point(500, 220);
   case 2:
    return new Point(320, 40);
   case 3:
    return new Point(140, 220);
   case 4:
    return new Point(320,400);
   }
  }
  return null;
 }
}


以下放在ds包下

Game

package ds;
import java.util.*;
public class Game {
//用户名
String userName;
private boolean isStart=false;
boolean isReady = false;
public static ArrayList<Poke> bottomPoke=new ArrayList<Poke>(4);
//玩家手上牌的信息
public static ArrayList<Poke> currentPoke = new ArrayList<Poke>();
//当前轮的牌
public static ArrayList<Poke> poke = new ArrayList<Poke>();
String ddzName;
int order;
int turnBanker = 0;
public Game() {}
public Game(String userName) {
this.userName=userName;
}
public int getTurnBanker() {
return turnBanker;
}
public void setTurnBanker(int turnBanker) {
this.turnBanker = turnBanker;
}
public int getOrder() {
return order;
}
public void setOrder(int order) {
this.order = order;
}
public String getDdzName() {
return ddzName;
}
public void setDdzName(String ddzName) {
this.ddzName = ddzName;
}
public ArrayList<Poke> getCurrentPoke() {
return currentPoke;
}
public void setCurrentPoke(ArrayList<Poke> currentPoke) {
this.currentPoke = currentPoke;
}
public ArrayList<Poke> getBottomPoke() {
return bottomPoke;
}
public void setBottomPoke(ArrayList<Poke> bottomPoke) {
this.bottomPoke = bottomPoke;
}
public boolean isReady() {
return isReady;
}
public void setReady(boolean isReady) {
this.isReady = isReady;
}
public boolean isStart() {
return isStart;
}
public void setStart(boolean isStart) {
this.isStart = isStart;
}
}


 Poke

package ds;

public class Poke implements Comparable{
int pokeNum;
int pokeColor;
public Poke(){}
public Poke(int pokeNum,int pokeColor){
this.pokeColor=pokeColor;
this.pokeNum=pokeNum;
}
public int getPokeNum() {
return pokeNum;
}
public void setPokeNum(int pokeNum) {
this.pokeNum = pokeNum;
}
public int getPokeColor() {
return pokeColor;
}
public void setPokeColor(int pokeColor) {
this.pokeColor = pokeColor;
}
public String toString(){
return pokeNum+"分"+pokeColor;
}
public boolean equals(Object obj)
{
if(obj == this)
return true;
if(obj != null && obj.getClass() == Poke.class)
{
Poke poke = (Poke) obj;
if(poke.getPokeNum() == pokeNum &&
poke.getPokeColor() == pokeColor)
{
return true;
}
}
return false;
}
public int compareTo(Object obj){
Poke p = (Poke)obj;
if(pokeNum == p.getPokeNum() && pokeNum == 13)
return pokeColor - p.getPokeColor();
else
return pokeNum - p.getPokeNum() ;
}
}


User

package ds;

public class User {
private String userName;
private int desk;
private int site;
public User(){}
public User(String userName){
this.userName=userName;
}
public User(String userName,int desk,int site){
this.userName=userName;
this.desk=desk;
this.site=site;
}
public int getDesk() {
return desk;
}
public void setDesk(int desk) {
this.desk = desk;
}
public int getSite() {
return site;
}
public void setSite(int site) {
this.site = site;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public boolean equals(Object obj){
if(obj == this)
return true;
if(obj instanceof User){
User user = (User)obj;
return userName.equals(user.userName);
}
else{
return false;
}
}
public int hashCode(){
return userName.hashCode();
}
}