📄 wzq.java
字号:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class wzq extends Applet implements MouseMotionListener,MouseListener
{
int lx=0,ly=0;
int turn=1;// 1为黑,2为白
int judge=0;//游戏是否结束 =1 黑胜 =2,白胜
int[][] mode=new int[19][19]; //=0,无,=1 黑, =2,白,=3 临时
public void init()
{
for(int i=0;i<=18;i++)
for(int j=0;j<=18;j++)
{
mode[i][j]=0;
}
setBackground(Color.orange);
addMouseMotionListener(this);
addMouseListener(this);
}
public int panduan()
{
judge=0;
for(int i=0;i<=14;i++)
for(int j=0;j<=14;j++)
{
if(mode[i][j]==1 && mode[i+1][j]==1 && mode[i+2][j]==1 && mode[i+3][j]==1 && mode[i+4][j]==1 )
{
judge=1;
break;
}
if(mode[i][j]==1 && mode[i][j+1]==1 && mode[i][j+2]==1 && mode[i][j+3]==1 && mode[i][j+4]==1 )
{
judge=1;
break;
}
if(mode[i][j]==1 && mode[i+1][j+1]==1 && mode[i+2][j+2]==1 && mode[i+3][j+3]==1 && mode[i+4][j+4]==1 )
{
judge=1;
break;
}
if(mode[i][j]==2 && mode[i+1][j]==2 && mode[i+2][j]==2 && mode[i+3][j]==2 && mode[i+4][j]==2 )
{
judge=2;
break;
}
if(mode[i][j]==2 && mode[i][j+1]==2 && mode[i][j+2]==2 && mode[i][j+3]==2 && mode[i][j+4]==2 )
{
judge=2;
break;
}
if(mode[i][j]==2 && mode[i+1][j+1]==2 && mode[i+2][j+2]==2 && mode[i+3][j+3]==2 && mode[i+4][j+4]==2 )
{
judge=2;
break;
}
}
for( i=4;i<=18;i++)
for( j=0;j<=14;j++)
{
if(mode[i][j]==1 && mode[i-1][j+1]==1 && mode[i-2][j+2]==1 && mode[i-3][j+3]==1 && mode[i-4][j+4]==1 )
{
judge=1;
break;
}
if(mode[i][j]==2 && mode[i-1][j+1]==2 && mode[i-2][j+2]==2 && mode[i-3][j+3]==2 && mode[i-4][j+4]==2 )
{
judge=2;
break;
}
}
return judge;
}
public void paint(Graphics g)
{
g.setColor(Color.blue);
for(int i=50;i<=410;i=i+20)
{
g.drawLine(50,i,410,i);
g.drawLine(i,50,i,410);
}
for(int i=0;i<=18;i++)
for(int j=0;j<=18;j++)
{
if(mode[i][j]==1)
{
g.setColor(Color.black);
g.fillOval(42+20*i,42+20*j,16,16);
}
if(mode[i][j]==2)
{
g.setColor(Color.white);
g.fillOval(42+20*i,42+20*j,16,16);
}
if(mode[i][j]==3)
{
g.setColor(Color.cyan);
g.fillOval(45+20*i,45+20*j,10,10);
}
}
if(judge==1)
{
g.setColor(Color.black);
g.drawString("黑胜了!!",450,200);
}
if(judge==2)
{
g.setColor(Color.red);
g.drawString("白胜了!!",450,200);
}
}
public void mousePressed(MouseEvent e) {}
public void mouseMoved(MouseEvent e) {
if(mode[lx][ly]==3)
mode[lx][ly]=0;
int x=e.getX();
int y=e.getY();
if(x>410) x=410;
if(y>410) y=410;
int i,j;
i=(x-50)/20;
j=(y-50)/20;
if(judge==0&&mode[i][j]==0)
mode[i][j]=3;
lx=i;
ly=j;
repaint();
}
public void mouseReleased(MouseEvent e){
int x=e.getX();
int y=e.getY();
if(x>410) x=410;
if(y>410) y=410;
int i,j;
i=(x-50)/20;
j=(y-50)/20;
if(turn==1 && judge==0 && mode[i][j]!=1 && mode[i][j]!=2)
{
mode[i][j]=1;
turn=2;
}
else if(turn==2 && judge==0 && mode[i][j]!=1 && mode[i][j]!=2)
{
mode[i][j]=2;
turn=1;
}
judge=panduan();
repaint();
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseClicked(MouseEvent e) {}
public void mouseDragged(MouseEvent e) {}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -