java 设计连连看_如何用JAVA 编写一个连连看游戏全程设计

展开全部

刚试了。。测试通过。。

importjavax.swing.*;

importjava.awt.*;

importjava.awt.event.*;

publicclass LianLianKan implements ActionListener {

JFrame mainFrame; // 主面板

Container thisContainer;

JPanel centerPanel, southPanel, northPanel; //子面板

JButton diamondsButton[][] = newJButton[6][5];// 游戏按钮e69da5e887aa62616964757a686964616f31333330363261数组

JButton exitButton, resetButton, newlyButton;// 退出,重列,重新开始按钮

JLabel fractionLable = newJLabel("0"); // 分数标签

JButton firstButton, secondButton; // 分别记录两次被选中的按钮

// 储存游戏按钮位置(这里其实只要6行,5列。但是我们用了8行,7列。是等于在这个面板按钮的周围还围

//了一层是0的按钮,这样就可以实现靠近面板边缘的两个按钮可以消去)

int grid[][] = new int[8][7];

static boolean pressInformation = false; // 判断是否有按钮被选中

int x0 = 0, y0 = 0, x = 0, y = 0, fristMsg =0, secondMsg = 0, validateLV; // 游戏按钮的位置坐标

int i, j, k, n;// 消除方法控制

public void init() {

mainFrame = new JFrame("JKJ连连看");

thisContainer = mainFrame.getContentPane();

thisContainer.setLayout(new BorderLayout());

centerPanel = new JPanel();

southPanel = new JPanel();

northPanel = new JPanel();

thisContainer.add(centerPanel,"Center");

thisContainer.add(southPanel,"South");

thisContainer.add(northPanel,"North");

centerPanel.setLayout(new GridLayout(6, 5));

for (int cols = 0; cols < 6; cols++) {

for (int rows = 0; rows < 5; rows++) {

diamondsButton[cols][rows] = newJButton(String

.valueOf(grid[cols + 1][rows + 1]));

diamondsButton[cols][rows].addActionListener(this);

centerPanel.add(diamondsButton[cols][rows]);

}

}

exitButton = new JButton("退出");

exitButton.addActionListener(this);

resetButton = new JButton("重列");

resetButton.addActionListener(this);

newlyButton = new JButton("再来一局");

newlyButton.addActionListener(this);

southPanel.add(exitButton);

southPanel.add(resetButton);

southPanel.add(newlyButton);

fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable

.getT

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值