import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ChessBoard extends JPanel implements MouseListener,MouseMotionListener
{
public ChessPoint point[][];
public int unitWidth,unitHeight;
int x轴长,y轴长;
int x,y;
boolean move=false;
public String 红方颜色="红色",黑方颜色="黑色";
ChessPiece 红车1,红车2,红马1,红马2,红相1,红相2,红帅,红士1,红士2,
红兵1,红兵2,红兵3,红兵4,红兵5,红炮1,红炮2;
ChessPiece 黑车1,黑车2,黑马1,黑马2,黑将,黑士1,黑士2,
黑卒1,黑卒2,黑卒3,黑卒4,黑卒5,黑象1,黑象2,黑炮1,黑炮2;
int startX,startY;
int startI,startJ;
public boolean 红方走棋=true,黑方走棋=false;
Rule rule=null;
public MakeChessManual record=null;
public ChessBoard(int w,int h,int r,int c)
{
setLayout(null);
addMouseListener(this);
addMouseMotionListener(this);
Color bc=getBackground();
unitWidth=w;
unitHeight=h;
x轴长=r;
y轴长=c;
point=new ChessPoint[r+1][c+1];
for(int i=1;i<=r;i++)
{
for(int j=1;j<=c;j++)
{
point[i][j]=new ChessPoint(i*unitWidth,j*unitHeight,false);
}
}
rule=new Rule(this,point);
record=new MakeChessManual(this,point) ;
红车1=new ChessPiece("车",Color.red,bc,w-4,h-4,this);
红车1.set棋子类别(红方颜色);
红车2=new ChessPiece("车",Color.red,bc,w-4,h-4,this);
红车2.set棋子类别(红方颜色);
红马1=new ChessPiece("马",Color.red,bc,w-4,h-4,this);
红马1.set棋子类别(红方颜色);
红马2=new ChessPiece("马",Color.red,bc,w-4,h-4,this);
红马2.set棋子类别(红方颜色);
红炮1=new ChessPiece("炮",Color.red,bc,w-4,h-4,this);
红炮1.set棋子类别(红方颜色);
红炮2=new ChessPiece("炮",Color.red,bc,w-4,h-4,this);
红炮2.set棋子类别(红方颜色);
红相1=new ChessPiece("相",Color.red,bc,w-4,h-4,this);
红相1.set棋子类别(红方颜色);
红相2=new ChessPiece("相",Color.red,bc,w-4,h-4,this);
红相2.set棋子类别(红方颜色);
红士1=new ChessPiece("士",Color.red,bc,w-4,h-4,this);
红士1.set棋子类别(红方颜色);
红士2=new ChessPiece("士",Color.red,bc,w-4,h-4,this);
红士2.set棋子类别(红方颜色);
红帅=new ChessPiece("帅",Color.red,bc,w-4,h-4,this);
红帅.set棋子类别(红方颜色);
红兵1=new ChessPiece("兵",Color.red,bc,w-4,h-4,this);
红兵1.set棋子类别(红方颜色);
红兵2=new ChessPiece("兵",Color.red,bc,w-4,h-4,this);
红兵2.set棋子类别(红方颜色);
红兵3=new ChessPiece("兵",Color.red,bc,w-4,h-4,this);
红兵3.set棋子类别(红方颜色);
红兵4=new ChessPiece("兵",Color.red,bc,w-4,h-4,this);
红兵4.set棋子类别(红方颜色);
红兵5=new ChessPiece("兵",Color.red,bc,w-4,h-4,this);
红兵5.set棋子类别(红方颜色);
黑将=new ChessPiece("将",Color.blue,bc,w-4,h-4,this);
黑将.set棋子类别(黑方颜色);
黑士1=new ChessPiece("士",Color.blue,bc,w-4,h-4,this);
黑士1.set棋子类别(黑方颜色);
黑士2=new ChessPiece("士",Color.blue,bc,w-4,h-4,this);
黑士2.set棋子类别(黑方颜色);
黑车1=new ChessPiece("车",Color.blue,bc,w-4,h-4,this);
黑车1.set棋子类别(黑方颜色);
黑车2=new ChessPiece("车",Color.blue,bc,w-4,h-4,this);
黑车2.set棋子类别(黑方颜色);
黑炮1=new ChessPiece("炮",Color.blue,bc,w-4,h-4,this);
黑炮1.set棋子类别(黑方颜色);
黑炮2=new ChessPiece("炮",Color.blue,bc,w-4,h-4,this);
黑炮2.set棋子类别(黑方颜色);
黑象1=new ChessPiece("象",Color.blue,bc,w-4,h-4,this);
黑象1.set棋子类别(黑方颜色);
黑象2=new ChessPiece("象",Color.blue,bc,w-4,h-4,this);
黑象2.set棋子类别(黑方颜色);
黑马1=new ChessPiece("马",Color.blue,bc,w-4,h-4,this);
黑马1.set棋子类别(黑方颜色);
黑马2=new ChessPiece("马",Color.blue,bc,w-4,h-4,this);
黑马2.set棋子类别(黑方颜色);
黑卒1=new ChessPiece("卒",Color.blue,bc,w-4,h-4,this);
黑卒1.set棋子类别(黑方颜色);
黑卒2=new ChessPiece("卒",Color.blue,bc,w-4,h-4,this);
黑卒2.set棋子类别(黑方颜色);
黑卒3=new ChessPiece("卒",Color.blue,bc,w-4,h-4,this);
黑卒3.set棋子类别(黑方颜色);
黑卒4=new ChessPiece("卒",Color.blue,bc,w-4,h-4,this);
黑卒4.set棋子类别(黑方颜色);
黑卒5=new ChessPiece("卒",Color.blue,bc,w-4,h-4,this);
黑卒5.set棋子类别(黑方颜色);
point[1][10].setPiece(红车1,this);
point[2][10].setPiece(红马1,this);
point[3][10].setPiece(红相1,this);
point[4][10].setPiece(红士1,this);
point[5][10].setPiece(红帅,this);
point[6][10].setPiece(红士2,this);
point[7][10].setPiece(红相2,this);
point[8][10].setPiece(红马2,this);
point[9][10].setPiece(红车2,this);
point[2][8].setPiece(红炮1,this);
point[8][8].setPiece(红炮2,this);
point[1][7].setPiece(红兵1,this);
point[3][7].setPiece(红兵2,this);
point[5][7].setPiece(红兵3,this);
point[7][7].setPiece(红兵4,this);
point[9][7].setPiece(红兵5,this);
point[1][1].setPiece(黑车1,this);
point[2][1].setPiece(黑马1,this);
point[3][1].setPiece(黑象1,this);
point[4][1].setPiece(黑士1,this);
point[5][1].setPiece(黑将,this);
point[6][1].setPiece(黑士2,this);
point[7][1].setPiece(黑象2,this);
point[8][1].setPiece(黑马2,this);
point[9][1].setPiece(黑车2,this);
point[2][3].setPiece(黑炮1,this);
point[8][3].setPiece(黑炮2,this);
point[1][4].setPiece(黑卒1,this);
point[3][4].setPiece(黑卒2,this);
point[5][4].setPiece(黑卒3,this);
point[7][4].setPiece(黑卒4,this);
point[9][4].setPiece(黑卒5,this);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
for(int j=1;j<=y轴长;j++)
{
g.drawLine(point[1][j].x,point[1][j].y,point[x轴长][j].x,point[x轴长][j].y);
}
for(int i=1;i<=x轴长;i++)
{
if(i!=1&&i!=x轴长)
{
g.drawLine(point[i][1].x,point[i][1].y,point[i][y轴长-5].x,point[i][y轴长-5].y);
g.drawLine(point[i][y轴长-4].x,point[i][y轴长-4].y,point[i][y轴长].x,point[i][y轴长].y);
}
else
{
g.drawLine(point[i][1].x,point[i][1].y,point[i][y轴长].x,point[i][y轴长].y);
}
}
g.drawLine(point[4][1].x,point[4][1].y,point[6][3].x,point[6][3].y);
g.drawLine(point[6][1].x,point[6][1].y,point[4][3].x,point[4][3].y);
g.drawLine(point[4][8].x,point[4][8].y,point[6][y轴长].x,point[6][y轴长].y);
g.drawLine(point[4][y轴长].x,point[4][y轴长].y,point[6][8].x,point[6][8].y);
for(int i=1;i<=x轴长;i++)
{
g.drawString(""+i,i*unitWidth,unitHeight/2);
}
int j=1;
for(char c='A';c<='J';c++)
{
g.drawString(""+c,unitWidth/4,j*unitHeight);
j++;
}
}
public void mousePressed(MouseEvent e)
{
ChessPiece piece=null;
Rectangle rect=null;
if(e.getSource()==this)
move=false;
if(move==false)
if(e.getSource() instanceof ChessPiece)
{
piec
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
java课程设计耿祥义版源代码.rar (91个子文件)
java课程设计耿祥义版源代码
chap15
chap15
BroadCastWord.java 4KB
Receive.java 3KB
chap6
chap6
ChoiceFile.java 3KB
ClientTestArea.java 6KB
Server.java 4KB
Client.java 4KB
ReadTestquestion.java 4KB
chap14
chap14
ChatServer.java 6KB
ClientChat.java 3KB
ChatArea.java 6KB
InputNameTextField.java 4KB
chap11
chap11
MakeChessManual.java 4KB
Rule.java 9KB
ChessPiece.java 1KB
ChessPoint.java 989B
ChessBoard.java 14KB
MoveStep.java 194B
Chess.java 5KB
Demon.java 6KB
chap5
chap5
TestArea.java 8KB
EnglishTest.java 695B
ReadTestquestion.java 4KB
chap3
chap3
Tower.java 2KB
HannoiTower.java 13KB
Disk.java 497B
TowerPoint.java 868B
chap12
chap12
PuzzlePad.java 6KB
SquarePoint.java 746B
PuzzleFrame.java 2KB
chap4
chap4
MakeJPEG.java 7KB
chap2
chap2
OperationButton.java 317B
ComputerPad.java 12KB
NumberButton.java 320B
chap7
chap7
ChoiceFile.java 3KB
ClientTestArea.java 6KB
Server.java 4KB
ClientBS.java 3KB
ReadTestquestion.java 4KB
chap1
chap1
RandomSetIcon.java 861B
MemoryTestPane.java 4KB
Memory.java 6KB
Record.java 2KB
People.java 302B
ShowRecord.java 3KB
Block.java 697B
chap13
RandomSetMine.java 990B
CountMine.java 497B
FindAroundMineNumber.java 2KB
DetermineDigArea.java 2KB
DetermineMineMarkIsRightOrWrong.java 1002B
MineSquare.java 9KB
Game.java 4KB
FindSafeArea.java 1KB
TimeCount.java 583B
Record.java 3KB
FindAroundMineMarkNumber.java 514B
chap13
RandomSetMine.java 990B
CountMine.java 497B
FindAroundMineNumber.java 2KB
DetermineDigArea.java 2KB
DetermineMineMarkIsRightOrWrong.java 1002B
MineSquare.java 9KB
Game.java 4KB
FindSafeArea.java 1KB
TimeCount.java 583B
Record.java 3KB
FindAroundMineMarkNumber.java 514B
ShowRecord.java 4KB
DecideWinner.java 760B
Block.java 3KB
ShowRecord.java 4KB
DecideWinner.java 760B
Block.java 3KB
chap9
Delete.java 5KB
StudentManager.java 3KB
Inquest.java 4KB
StudentSituation.java 6KB
ModifySituation.java 8KB
chap9
Delete.java 5KB
StudentManager.java 3KB
Inquest.java 4KB
StudentSituation.java 6KB
ModifySituation.java 8KB
Student.java 1KB
Student.java 1KB
chap8
chap8
Year.java 2KB
Month.java 2KB
CalendarPad.java 6KB
NotePad.java 6KB
chap10
chap10
DatabaseServer.java 4KB
DatabaseClient.java 4KB
共 91 条
- 1
资源评论
- jacksoom2015-08-04源码真的是非常的给力
ljtyzhr
- 粉丝: 173
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功