grids[Integer.parseInt(step_array[0])][Integer.parseInt(step_array[1])].setValue(Integer.parseInt(step_array[2]));
steps.add(grids[Integer.parseInt(step_array[0])][Integer.parseInt(step_array[1])]);
}
}
catch(Exception ex)
{
}
}
private class Grid extends JPanel implements MouseListener
{
int x, y, value;
boolean selected;
public Grid(int x, int y)
{
this.x=x;
this.y=y;
addMouseListener(this);
}
public void mousePressed(MouseEvent event)
{
if(game_state==Playing)
{
int button=event.getButton();
if(button==MouseEvent.BUTTON1)
{
if(value=https://www.04ip.com/post/=0)
{
steps.add(this);
setValue(1);
WinCheck();
turn=false;
if(game_state==Playing)
gobangAI();
}
}
else
control_menu.show(this, event.getX(), event.getY());
}
}
public void mouseEntered(MouseEvent event)
{
if(game_state==Playing)
setSelected(true);
}
public void mouseExited(MouseEvent event)
{
if(game_state==Playing)
setSelected(false);
}
public void mouseClicked(MouseEvent event)
{
}
public void mouseReleased(MouseEvent event)
{
}
public Dimension getPreferredSize()
{
return new Dimension(20, 20);
}
public Dimension getMinimumSize()
{
return getPreferredSize();
}
public int getLocX()
{
return x;
}
public int getLocY()
{
return y;
}
public int getValue()
{
return value;
}
public void Initial()
{
value=https://www.04ip.com/post/grid[x][y]=0;
selected=false;
repaint();
}
public void setValue(int new_value)
{
locX=x;
locY=y;
value=https://www.04ip.com/post/grid[x][y]=new_value;
repaint();
}
public void setSelected(boolean select)
{
selected=select;
repaint();
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
if(game_state!=Startgame_state!=Select)
{
g.drawLine(0, 10, 19, 10);
g.drawLine(10, 0, 10, 19);
/* 礶娩絬 */
g.setColor(Color.BLUE);
if(x==0)
g.drawLine(0, 0, 19, 0);
else if(x==length-1)
g.drawLine(0, 19, 19, 19);
if(y==0)
g.drawLine(19, 0, 19, 19);
else if(y==length-1)
g.drawLine(0, 0, 0, 19);
if(selected)
setBackground(Color.WHITE);
else
setBackground(Color.LIGHT_GRAY);
}
//g.drawString(x+" "+y, 1, 10);
if(value!=0)
{
temp = value=https://www.04ip.com/post/=1? black: white;
g.drawImage(temp, 4, 4, this);
}
}
}
}
急需一个用eclipse写的五子棋代码 , 能运行的// 运行代码很简单:在eclipse的项目中新建一个类Five.java 把下面的代码放入该类即可
// 游戏运行:上下左右键控制方向,enter键确定棋子落定之处,黑白交替执行
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* 借鉴别人的 。。。
*/
public class Five extends KeyAdapter {
boolean start = false;
JFrame frame;
Thread timerThread;
int h, l;// 定义变量
int pans[][] = new int[11][11]; // 变量初始值
int gbx = 5;
int gby = 5;
int ziShu = 0;
int shui = 0;
Five() {
frame = new JFrame("五子棋");
frame.getContentPane().add(new Screen());
frame.addKeyListener(this);
frame.setSize(12 * 40 + 5 * 2, 12 * 40 + 22 + 5 * 2 + 100);// 窗口大小
frame.setVisible(true);
frame.repaint();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
推荐阅读
- 保皇直播技巧,保皇游戏直播
- 云从科技新增ChatGPT概念,云从科技是什么公司
- 毕业设计模仿现有的网站吗,毕业设计论文去网上模仿
- 即时战略类游戏发展史小说,即时战略类的游戏
- linux命令逻辑符号 linux命令符号解释
- 电商如何发液体快递,液体怎么发国际快递
- 会展小程序开发功能,会展软件应用
- 无人直播图片动漫,无人直播效果怎么样
- php抓取首页数据 php获取当前页面url