国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

用Java編寫掃雷游戲--代碼思想

2019-11-18 13:37:38
字體:
來源:轉載
供稿:網友

  import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/*按扭類*/

class Bomb extends JButton
{

public int num_x,num_y; //第幾號方塊
public int BombRoundCount; //四周雷數
public boolean isBomb; //是否為雷
public boolean isClicked; //是否被點擊
public int BombFlag; //探雷標記
public boolean isRight; //是否點擊右鍵

public Bomb(int x,int y)
{
BombFlag = 0;
num_x = x;
num_y = y;
BombRoundCount = 0;
isBomb = false;
isClicked = false;
isRight = false;
}
}
/*窗口及算法實現類*/

class MainBomb extends JFrame implements ActionListener,MouseListener
{

public JTextField text;
public Label nowBomb,setBomb;
public int BlockNum,BombNum; //當前方塊數當前雷數
public Icon icon_bomb = new ImageIcon("Bomb.gif"); //踩雷
public Icon icon_bomb_big = new ImageIcon("bomb_big.gif"); //踩雷標記
public Icon icon_flag = new ImageIcon("flag.gif"); //雷標記
public Icon icon_question = new ImageIcon("question.gif"); //迷惑是否有雷
public JButton start = new JButton(" 開始 ");
public Panel MenuPamel = new Panel();
public Panel mainPanel = new Panel();
public Bomb[][] bombButton;

/*界面設計*/

public MainBomb()
{
super("掃雷 Aaron2004制作 2004.8 ");
BlockNum = 64;
BombNum = 10;
Container c=getContentPane();
c.setBackground(Color.gray);
c.setLayout(new BorderLayout());
text=new JTextField("10 ",3);
nowBomb = new Label("當前雷數"+" "+BombNum+"");
setBomb= new Label("設置地雷數");
start.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
BombNum = Integer.parseInt(text.getText().trim());
if(BombNum >= 10 && BombNum < 50 )
replay();
else
{
JOptionPane msg = new JOptionPane();
JOptionPane.showMessageDialog(null,"您設置的地雷數太多了,請重設!","錯誤",2);
}

}
} );
MenuPamel.add(setBomb);
MenuPamel.add(text);
MenuPamel.add(start);
MenuPamel.add(nowBomb);
c.add(MenuPamel,"North");

mainPanel.setLayout(new GridLayout( (int)Math.sqrt(BlockNum) , (int)Math.sqrt(BlockNum)) );
bombButton=new Bomb[ (int)Math.sqrt(BlockNum) ][];

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 隆林| 广东省| 托克逊县| 木里| 台南县| 台前县| 宜黄县| 新河县| 贵溪市| 石棉县| 安新县| 石城县| 贵定县| 凉山| 芦溪县| 宁强县| 泗水县| 达日县| 崇左市| 疏附县| 滕州市| 澄江县| 浮梁县| 彭泽县| 修武县| 吐鲁番市| 安庆市| 阜阳市| 台南县| 利辛县| 房产| 盐城市| 五台县| 鄂州市| 克什克腾旗| 邯郸县| 常德市| 夏河县| 黑河市| 兰西县| 潜山县|