展开全部
保存为appwzq.java
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class appwzq extends Applet implements MouseListener
{
al;
static int nu=29;
int x1,x2,y1,y2,width,height;
int[][] A=new int[nu][nu];
int j=20; //记录间隔长度
int lj=16; //记录棋子直径62616964757a686964616fe4b893e5b19e31333262353965
int user=1;
boolean flag=false;
public void init() //初始化方法
{
this.addMouseListener(this);
}
public void mousePressed(MouseEvent e)
{
flag= true;
x1=e.getX();
y1=e.getY();
deal();
}
public void mouseReleased(MouseEvent e)
{
Graphics g=getGraphics();
paintblack(g);
}
public void paintblack(Graphics g)
{
int a=1;
for(int i=1;i<=nu;i++)
{ a=i*j;
g.drawLine(a,j,a,j*nu);
}
for(int i=1;i<=nu;i++)
{ a=i*j;
g.drawLine(j,a,j*nu,a);
}
}
public void paint(Graphics g)
{
if (user==1)
{
g.setColor(Color.black); //setColor(Color c); 设置绘图区颜色
g.fillOval(x2*j-j/2,y2*j-j/2,lj,lj); //fillOval(int x,int y, int width,int height) 画椭圆并用当前颜色填充
//drawOval(int x,int y, int width,int height) 画椭圆
}else
if (user==2)
{
g.setColor(Color.red); //setColor(Color c); 设置绘图区颜色
g.fillOval(x2*j-j/2,y2*j-j/2,lj,lj); //fillOval(int x,int y, int width,int height) 画椭圆并用当前颜色填充
//drawOval(int x,int y, int width,int height) 画椭圆
}
win(); //判断是否赢
}
public void deal()
{
int x3,y3;
x2=x1/j;
y2=y1/j;
x3=x2*j;
y3=y2*j;
if (x2<=nu && y2<=nu)
{
if (((x3-x1)*(x3-x1)+(y3-y1+j)*(y3-y1+j))<=lj*lj/4)
{
y2++;
}else
if (((x3-x1+j)*(x3-x1+j)+(y3-y1)*(y3-y1))<=lj*lj/4)
{
x2++;
}else
if (((x3-x1+j)*(x3-x1+j)+(y3-y1+j)*(y3-y1+j))<=lj*lj/4)
{
y2++;
x2++;
}else
{
y2=-1;
x2=-1;
}
if (y2>=0&&x2>=0&&A[x2][y2]==0)
{
A[x2][y2]=user;
Graphics g=getGraphics();
paint(g);
}
}
}
public void win()
{
int x3,y3,x=0,y=0,xy=0,yx=0;
for (int i=-5;i<6 ;i++ )
{
x3=x2;
y3=y2;
x3=x3+i;
if (0<=x3&&x3<=nu&&0<=y3&&y3<=nu) //x轴
{
if (A[x3][y3]==user)
{ x++; } else { x=0; }
}
y3=y3+i; //xy轴
if (0<=x3&&x3<=nu&&0<=y3&&y3<=nu)
{
if (A[x3][y3]==user)
{ xy++; } else { xy=0; }
}
x3=x3-i; //y轴
if (0<=x3&&x3<=nu&&0<=y3&&y3<=nu)
{
if (A[x3][y3]==user)
{ y++; } else { y=0; }
}
x3=x3-i; //yx轴
if (0<=x3&&x3<=nu&&0<=y3&&y3<=nu)
{
if (A[x3][y3]==user)
{ yx++; } else { yx=0; }
}
if (x>4||y>4||xy>4||yx>4)
{
i=7;
Graphics g=getGraphics();
if (user==1)
{
g.drawString("黑方赢",j*nu+30,300);goto al;
}else { g.drawString("红方赢",j*nu+30,300);goto al; }
}
}
if (user==1)
{
user=2;
}else{ user=1; }
}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
}
保存为。html格式
width=800
height=600>
输赢出来之后还能下棋,我没写结束的语句。你们自己写吧。
已赞过
已踩过<
你对这个回答的评价是?
评论
收起