import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
/**
* @author yeeku.H.lee [email protected]
* @version 1.0
* <br>Copyright (C), 2005-2008, yeeku.H.Lee
* <br>This program is protected by copyright laws.
* <br>Program Name:
* <br>Date:
*/
public class MainGame extends JPanel
{
private InfoSave infoSave;
private MyPanel mp;
private int tableNumber;
private String name;
private String sex;
private String way;
private String otherWay;
private String size = "1";
private BufferedImage whiteDisk;
private BufferedImage blackDisk;
private BufferedImage curBlack;
private BufferedImage curWhite;
private BufferedImage seatEmpty;
private BufferedImage maleSeatFull;
private BufferedImage femaleSeatFull;
private BufferedImage gameImage;
private BufferedImage ready;
private BufferedImage start;
private BufferedImage play;
private BufferedImage peace;
private BufferedImage lost;
private PrintStream ps;
private Rectangle leftName = new Rectangle(13, 348, 66, 125);
private Rectangle rightName = new Rectangle(645, 348, 66, 125);
private Image board; //棋盘图片
private Image white; //白棋图片
private Image black; //黑棋图片
private Image selected;
private int posX;
private int posY;
private int X;
private int Y;
private int preX; //前一步的坐标
private int preY; //前一步的坐标
private int preSX; //前一步的移动坐标
private int preSY; //前一步的移动坐标
private int otherX; //对方的坐标
private int otherY; //对方的坐标
private int step; //步数
private int count; //count 是计数器,为5的时候表胜利
private int cursor; //光标标志
private int winCountL; //胜利次数
private int winCountR; //胜利次数
private boolean startOver = false;
private boolean peaceOver = false;
private boolean lostOver = false;
private final int CHESS_SIZE = 15; //CHESS_SIZE 是棋盘大小
private int[][] chess = new int[CHESS_SIZE][CHESS_SIZE];
private int[][] select = new int[CHESS_SIZE][CHESS_SIZE];
private int[][] curChess = new int[CHESS_SIZE][CHESS_SIZE]; //自己或者对手上一步下的棋
private boolean playChess = false; //可否下棋
private boolean isBegin = false; //游戏开始了吗
private boolean isReady = false; //准备好了吗
private boolean isOtherReady = false; //对方准备好了吗
private Rectangle startButton = new Rectangle(334, 656 , 60 , 31);
private Rectangle peaceButton = new Rectangle(269, 653 , 42 , 35);
private Rectangle lostButton = new Rectangle(413, 659 , 45 , 18);
private int sec = 0;
private int dSec = 0;
private int min = 0;
private int dMin = 1;
private int secR = 0;
private int dSecR = 0;
private int minR = 0;
private int dMinR = 1;
private Timer timerLeft;
private Timer timerRight;
public MainGame(InfoSave infoSave , String way , int tableNumber)
{
try
{
this.tableNumber = tableNumber;
this.infoSave = infoSave;
this.way = way;
mp = new MyPanel();
ps = new PrintStream(infoSave.getSocket().getOutputStream());
gameImage = ImageIO.read(new File("fiveStone\\room2.bmp"));
ready = ImageIO.read(new File("fiveStone\\ready.jpg"));
start = ImageIO.read(new File("fiveStone\\start.jpg"));
play = ImageIO.read(new File("fiveStone\\play.jpg"));
peace = ImageIO.read(new File("fiveStone\\peace.jpg"));
lost = ImageIO.read(new File("fiveStone\\lost.jpg"));
whiteDisk = ImageIO.read(new File("fiveStone\\whiteDisk.gif"));
blackDisk = ImageIO.read(new File("fiveStone\\blackDisk.gif"));
curBlack = ImageIO.read(new File("fiveStone\\curBlack.gif"));
curWhite = ImageIO.read(new File("fiveStone\\curWhite.gif"));
maleSeatFull = ImageIO.read(new File("fiveStone\\maleSeatFull.jpg"));
femaleSeatFull = ImageIO.read(new File("fiveStone\\femaleSeatFull.jpg"));
seatEmpty = ImageIO.read(new File("fiveStone\\seatEmpty.jpg"));
white = ImageIO.read(new File("fiveStone\\white.gif"));
black = ImageIO.read(new File("fiveStone\\black.gif"));
selected = ImageIO.read(new File("fiveStone\\selected.gif"));
this.setMinimumSize(new Dimension(723 , 702));
this.setPreferredSize(new Dimension(gameImage.getWidth(null), gameImage.getHeight(null)));
mp.setPreferredSize(new Dimension(gameImage.getWidth(null), gameImage.getHeight(null)));
this.add(mp);
timer();
playChess();
}
catch (Exception e)
{
e.printStackTrace();
}
}
/*
向右横扫描4格,判断是否有5个相连的棋
*/
private void acrossScan(int i , int j)
{
//如果遇到有棋的地方就开始扫描
if (chess[i][j] == 1 || chess[i][j] == 2)
{
if ((j+4) < chess[i].length) //判断棋的右方是否足够有4个连续位置
{
count = 1;
for (int k=1;k<=4 ;k++ )
{
if (chess[i][j+k] == chess[i][j])
{
count++; //如果相连的地方有相同的棋就做标记
}
else count = 0;
}
}
}
}
/*
向下竖扫描4格,判断是否有5个相连的棋
*/
private void erectScan(int i , int j)
{
//如果遇到有棋的地方就开始扫描
if (chess[i][j] == 1 || chess[i][j] == 2)
{
if ((i+4) < chess.length) //判断棋的下方是否足够有4个连续位置
{
count = 1;
for (int k=1;k<=4 ;k++ )
{
if (chess[i+k][j] == chess[i][j])
{
count++; //如果相连的地方有相同的棋就做标记
}
else count = 0;
}
}
}
}
/*
向右上横扫描4格,判断是否有5个相连的棋
*/
private void topRightScan(int i , int j)
{
//如果遇到有棋的地方就开始扫描
if (chess[i][j] == 1 || chess[i][j] == 2)
{
if ((i-4) >= 0 && (j+4) < chess[i].length) //判断棋的右斜上方是否足够有4个连续位置
{
count = 1;
for (int k=1;k<=4 ;k++ )
{
if (chess[i-k][j+k] == chess[i][j])
{
count++; //如果相连的地方有相同的棋就做标记
}
else count = 0;
}
}
}
}
/*
向右下横扫描4格,判断是否有5个相连的棋
*/
private void belowRightScan(int i , int j)
{
//如果遇到有棋的地方就开始扫描
if (chess[i][j] == 1 || chess[i][j] == 2)
{
if ((i+4) < chess.length && (j+4) < chess[i].length) //判断棋的右斜下方是否足够有4个连续位置
{
count = 1;
for (int k=1;k<=4 ;k++ )
{
if (chess[i+k][j+k] == chess[i][j])
{
count++; //如果相连的地方有相同的棋就做标记
}
else count = 0;
}
}
}
}
//逐一调用4种扫描方法判断胜负
public void win()
{
for (int i = 0; i < chess.length ; i++ )
{
for (int j = 0 ; j < chess[i].length ; j++ )
{
acrossScan(i,j);
if (count!=5)
{
erectScan(i,j);
}
if (count!=5)
{
topRightScan(i,j);
}
if (count!=5)
{
belowRightScan(i,j);
}
if (count==5)
{
count=0;
//判断是黑棋还是白棋赢
if (chess[i][j] == 1)
{
timerLeft.stop();
timerRight.stop();
JOptionPane.showMessageDialog(mp , "黑棋胜利!!" , "胜利" ,
JOptionPane.INFORMATION_MESSAGE);
winCountL++;
}
else if (chess[i][j] == 2)
{
timerLeft.stop();
timerRight.stop();
JOptionPane.showMessageDialog(mp , "白棋胜利!!" , "胜利" ,
JOptionPane.INFORMATION_MESSAGE);
winCountR++;
}
try
{
PrintStream ps = new PrintStream(infoSave.getSocket().getOutputStream());
ps.println(MyProtocol.WIN + this.tableNumber + MyProtocol.WIN);
}
catch (Exception e)
{
没有合适的资源?快使用搜索试试~ 我知道了~
wuziqi.rar_play fivestone_五子棋java_网络版五子棋 java
共310个文件
jpg:166个
class:80个
gif:30个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 124 浏览量
2022-09-20
17:01:56
上传
评论
收藏 3.7MB RAR 举报
温馨提示
基于service的网络版五子棋
资源推荐
资源详情
资源评论
收起资源包目录
wuziqi.rar_play fivestone_五子棋java_网络版五子棋 java (310个子文件)
room2.bmp 1.45MB
room.bmp 1.45MB
room2.bmp 1.45MB
room.bmp 1.45MB
headerFrame.bmp 289KB
headerFrame1.bmp 289KB
headerFrame.bmp 289KB
headerFrame1.bmp 289KB
MainGame.class 15KB
MainGame.class 15KB
ServerThread.class 8KB
ServerThread.class 8KB
ChatSystem.class 7KB
ChatSystem.class 7KB
HallPanel.class 7KB
HallPanel.class 7KB
LoginDialog.class 5KB
LoginDialog.class 5KB
MainGame$MyPanel.class 5KB
MainGame$MyPanel.class 5KB
ClientThread.class 4KB
ClientThread.class 4KB
MainGame$1.class 4KB
MainGame$1.class 4KB
HostGame.class 4KB
HostGame.class 4KB
InfoSave.class 3KB
InfoSave.class 3KB
HeadPanel.class 3KB
HeadPanel.class 3KB
ChatSystem$PlayersModel.class 2KB
ChatSystem$PlayersModel.class 2KB
Client.class 2KB
Client.class 2KB
MainGame$2.class 2KB
MainGame$2.class 2KB
Person.class 2KB
Person.class 2KB
HostGame$1.class 2KB
HostGame$1.class 2KB
MainGame$3.class 2KB
MainGame$4.class 2KB
MainGame$3.class 2KB
MainGame$4.class 2KB
GameHall.class 1KB
GameHall.class 1KB
ChatSystem$person.class 1KB
ChatSystem$person.class 1KB
MyProtocol.class 1KB
MyProtocol.class 1KB
MyProtocol.class 1KB
MyProtocol.class 1KB
Server.class 1KB
Server.class 1KB
HeadPanel$2.class 1KB
HeadPanel$2.class 1KB
HeadPanel$MyPanel.class 949B
HeadPanel$MyPanel.class 949B
MyMap.class 912B
MyMap.class 912B
ChatSystem$3.class 904B
ChatSystem$3.class 904B
Client$1.class 876B
Client$1.class 876B
HeadPanel$1.class 838B
HeadPanel$1.class 838B
LoginDialog$MyPanel.class 659B
LoginDialog$MyPanel.class 659B
Client$2.class 598B
Client$2.class 598B
HostGame$MyPanel.class 574B
HostGame$MyPanel.class 574B
HallPanel$2.class 571B
HallPanel$2.class 571B
HallPanel$1.class 566B
HallPanel$1.class 566B
LoginDialog$2.class 561B
LoginDialog$2.class 561B
ChatSystem$2.class 555B
ChatSystem$2.class 555B
LoginDialog$3.class 526B
LoginDialog$3.class 526B
ChatSystem$1.class 520B
ChatSystem$1.class 520B
LoginDialog$1.class 501B
LoginDialog$1.class 501B
LoginDialog$4.class 446B
LoginDialog$4.class 446B
ClientRun.cmd 16B
ClientRun.cmd 16B
ServerRun.cmd 11B
ServerRun.cmd 11B
Thumbs.db 123KB
Thumbs.db 123KB
Thumbs.db 48KB
Thumbs.db 48KB
Fqshow.gif 8KB
Fqshow.gif 8KB
Mqshow.gif 8KB
Mqshow.gif 8KB
共 310 条
- 1
- 2
- 3
- 4
资源评论
周楷雯
- 粉丝: 80
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功