java编写一个五子棋游戏,拜托了 35
可以选择黑白棋,可以决定先后走,废话的就免了,我急着用,先谢谢了,我的分不多了,都给上了已经,以后追加吧带着注释,我对java不是很懂,谢了...
可以选择黑白棋,可以决定先后走,废话的就免了,我急着用,先谢谢了,我的分不多了,都给上了已经,以后追加吧
带着注释,我对java不是很懂,谢了 展开
带着注释,我对java不是很懂,谢了 展开
5个回答
展开全部
保存为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; //记录棋子直径
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格式
<HTML>
<BODY>
<applet code=appwzq.class
width=800
height=600>
</applet>
</BODY>
</HTML>
输赢出来之后还能下棋,我没写结束的语句。你们自己写吧。
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; //记录棋子直径
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格式
<HTML>
<BODY>
<applet code=appwzq.class
width=800
height=600>
</applet>
</BODY>
</HTML>
输赢出来之后还能下棋,我没写结束的语句。你们自己写吧。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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){}
}
{
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){}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
别啊,我也想要一份。。也传我一份吧
hnxnpp@qq.com
hnxnpp@qq.com
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
留个邮箱吧。我给你发一份。我自己做的。比你说的要复杂些。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
留个邮箱吧。我给你发一份。我自己做的。比你说的要复杂些。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询