简单黑白棋Word格式.docx
- 文档编号:8146061
- 上传时间:2023-05-10
- 格式:DOCX
- 页数:21
- 大小:17.64KB
简单黑白棋Word格式.docx
《简单黑白棋Word格式.docx》由会员分享,可在线阅读,更多相关《简单黑白棋Word格式.docx(21页珍藏版)》请在冰点文库上搜索。
}
classDrawPaneextendsJPanel{
privateInsetsinsets;
finalstaticintBLACK=-1;
finalstaticintWHITE=1;
privatePointpoint=null;
privateintcolorStatus;
privateint[][]status=null;
privateintcount;
privateintchessNum;
privateJTextAreainfoText=null;
privateint[][]statusW=null;
privateintlevel=1;
privateintwhiteCount=0;
privateintblackCount=0;
privateColorbgColor=null;
publicDrawPane(Colorc){
initComponent();
initChess();
bgColor=c;
addMouseListener(newMouseAdapter(){
publicvoidmouseClicked(MouseEvente){
response(e.getPoint());
});
setFocusable(true);
addKeyListener(newmyKeyListener());
publicvoidpaintComponent(Graphicsg){
super.paintComponent(g);
if(insets==null){
insets=getInsets();
//super.paintComponents(g);
Graphics2Dg2d=(Graphics2D)g;
g2d.setColor(Color.green);
g2d.fill3DRect(50,50,400,400,true);
g2d.setColor(Color.RED);
for(inti=0;
i<
8;
i++){
for(intj=0;
j<
j++){
g2d.drawString(i+"
"
50*i+75,45);
g2d.drawString(j+"
40,50*j+75);
g2d.drawRect(50+50*i,50+50*j,50,50);
if(status[i][j]==BLACK){
g2d.setColor(Color.BLACK);
g2d.fillOval(i*50+53,j*50+53,44,44);
if(status[i][j]==WHITE){
g2d.setColor(Color.WHITE);
if(status[i][j]>
1){
//g2d.setColor(Color.BLUE);
//g2d.drawString("
+(status[i][j]-1),i*50+75,
//j*50+75);
g2d.drawString("
X"
i*50+75,j*50+75);
g2d.fillOval(200,470,30,30);
g2d.fillOval(300,470,30,30);
g2d.setColor(bgColor);
g2d.fillRect(240,470,60,30);
g2d.fillRect(340,470,60,30);
+blackCount,240,490);
+whiteCount,340,490);
//jug(colorStatus);
publicvoidinitComponent(){
infoText=newJTextArea();
setLayout(newBorderLayout());
infoText.setEditable(false);
//infoText.setBackground(Color.PINK);
infoText.setForeground(Color.BLACK);
JScrollPanejsp=newJScrollPane(infoText);
JPanelinfoPanel=newJPanel(newBorderLayout());
//infoPanel.setBackground(Color.PINK);
infoPanel.add(jsp,BorderLayout.CENTER);
infoPanel.add(newJLabel("
"
),BorderLayout.NORTH);
),BorderLayout.SOUTH);
add(infoPanel,BorderLayout.EAST);
publicvoidinitChess(){
chessNum=4;
count=0;
colorStatus=BLACK;
status=newint[8][8];
status[3][3]=BLACK;
status[4][4]=BLACK;
status[3][4]=WHITE;
status[4][3]=WHITE;
statusW=newint[8][8];
statusW[i][j]=2;
4;
statusW[i+2][0]=3;
statusW[i+2][1]=1;
statusW[i+2][7]=3;
statusW[i+2][6]=1;
statusW[0][i+2]=3;
statusW[1][i+2]=1;
statusW[7][i+2]=3;
statusW[6][i+2]=1;
2;
statusW[i][j]=0;
statusW[7-i][j]=0;
statusW[i][7-j]=0;
statusW[7-i][7-j]=0;
statusW[0][0]=4;
statusW[0][7]=4;
statusW[7][0]=4;
statusW[7][7]=4;
jug(colorStatus);
Stringmsg="
下棋的不骤:
;
infoText.setText(msg+"
\n"
repaint();
publicvoidresponse(Pointp){
booleaninterrupt=false;
point=setPoint(p);
if(point!
=null){
intx=point.x/50-1;
inty=point.y/50-1;
if(check(x,y,colorStatus)>
0){
manulChess(x,y,BLACK);
if(level==1){
autoChess(WHITE);
}else{
autoChess(WHITE,2);
if(blPass()){
if(!
blPass()){
interrupt=true;
if(blOver(interrupt)){
publicPointsetPoint(Pointp){
if(p.x<
50||p.x>
450||p.y<
50||p.y>
450){
returnnull;
p.x=(p.x/50)*50;
p.y=(p.y/50)*50;
returnp;
publicbooleanchange(inti,intj,intsta){
booleanflag=false;
//north
if(j!
=0){
if(sta!
=status[i][j-1]&
&
1==Math.abs(status[i][j-1])){
intm=j-1;
while(status[i][j-1]==status[i][m]&
m>
m--;
//System.out.println(m);
if(status[i][m]==sta){
flag=true;
for(intn=j-1;
n>
m;
n--){
status[i][n]=sta;
//System.out.println("
["
+i+"
"
+n+"
]"
//+status[i][n]);
//south
=7){
=status[i][j+1]&
1==Math.abs(status[i][j+1])){
intm=j+1;
while(status[i][j+1]==status[i][m]&
m<
7){
m++;
for(intn=j+1;
n<
n++){
//west
if(i!
=status[i-1][j]&
1==Math.abs(status[i-1][j])){
intm=i-1;
while(status[i-1][j]==status[m][j]&
if(status[m][j]==sta){
for(intn=i-1;
status[n][j]=sta;
+j+"
//+status[n][j]);
//east
=status[i+1][j]&
1==Math.abs(status[i+1][j])){
intm=i+1;
while(status[i+1][j]==status[m][j]&
for(intn=i+1;
//northwest
=0&
i!
=status[i-1][j-1]
&
1==Math.abs(status[i-1][j-1])){
intn=j-1;
while(status[i-1][j-1]==status[m][n]&
0&
n--;
m="
+m+"
n="
+n);
if(status[m][n]==sta){
for(intx=i-1,y=j-1;
x>
x--,y--){
//for(inty=j-1;
y>
n;
y--){
status[x][y]=sta;
+x+"
+y+"
//+status[x][y]);
//}
//southeast
=7&
=status[i+1][j+1]
1==Math.abs(status[i+1][j+1])){
intn=j+1;
while(status[i+1][j+1]==status[m][n]&
7&
n++;
for(intx=i+1,y=j+1;
x<
x++,y++){
//for(inty=j+1;
y<
y++){
//northeast
=status[i+1][j-1]
1==Math.abs(status[i+1][j-1])){
while(status[i+1][j-1]==status[m][n]&
for(intx=i+1,y=j-1;
x++,y--){
//southwest
=status[i-1][j+1]
1==Math.abs(status[i-1][j+1])){
while(status[i-1][j+1]==status[m][n]&
for(intx=i-1,y=j+1;
x--,y++){
//}
returnflag;
publicintcheck(inti,intj,intsta){
intflag=0;
if(Math.abs(status[i][j])==1){
return0;
flag=flag+(j-1-m);
flag=flag+(m-j-1);
flag=flag+(i-1-m);
flag=flag+(m-i-1);
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 简单 白棋