用eclipse编写一个基于java的五子棋(与电脑对弈)基于java五子棋代码java随机的五子棋五子棋代码java随机:
主要功能代码如下:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Main extends JFrame implements ActionListener{
private static final long serialVersionUID = 1L;
JButton[][] point=new JButton[40][40];
int[][] state=new int[40][40];
int[][] value=https://www.04ip.com/post/new int[40][40];
int[] place=new int[2];
public Main(){
this.setTitle("五子棋");
this.setBounds(100,10,1000,1000);
this.setLayout(new GridLayout(30,30));
int i,j;
for(i=0;i=39;i++){
for(j=0;j=39;j++){
state[i][j]=0;
value[i][j]=0;
}
}
for(i=5;i=34;i++){
for (j=5;j=34;j++){
point[i][j]=new JButton("");
this.add(point[i][j]);
point[i][j].addActionListener(this);
}
}
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
int i,j;
for(i=5;i=34;i++){
for(j=5;j=34;j++){
if(e.getSource()==point[i][j]){
point[i][j].setBackground(Color.RED);
state[i][j]=1;
point[i][j].setEnabled(false);
value[i][j]=0;
}
}
}
public static void main(String[] args)throws NullPointerException{
new Main();
}
else if(((state[i][j]==0)(state[i][j+1]==1)(state[i][j+2]==0))||
((state[i][j]==0)(state[i][j-1]==1)(state[i][j-2]==0))||
((state[i][j]==0)(state[i+1][j]==1)(state[i+2][j]==0))||
((state[i][j]==0)(state[i-1][j]==1)(state[i-2][j]==0))||//空红空
((state[i][j]==0)(state[i+1][j+1]==1)(state[i+2][j+2]==0))||
((state[i][j]==0)(state[i+1][j-1]==1)(state[i+2][j-2]==0))||
((state[i][j]==0)(state[i-1][j+1]==1)(state[i-2][j+2]==0))||
((state[i][j]==0)(state[i-1][j-1]==1)(state[i-2][j-2]==0))||
((state[i][j]==0)(state[i][j+1]==1)(state[i][j+2]==1)(state[i][j+3]==2))||
((state[i][j]==0)(state[i][j-1]==1)(state[i][j-2]==1)(state[i][j-3]==2))||
((state[i][j]==0)(state[i+1][j]==1)(state[i+2][j]==1)(state[i+3][j]==2))||
((state[i][j]==0)(state[i-1][j]==1)(state[i-2][j]==1)(state[i-3][j]==2))||//空红红蓝型
((state[i][j]==0)(state[i+1][j+1]==1)(state[i+2][j+2]==1)(state[i+3][j+3]==2))||
((state[i][j]==0)(state[i+1][j-1]==1)(state[i+2][j-2]==1)(state[i+3][j-3]==2))||
((state[i][j]==0)(state[i-1][j+1]==1)(state[i-2][j+2]==1)(state[i-3][j+3]==2))||
((state[i][j]==0)(state[i-1][j-1]==1)(state[i-2][j-2]==1)(state[i-3][j-3]==2))){
value[i][j]=2;
return value[i][j];
}
else if(((state[i][j]==0)(state[i][j+1]==2)(state[i][j+2]==0))||
((state[i][j]==0)(state[i][j-1]==2)(state[i][j-2]==0))||
((state[i][j]==0)(state[i+1][j]==2)(state[i+2][j]==0))||
((state[i][j]==0)(state[i-1][j]==2)(state[i-2][j]==0))||
((state[i][j]==0)(state[i+1][j+1]==2)(state[i+2][j+2]==0))||
((state[i][j]==0)(state[i+1][j-1]==2)(state[i+2][j-2]==0))||
((state[i][j]==0)(state[i-1][j+1]==2)(state[i-2][j+2]==0))||
((state[i][j]==0)(state[i-1][j-1]==2)(state[i-2][j-2]==0))||
((state[i][j]==0)(state[i][j+1]==2)(state[i][j+2]==2)(state[i][j+3]==1))||
((state[i][j]==0)(state[i][j-1]==2)(state[i][j-2]==2)(state[i][j-3]==1))||
((state[i][j]==0)(state[i+1][j]==2)(state[i+2][j]==2)(state[i+3][j]==1))||
((state[i][j]==0)(state[i-1][j]==2)(state[i-2][j]==2)(state[i-3][j]==1))||
((state[i][j]==0)(state[i+1][j+1]==2)(state[i+2][j+2]==2)(state[i+3][j+3]==1))||
((state[i][j]==0)(state[i+1][j-1]==2)(state[i+2][j-2]==2)(state[i+3][j-3]==1))||
((state[i][j]==0)(state[i-1][j+1]==2)(state[i-2][j+2]==2)(state[i-3][j+3]==1))||
((state[i][j]==0)(state[i-1][j-1]==2)(state[i-2][j-2]==2)(state[i-3][j-3]==1))){
value[i][j]=1;
return value[i][j];
}
else{
value[i][j]=0;
return value[i][j];
推荐阅读
- 保皇直播技巧,保皇游戏直播
- 云从科技新增ChatGPT概念,云从科技是什么公司
- 毕业设计模仿现有的网站吗,毕业设计论文去网上模仿
- 即时战略类游戏发展史小说,即时战略类的游戏
- linux命令逻辑符号 linux命令符号解释
- 电商如何发液体快递,液体怎么发国际快递
- 会展小程序开发功能,会展软件应用
- 无人直播图片动漫,无人直播效果怎么样
- php抓取首页数据 php获取当前页面url