掃雷代碼java
⑴ java,編一個游戲小游戲,比如掃雷,這個程序大概的代碼是什麼,誰能教教我我比較笨,但是我認學。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main
{
public static void main(String[] argus)
{
Landmine Zhang = new Landmine();
}
}
//
// Landmine類 主界面
class Landmine extends JFrame
{
static Resources resources = new Resources();
Playing listener = new Playing(this); //主要監聽者,監聽地雷面板的動作
Help helpListener = new Help(this); //輔助監聽者,監聽「幫助」、「關於」
JPanel landminePanel = new JPanel(); //創建地雷面板
JPanel topPanel = new JPanel(); //創建頂部面板
JPanel lowerPanel = new JPanel(); //創建底部面板
public static MyButton [][] lei; //主區按鈕組
public static int numberOfUnflaged ; //剩餘的雷數,顯示在topPanel上,用於提示用戶
public static int numberOfClicked; //已經翻開的格子數,當數字數字到"總格子數—雷數"時,即勝利
public static int usedTime; //已用時間
public static JLabel numberOfUnflagedLabel = new JLabel(); //創建剩雷數標簽
public static JLabel timeLabel = new JLabel();//創建時間標簽
public static Timer timer; //創建計時
Keylistener keyListener = new Keylistener(this);
public Landmine()
{
super("掃雷__1.2版__小老頭"); //標題
setBounds(300,90,800,800); //設置窗口位置和大小
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//最大化、最小化、關閉按鈕
BorderLayout ff = new BorderLayout(); //創建布局管理器
setLayout(ff); //關聯布局管理器
setResizable(false); //禁止改變窗口大小
/*初始化一些數據*/
numberOfClicked = 0;
numberOfUnflaged = 40;
usedTime = 0;
/*設置頂部面板*/
numberOfUnflagedLabel.setText("剩餘雷數:"+numberOfUnflaged);//顯示剩餘雷數
numberOfUnflagedLabel.setFont(resources.fontOne);//設置剩雷數標簽字體
numberOfUnflagedLabel.setIcon(resources.bombIconForLabel);//剩雷數標簽圖標(地雷形)
topPanel.add(numberOfUnflagedLabel); //剩雷數標簽加入topPanel
timeLabel.setText("用時:" + usedTime); //顯示剩餘時間
timeLabel.setFont(resources.fontOne); //設置時間標簽字體
timeLabel.setIcon(resources.clockIcon); //設置時間標簽圖標
topPanel.add(timeLabel); //時間標簽加入topPanel
add(topPanel,BorderLayout.NORTH); //加入主面板上部
timer = new Timer(1000,new TimerListener());//計算器注冊監聽者
/*設置底部面板*/
JButton aboutJB = new JButton("關於"); //創建「關於」按鈕
JButton helpJB = new JButton("求救"); //創建「求救」按鈕
helpJB.addActionListener(helpListener); //"求救"按鈕加入監聽者
aboutJB.addActionListener(helpListener);//"關於"按鈕加入監聽者
helpJB.addKeyListener(keyListener);
aboutJB.addKeyListener(keyListener); //注冊按鍵監聽
lowerPanel.add(aboutJB); //「關於」按鈕加入lowerPanel
lowerPanel.add(helpJB); //「幫助」按鈕加入lowerPanel
add(lowerPanel,BorderLayout.SOUTH);
/*設置地雷面板*/
GridLayout dd = new GridLayout(16,16);
landminePanel.setLayout(dd); //布局管理
lei = new MyButton[18][18];
for(int i=0; i<18; ++i)
{//創建下標0—17的按鈕,18*18矩陣
for(int j=0; j<18; ++j)
{
lei[i][j] = new MyButton(i,j);
}
}
for(int i=1; i<17; ++i)
{//將下標1-16的按鈕,加入面板、設置圖標、翻開標記為假、加入監聽者
for(int j=1; j<17; ++j)
{
landminePanel.add(lei[i][j]); //按鈕加入地雷面板
lei[i][j].setIcon(resources.smallIcon); //設置按鈕圖標
lei[i][j].isClicked = false; //翻開標記設置為 假lei[i][j].setIcon(dead);
lei[i][j].addActionListener(listener); //加入監聽者
lei[i][j].addMouseListener(listener); //加入滑鼠事件監聽者
lei[i][j].addKeyListener(keyListener); //按鈕注冊按鍵監聽,當焦點在按鈕上是能監聽按鍵
}
}
add(landminePanel,BorderLayout.CENTER); //landminePanel加入主框架中央
addLandmine(); //布雷
timer.start(); //啟動計時器
setVisible(true);//顯示之
}
/*布雷*/
public static void addLandmine()
{//隨機將40的按鈕的是否為雷的標記isBomb設為真
for(int count = 0; count<40; /*blank*/)
{
int i = (int)(Math.random()*100 % 16 +1 ) ;
int j = (int)(Math.random()*100 % 16 +1 ) ;
if(lei[i][j].isBomb == false)
{
lei[i][j].isBomb = true;
count++;
}
}
}
class TimerListener implements ActionListener
{//內部類,時間監聽
public void actionPerformed(ActionEvent e)
{
usedTime++;
timeLabel.setText("用時:" + usedTime);
}
}
}
//
// Playing類 執行主要游戲操作
class Playing implements ActionListener,MouseListener
{
static Resources resources = new Resources();
public static Landmine gui;
public Playing(Landmine in )
{
gui = in;
}
public void actionPerformed(ActionEvent event)
{
MyButton receive = (MyButton)event.getSource();
if(receive.isBomb)
{//如果翻到了雷。。
for(int i=1; i<17; ++i)
{//將所有的雷圖標設為 「地雷」
for(int j=1; j<17; ++j)
{
if(gui.lei[i][j].isBomb)
gui.lei[i][j].setIcon(resources.bombIcon);
}
}
receive.setIcon(resources.deadIcon);//將踩到的地雷圖標設為 「衰」
gui.timer.stop(); //停止計時器
JOptionPane.showMessageDialog(null,"小朋友,你掛了…","失敗!",
JOptionPane.INFORMATION_MESSAGE,
resources.deadIcon);//提示失敗
int yourChose = JOptionPane.showConfirmDialog(null,"你可能是一不小心點錯了,再來一局?" );
if(yourChose == JOptionPane.OK_OPTION)
{//點擊「是」時
replay();
}
else
{//點擊 「否」 或 「取消」 時退出程序
System.exit(0);
}
}
else if(receive.isClicked ==false)
{//未翻到雷
showBombNumber(receive);
}
}
public static void showBombNumber(MyButton in)
{//翻開點擊的按鈕
int numberOfLandmine = 0;//記錄雷的個數
in.isClicked = true; //翻開標記設為真
/*檢測周圍8個方塊是否為雷*/
if(gui.lei[in.num_x-1][in.num_y-1].isBomb == true) numberOfLandmine++;//左上
if(gui.lei[in.num_x][in.num_y-1].isBomb == true) numberOfLandmine++; //上
if(gui.lei[in.num_x+1][in.num_y-1].isBomb == true) numberOfLandmine++;//右上
if(gui.lei[in.num_x+1][in.num_y].isBomb == true) numberOfLandmine++; //右
if(gui.lei[in.num_x+1][in.num_y+1].isBomb == true) numberOfLandmine++;//右下
if(gui.lei[in.num_x][in.num_y+1].isBomb == true) numberOfLandmine++; //下
if(gui.lei[in.num_x-1][in.num_y+1].isBomb == true) numberOfLandmine++;//左下
if(gui.lei[in.num_x-1][in.num_y].isBomb == true) numberOfLandmine++; //左
in.setIcon(new ImageIcon("images/"+numberOfLandmine+".png"));//根據周圍的雷數顯示數字圖標
gui.numberOfClicked++;//翻開格子數+1
if(gui.numberOfClicked==216)
{//翻開216個格子時游戲成功,用戶選擇是否再來一局
int yourChoice = JOptionPane.showConfirmDialog(null,"恭喜你成功了!再來一盤嗎?");
if(yourChoice == JOptionPane.OK_OPTION)
replay();
else
System.exit(0);
}
if(numberOfLandmine==0)
{//如果周圍無雷,則將周圍未翻開格子的全部翻開
if(gui.lei[in.num_x-1][in.num_y-1].isClicked == false)
showBombNumber(gui.lei[in.num_x-1][in.num_y-1]);
if(gui.lei[in.num_x][in.num_y-1].isClicked == false)
showBombNumber(gui.lei[in.num_x][in.num_y-1]);
if(gui.lei[in.num_x+1][in.num_y-1].isClicked == false)
showBombNumber(gui.lei[in.num_x+1][in.num_y-1]);
if(gui.lei[in.num_x+1][in.num_y].isClicked == false)
showBombNumber(gui.lei[in.num_x+1][in.num_y]);
if(gui.lei[in.num_x+1][in.num_y+1].isClicked == false)
showBombNumber(gui.lei[in.num_x+1][in.num_y+1]);
if(gui.lei[in.num_x][in.num_y+1].isClicked == false)
showBombNumber(gui.lei[in.num_x][in.num_y+1]);
if(gui.lei[in.num_x-1][in.num_y+1].isClicked == false)
showBombNumber(gui.lei[in.num_x-1][in.num_y+1]);
if(gui.lei[in.num_x-1][in.num_y].isClicked == false)
showBombNumber(gui.lei[in.num_x-1][in.num_y]);
}
}
public static void replay()
{//重新開始
gui.dispose(); //釋放框架資源
gui.timer.stop(); //終止計時器
Landmine ff = new Landmine();//重新創建一個主類的實例
//這幾條語句實現了重新開始————關閉上一個窗口,重新開啟一個
//但是這種方法會造成內存的浪費,一個改進的方法是不關閉當年窗口,而是將當前窗口重新初始化
}
public void mousePressed(MouseEvent e)
{//當滑鼠右鍵點擊時自動調用此函數
int mods = e.getModifiers();
MyButton receive = (MyButton)e.getSource();
if((mods & InputEvent.BUTTON3_MASK) != 0)
{//滑鼠右鍵
if(receive.isClicked == false)
{
receive.isRight = receive.isRight ? false : true;//改變receive.isRight的值
if(receive.isRight)
{//如果添加標記,則剩餘雷數-1,設置標簽為「旗幟」
gui.numberOfUnflaged--;
receive.setIcon(resources.flagIcon);
}
else
{//如果清除標記,則剩餘雷數+1,設置標簽為「未翻開」
gui.numberOfUnflaged++;
receive.setIcon(resources.smallIcon);
}
gui.numberOfUnflagedLabel.setText("剩餘雷數:"+gui.numberOfUnflaged);
//更新剩餘雷數標簽
}
}
}
public void mouseReleased(MouseEvent e){}
public void mouseExited(MouseEvent e) {}
public void mouseClicked(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
}
//
// Help類,響應「關於」、「求救」
class Help implements ActionListener
{
static Resources resources = new Resources();
public static Landmine gui;
public Help(Landmine in)
{
gui = in ;
}
public void actionPerformed(ActionEvent event)
{
if(event.getActionCommand()=="關於")
JOptionPane.showMessageDialog(null,"掃雷1.2版。。小老頭出品");
if(event.getActionCommand()=="求救")
help();
}
public static void help()
{//求救
int stopNumber = (int)(Math.random() * gui.numberOfUnflaged + 1 );
int count = 0;
for(int i=1; i<17;++i )
{
for(int j=1; j<17; ++j)
{
if( gui.lei[i][j].isBomb && !gui.lei[i][j].isClicked && !gui.lei[i][j].isRight )
{
count++;
}
if(count == stopNumber)
{
gui.lei[i][j].setIcon(resources.badIcon);
return;
}
}
}
}
}
//
// Keylistener類,響應鍵盤事件
class Keylistener implements KeyListener
{
static Resources resources = new Resources();
Landmine gui;
public Keylistener(Landmine in)
{
gui = in;
}
public void keyPressed(KeyEvent e)
{//有鍵按下時自動執行該方法
if(e.getKeyCode() == KeyEvent.VK_UP)
{//按鍵為 向上 時,將所有未標記的地雷顯示出
for(int i=1; i<17; ++i)
{
for(int j=1; j<17; ++j)
{
if(gui.lei[i][j].isBomb && !gui.lei[i][j].isRight)
gui.lei[i][j].setIcon(resources.badIcon);
}
}
}
if(e.getKeyCode() == KeyEvent.VK_DOWN)
{//按鍵為 向下 時,將所有未標記的地雷恢復為未點擊的圖標
for(int i=1; i<17; ++i)
{
for(int j=1; j<17; ++j)
{
if(gui.lei[i][j].isBomb && !gui.lei[i][j].isRight)
gui.lei[i][j].setIcon(resources.smallIcon);
}
}
}
}
public void keyReleased(KeyEvent e){}
public void keyTyped(KeyEvent e){}
}
//
// 按鈕類 MyBtton
class MyButton extends JButton
{
public int num_x,num_y; //第幾號方塊
public boolean isBomb; //是否為雷
public boolean isClicked; //是否被點擊
public int BombFlag; //探雷標記
public boolean isRight; //是否點擊右鍵
public MyButton(int x, int y)
{
BombFlag = 0;
num_x = x;
num_y = y;
isBomb = false;
isClicked = true;
isRight = false;
}
}
//
// 資源類 其他類中用到的圖標,字體等
class Resources
{
public static ImageIcon deadIcon;
public static ImageIcon smallIcon;
public static ImageIcon clockIcon;
public static ImageIcon bombIcon;
public static ImageIcon flagIcon;
public static ImageIcon badIcon;
public static ImageIcon bombIconForLabel;
public static Font fontOne;
public Resources()
{
deadIcon = new ImageIcon("images/dead.gif");
smallIcon = new ImageIcon("images/smallIcon.png");
clockIcon = new ImageIcon("images/clock2.png");
bombIcon = new ImageIcon("images/bomb.png");
flagIcon = new ImageIcon("images/flag_2.png");
badIcon = new ImageIcon("images/bad.gif");
bombIconForLabel = new ImageIcon("images/bombForLabel.gif");
fontOne = new Font("null",Font.BOLD,20);
}
}
⑵ 運行在Eclipse環境下的java掃雷游戲的初級代碼是什麼
import java.awt.Button;x0dx0aimport java.util.Set;x0dx0a// 每一個小方塊類x0dx0apublic class Diamond extends Button {x0dx0aprivate Diamond[] diamonds;x0dx0ax0dx0a// 該小方塊周圍的八個方向上的小方塊x0dx0aprivate Diamond east;x0dx0aprivate Diamond north;x0dx0aprivate Diamond northEast;x0dx0aprivate Diamond northWest;x0dx0aprivate Diamond south;x0dx0aprivate Diamond southEast;x0dx0aprivate Diamond southWest;x0dx0aprivate Diamond west;x0dx0ax0dx0aprivate boolean isBomb;// 是否是雷x0dx0aprivate boolean isChange;// 又沒有被翻過x0dx0aprivate int no;// 產生的方塊的編號x0dx0ax0dx0a// 持有所有小方塊的引用,方便進行操作x0dx0apublic Diamond(Diamond[] diamonds) {x0dx0athis.diamonds = diamonds;x0dx0a}x0dx0ax0dx0a// 按鍵時方塊發生改變x0dx0apublic boolean change() {x0dx0athis.isChange = true;// 說明已經翻過了x0dx0aif(isBomb) {// 觸雷x0dx0a//this.setBackground(Color.red);x0dx0areturn true;x0dx0a} else {// 不是雷,就顯示周圍雷的數目x0dx0a//this.setLabel(this.getNearBombNo() + "");x0dx0athis.setLabel(this.getNearBombNo() + "");x0dx0a//if(this.getNearBombNo() == 0) {x0dx0a//this.moveon();x0dx0a//}x0dx0areturn false;x0dx0a}x0dx0a}x0dx0ax0dx0a// 獲得該小方塊周圍雷的數量x0dx0apublic int getNearBombNo() {x0dx0aint no = 0;x0dx0aif(this.northWest != null && this.northWest.isBomb) no++;x0dx0aif(this.north != null && this.north.isBomb) no++;x0dx0aif(this.northEast != null && this.northEast.isBomb) no++;x0dx0aif(this.east != null && this.east.isBomb) no++;x0dx0aif(this.southEast != null && this.southEast.isBomb) no++;x0dx0aif(this.south != null && this.south.isBomb) no++;x0dx0aif(this.southWest != null && this.southWest.isBomb) no++;x0dx0aif(this.west != null && this.west.isBomb) no++;x0dx0ax0dx0areturn no;x0dx0a}x0dx0ax0dx0a// 獲得該小方塊周圍的小方塊x0dx0apublic Diamond getNearDimaond(int i) {x0dx0aint index = -1;x0dx0aswitch (i) {x0dx0acase 1:// 1表示西北,2,表示北,以此類推x0dx0aindex = no - 10;x0dx0aif(index < 1 || no == 19 || no == 28 || no == 37 || no == 46 || no == 55 || no == 64 || no == 73) {x0dx0areturn null;x0dx0a} else {x0dx0areturn diamonds[index];x0dx0a}x0dx0acase 2:x0dx0aindex = no - 9;x0dx0aif(index < 1) {x0dx0areturn null;x0dx0a} else {x0dx0areturn diamonds[index];x0dx0a}x0dx0acase 3:x0dx0aindex = no - 8;x0dx0aif(index < 1 || no == 9 || no == 18 || no == 27 || no == 36 || no == 45 || no == 54 || no == 63 || no == 72) {x0dx0areturn null;x0dx0a} else {x0dx0areturn diamonds[index];x0dx0a}x0dx0acase 4:x0dx0aindex = no + 1;x0dx0aif(no == 9 || no == 18 || no == 27 || no == 36 || no == 45 || no == 54 || no == 63 || no == 72 || no == 81) {x0dx0areturn null;x0dx0a} else {x0dx0areturn diamonds[index];x0dx0a}x0dx0acase 5:x0dx0aindex = no + 10;x0dx0aif(index >= 81 ||no == 9 || no == 18 || no == 27 || no == 36 || no == 45 || no == 54 || no == 63 || no == 72 || no == 81) {x0dx0areturn null;x0dx0a} else {x0dx0areturn diamonds[index];x0dx0a}x0dx0acase 6:x0dx0aindex = no + 9;x0dx0aif(index > 81) {x0dx0areturn null;x0dx0a} else {x0dx0areturn diamonds[index];x0dx0a}x0dx0acase 7:x0dx0aindex = no + 8;x0dx0aif(index >= 81 || no==1 || no == 10 || no == 19 || no == 28 || no == 37 || no == 46 || no == 55 || no == 64 || no == 73) {x0dx0areturn null;x0dx0a} else {x0dx0areturn diamonds[index];x0dx0a}x0dx0acase 8:x0dx0aindex = no - 1;x0dx0aif(no==1 || no==10 || no == 19 || no == 28 || no == 37 || no == 46 || no == 55 || no == 64 || no == 73) {x0dx0areturn null;x0dx0a} else {x0dx0areturn diamonds[index];x0dx0a}x0dx0a}x0dx0areturn null;x0dx0a}x0dx0ax0dx0a// 遞歸,set是用來裝已經翻過的小方塊的,不然會死循環,為什麼用set,因為set是不重復的x0dx0apublic void moveon(Set
⑶ 用java怎麼寫掃雷程序
首先要寫一個UI,也就是操作界面,使用java.swing.*內的東西就可以搞定;
其次寫一個hander,也就是具體的按鈕響應,UI的初始化(哪裡有雷),怎麼觸發雷和其他的;
一般來說簡單的掃雷模型就好了,如果需要更有意思點,可以寫一些資料庫的操作內容的tool類具體的就是處理歷史操作記錄,場均數據或多人競技的特點。
如果你是說你沒有設計思路,我可以給你個提示:遞歸演算法是觸發掃雷的方法,初始化用隨機數來做。
⑷ java掃雷游戲代碼
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Frame
extends JFrame {
JTextField text;
JLabel nowBomb, setBomb;
int BombNum, BlockNum; // 當前雷數,當前方塊數
int rightBomb, restBomb, restBlock; // 找到的地雷數,剩餘雷數,剩餘方塊數
JButton start = new JButton(" 開始 ");
JPanel MenuPamel = new JPanel();
JPanel bombPanel = new JPanel();
Bomb[][] bombButton;
JPanel c;
BorderLayout borderLayout1 = new BorderLayout();
GridLayout gridLayout1 = new GridLayout();
public Frame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
c = (JPanel) getContentPane();
setTitle("掃雷");
c.setBackground(Color.WHITE);
MenuPamel.setBackground(Color.GRAY);
c.setLayout(borderLayout1);
setSize(new Dimension(600, 600));
setResizable(false);
BlockNum = 144;
BombNum = 10;
text = new JTextField("10 ", 3);
nowBomb = new JLabel("當前雷數" + ":" + BombNum);
setBomb = new JLabel("設置地雷數");
start.addActionListener(new Frame1_start_actionAdapter(this));
MenuPamel.add(setBomb);
MenuPamel.add(text);
MenuPamel.add(start);
MenuPamel.add(nowBomb);
c.add(MenuPamel, java.awt.BorderLayout.SOUTH);
bombPanel.setLayout(gridLayout1);
gridLayout1.setColumns( (int) Math.sqrt(BlockNum));
gridLayout1.setRows( (int) Math.sqrt(BlockNum));
bombButton = new Bomb[ (int) Math.sqrt(BlockNum)][ (int) Math.sqrt(BlockNum)];
for (int i = 0; i < (int) Math.sqrt(BlockNum); i++) {
for (int j = 0; j < (int) Math.sqrt(BlockNum); j++) {
bombButton[i][j] = new Bomb(i, j);
//bombButton[i][j].setSize(10, 10);
bombButton[i][j].setFont(new Font("", Font.PLAIN, 14));//設置字體大小
bombButton[i][j].setForeground(Color.white);
bombButton[i][j].addMouseListener(new Bomb_mouseAdapter(this));
bombButton[i][j].addActionListener(new Bomb_actionAdapter(this));
bombPanel.add(bombButton[i][j]);
}
}
c.add(bombPanel, java.awt.BorderLayout.CENTER);
startBomb();
}
/* 開始按鈕 */
public void start_actionPerformed(ActionEvent e) {
int num=Integer.parseInt(text.getText().trim());
if (num >= 5 && num < 50) {
BombNum = num;
startBomb();
}
else if (num < 5) {
JOptionPane.showMessageDialog(null, "您設置的地雷數太少了,請重設!", "錯誤",
JOptionPane.ERROR_MESSAGE);
num=10;
BombNum = num;
}
else {
JOptionPane.showMessageDialog(null, "您設置的地雷數太多了,請重設!", "錯誤",
JOptionPane.ERROR_MESSAGE);
num=10;
BombNum = num;
}
}
/* 開始,布雷 */
public void startBomb() {
nowBomb.setText("當前雷數" + ":" + BombNum);
for (int i = 0; i < (int) Math.sqrt(BlockNum); i++) {
for (int j = 0; j < (int) Math.sqrt(BlockNum); j++) {
bombButton[i][j].isBomb = false;
bombButton[i][j].isClicked = false;
bombButton[i][j].isRight = false;
bombButton[i][j].BombFlag = 0;
bombButton[i][j].BombRoundCount = 9;
bombButton[i][j].setEnabled(true);
bombButton[i][j].setText("");
bombButton[i][j].setFont(new Font("", Font.PLAIN, 14));//設置字體大小
bombButton[i][j].setForeground(Color.BLUE);
rightBomb = 0;
restBomb = BombNum;
restBlock = BlockNum - BombNum;
}
}
for (int i = 0; i < BombNum; ) {
int x = (int) (Math.random() * (int) (Math.sqrt(BlockNum) - 1));
int y = (int) (Math.random() * (int) (Math.sqrt(BlockNum) - 1));
if (bombButton[x][y].isBomb != true) {
bombButton[x][y].isBomb = true;
i++;
}
}
CountRoundBomb();
}
/* 計算方塊周圍雷數 */
public void CountRoundBomb() {
for (int i = 0; i < (int) Math.sqrt(BlockNum); i++) {
for (int j = 0; j < (int) Math.sqrt(BlockNum); j++) {
int count = 0;
// 當需要檢測的單元格本身無地雷的情況下,統計周圍的地雷個數
if (bombButton[i][j].isBomb != true) {
for (int x = i - 1; x < i + 2; x++) {
for (int y = j - 1; y < j + 2; y++) {
if ( (x >= 0) && (y >= 0)
&& (x < ( (int) Math.sqrt(BlockNum)))
&& (y < ( (int) Math.sqrt(BlockNum)))) {
if (bombButton[x][y].isBomb == true) {
count++;
}
}
}
}
bombButton[i][j].BombRoundCount = count;
}
}
}
}
/* 是否挖完了所有的雷 */
public void isWin() {
restBlock = BlockNum - BombNum;
for (int i = 0; i < (int) Math.sqrt(BlockNum); i++) {
for (int j = 0; j < (int) Math.sqrt(BlockNum); j++) {
if (bombButton[i][j].isClicked == true) {
restBlock--;
}
}
}
if (rightBomb == BombNum || restBlock == 0) {
JOptionPane.showMessageDialog(this, "您挖完了所有的雷,您勝利了!", "勝利",
JOptionPane.INFORMATION_MESSAGE);
startBomb();
}
}
/** 當選中的位置為空,則翻開周圍的地圖* */
public void isNull(Bomb ClickedButton) {
int i, j;
i = ClickedButton.num_x;
j = ClickedButton.num_y;
for (int x = i - 1; x < i + 2; x++) {
for (int y = j - 1; y < j + 2; y++) {
if ( ( (x != i) || (y != j)) && (x >= 0) && (y >= 0)
&& (x < ( (int) Math.sqrt(BlockNum)))
&& (y < ( (int) Math.sqrt(BlockNum)))) {
if (bombButton[x][y].isBomb == false
&& bombButton[x][y].isClicked == false
&& bombButton[x][y].isRight == false) {
turn(bombButton[x][y]);
}
}
}
}
}
/* 翻開 */
public void turn(Bomb ClickedButton) {
ClickedButton.setEnabled(false);
ClickedButton.isClicked = true;
if (ClickedButton.BombRoundCount > 0) {
ClickedButton.setText(ClickedButton.BombRoundCount + "");
}
else {
isNull(ClickedButton);
}
}
/* 左鍵點擊 */
public void actionPerformed(ActionEvent e) {
if ( ( (Bomb) e.getSource()).isClicked == false
&& ( (Bomb) e.getSource()).isRight == false) {
if ( ( (Bomb) e.getSource()).isBomb == false) {
turn( ( (Bomb) e.getSource()));
isWin();
}
else {
for (int i = 0; i < (int) Math.sqrt(BlockNum); i++) {
for (int j = 0; j < (int) Math.sqrt(BlockNum); j++) {
if (bombButton[i][j].isBomb == true) {
bombButton[i][j].setText("b");
}
}
}
( (Bomb) e.getSource()).setForeground(Color.RED);
( (Bomb) e.getSource()).setFont(new Font("", Font.BOLD, 20));
( (Bomb) e.getSource()).setText("X");
JOptionPane.showMessageDialog(this, "你踩到地雷了,按確定重來", "踩到地雷", 2);
startBomb();
}
}
}
/* 右鍵點擊 */
public void mouseClicked(MouseEvent e) {
Bomb bombSource = (Bomb) e.getSource();
boolean right = SwingUtilities.isRightMouseButton(e);
if ( (right == true) && (bombSource.isClicked == false)) {
bombSource.BombFlag = (bombSource.BombFlag + 1) % 3;
if (bombSource.BombFlag == 1) {
if (restBomb > 0) {
bombSource.setForeground(Color.RED);
bombSource.setText("F");
bombSource.isRight = true;
restBomb--;
}
else {
bombSource.BombFlag = 0;
}
}
else if (bombSource.BombFlag == 2) {
restBomb++;
bombSource.setText("Q");
bombSource.isRight = false;
}
else {
bombSource.setText("");
}
if (bombSource.isBomb == true) {
if (bombSource.BombFlag == 1) {
rightBomb++;
}
else if (bombSource.BombFlag == 2) {
rightBomb--;
}
}
nowBomb.setText("當前雷數" + ":" + restBomb);
isWin();
}
}
public static void main(String[] args) {
Frame frame = new Frame();
frame.setVisible(true);
}
}
class Frame1_start_actionAdapter
implements ActionListener {
private Frame adaptee;
Frame1_start_actionAdapter(Frame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.start_actionPerformed(e);
}
}
////////////////////////////
class Bomb
extends JButton {
int num_x, num_y; // 第幾號方塊
int BombRoundCount; // 周圍雷數
boolean isBomb; // 是否為雷
boolean isClicked; // 是否被點擊
int BombFlag; // 探雷標記
boolean isRight; // 是否點擊右鍵
public Bomb(int x, int y) {
num_x = x;
num_y = y;
BombFlag = 0;
BombRoundCount = 9;
isBomb = false;
isClicked = false;
isRight = false;
}
}
class Bomb_actionAdapter
implements ActionListener {
private Frame adaptee;
Bomb_actionAdapter(Frame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.actionPerformed(e);
}
}
class Bomb_mouseAdapter
extends MouseAdapter {
private Frame adaptee;
Bomb_mouseAdapter(Frame adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.mouseClicked(e);
}
}
⑸ JAVA 掃雷的一段代碼求解釋
int BombNum, BlockNum; // 當前雷數,當前方塊數
int rightBomb, restBomb, restBlock; // 找到的地雷數,剩餘雷數,剩餘方塊數
JButton start = new JButton(" 開始 ");
JPanel MenuPamel = new JPanel(); //新建一個區域,看名字是放菜單.但是打錯字了.
JPanel bombPanel = new JPanel();//新建一個區域,雷區,由於雷是按鈕,這裡面應該都是按鈕(JButton).
Bomb[][] bombButton; 2維組數,放地雷.
class Bomb extends JButton {
int num_x, num_y; // 第幾號方塊
int BombRoundCount; // 周圍雷數
boolean isBomb; // 是否為雷
boolean isClicked; // 是否被點擊
int BombFlag; // 探雷標記
boolean isRight; // 是否點擊右鍵
public Bomb(int x, int y) {
num_x = x; //雷的位置 x,不解釋
num_y = y; //雷的位置 y,不解釋.獲得是參數的值,所new Bomb的時候傳入雷的位置,套嵌2個for循環.
BombFlag = 0; //是不是被插旗了
BombRoundCount = 9; //環繞數
isBomb = false; //是雷
isClicked = false; //被點
isRight = false; //是真的.( 以上都很好理解,直譯^_^)
}
}
/* 計算方塊周圍雷數 */
public void CountRoundBomb() {
for (int i = 0; i < (int) Math.sqrt(BlockNum); i++) { //開方 障礙數
for (int j = 0; j < (int) Math.sqrt(BlockNum); j++) { //同上,我判斷,設計的雷區是正方形,
//這里是找完所有的坐標.
int count = 0;
// 當需要檢測的單元格本身無地雷的情況下,統計周圍的地雷個數
if (bombButton[i][j].isBomb != true) { //如果不是雷
for (int x = i - 1; x < i + 2; x++) { //從左邊1個,到右邊1個,一共3個
for (int y = j - 1; y < j + 2; y++) { //我不知道,java y坐標是上還是下,總之
//鄰近的上中下.(這里會多找一個自己)
if ( (x >= 0) && (y >= 0)
&& (x < ( (int) Math.sqrt(BlockNum)))
&& (y < ( (int) Math.sqrt(BlockNum)))) { //因邊前面 x=i-1,所以排除超出邊界
//的情況
if (bombButton[x][y].isBomb == true) { //如果是雷;
count++; //加一個
}
}
}
}
bombButton[i][j].BombRoundCount = count; //設置該Bomb環繞數的值
}
}
}
}
總之就是,建個一個Bomb類. 別外有一個方法統計那些不是雷的地方,的周圍有幾顆雷,到時候點開,顯示出來.
⑹ java 掃雷源代碼
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.Timer;
public class ScanLei1 extends JFrame implements ActionListener{
private static final long serialVersionUID = 1L;
private Container contentPane;
private JButton btn;
private JButton[] btns;
private JLabel b1;
private JLabel b2;
private JLabel b3;
private Timer timer;
private int row=9;
private int col=9;
private int bon=10;
private int[][] a;
private int b;
private int[] a1;
private JPanel p,p1,p2,p3;
public ScanLei1(String title){
super(title);
contentPane=getContentPane();
setSize(297,377);
this.setBounds(400, 100, 400, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
timer =new Timer(1000,(ActionListener) this);
a = new int[row+2][col+2];
initGUI();
}
public void initGUI(){
p3=new JPanel();
b=bon;
JMenuBar menuBar=new JMenuBar();
JMenu menu1=new JMenu("游戲");
JMenu menu2=new JMenu("幫助");
JMenuItem mi1=new JMenuItem("初級");
JMenuItem mi2 = new JMenuItem("中級");
JMenuItem mi3 =new JMenuItem("高級");
mi1.addActionListener(this);
menu1.add(mi1);
mi2.addActionListener(this);
menu1.add(mi2);
mi3.addActionListener(this);
menu1.add(mi3);
menuBar.add(menu1);
menuBar.add(menu2);
p3.add(menuBar);
b1=new JLabel(bon+"");
a1=new int[bon];
btn =new JButton("開始");
btn.addActionListener(this);
b2=new JLabel("0");
b3=new JLabel("");
btns=new JButton[row*col];
p=new JPanel();
p.setLayout(new BorderLayout());
contentPane.add(p);
p.add(p3,BorderLayout.NORTH);
//combo=new JComboBox(new Object[]{"初級","中級","高級"} );
//加監聽
/*combo.addItemListener(new ItemListener(){
}});*/
p1=new JPanel();
//在那個位置
//(( FlowLayout)p1.getLayout()).setAlignment( FlowLayout.RIGHT);
p1.add(b1);
p1.add(btn);
p1.add(b2);
p1.add(b3);
p.add(p3,BorderLayout.NORTH);
p.add(p1,BorderLayout.CENTER);
p2=new JPanel();
p2.setLayout(new GridLayout(row,col,0,0));
for(int i=0;i<row*col;i++){
btns[i]=new JButton("");
btns[i].setMargin(new Insets(0,0,0,0));
btns[i].setFont(new Font(null,Font.BOLD,25));
btns[i].addActionListener(this);
btns[i].addMouseListener(new NormoreMouseEvent());
p2.add(btns[i]);
}
contentPane.add(p,BorderLayout.NORTH);
contentPane.add(p2,BorderLayout.CENTER);
}
public void go(){
setVisible(true);
}
public static void main(String[] args){
new ScanLei1("掃雷").go();
}
public void out(int[][] a,JButton[] btns,ActionEvent e,int i,int x,int y){
int p=1;
if(a[x][y]==0){
a[x][y]=10;
btns[i].setEnabled(false); //33
for(int l=y-1;l<=y+1;l++){
int m=x-1-1;
int n=l-1;
p=1;
System.out.println(a[1][2]);
if(n>-1&&n<col&&m>-1&&m<row)
{
for(int q=0;q<row&&p==1;q++){//col-->row;
if(((n+col*q)>=(m*col))&&((n+col*q)<(m+1)*col)){
if(a[x-1][l]!=0&&a[x-1][l]!=10){
btns[n+col*q].setText(a[x-1][l]+"");
a[x-1][l]=10;
btns[n+col*q].setEnabled(false);
}
else if(a[x-1][l]==0){
//a[x-1][l]=10;
btns[n+col*q].setEnabled(false);
out(a,btns,e,n+col*q,x-1,l); ////55////
a[x-1][l]=10;
btns[n+col*q].setEnabled(false);
}
p=0;
}
}
}
p=1;
m=x;
if(n>-1&&n<col&&m>-1&&m<col)
{
for(int q=0;q<row&&p==1;q++){
if(((n+col*q)>=(m*col))&&((n+col*q)<(m+1)*col)){
if(a[x+1][l]!=0&&a[x+1][l]!=10){
btns[n+col*q].setText(a[x+1][l]+"");
a[x+1][l]=10;
btns[n+col*q].setEnabled(false);
}
else if(a[x+1][l]==0){
out(a,btns,e,n+col*q,x+1,l);///55////
a[x+1][l]=10;
btns[n+col*q].setEnabled(false);
}
p=0;
}
}
}
}
int m=x-1;
int n=y-1-1;
p=1;
if(n>-1&&n<col&&m>-1&&m<col)
{
for(int q=0;q<row&&p==1;q++){
if(((n+col*q)>=(m*col))&&((n+col*q)<(m+1)*col)){
if(a[x][y-1]!=0&&a[x][y-1]!=10){
btns[n+col*q].setText(a[x][y-1]+"");
a[x][y-1]=10;
btns[n+col*q].setEnabled(false);
}
else if(a[x][y-1]==0){
out(a,btns,e,n+col*q,x,y-1);
a[x][y-1]=10;
btns[n+col*q].setEnabled(false);
}
p=0;
}
}
}
p=1;
m=x-1;
n=y+1-1;
if(n>-1&&n<col&&m>-1&&m<col)
{
for(int q=0;q<row&&p==1;q++){
if(((n+col*q)>=(m*col))&&((n+col*q)<(m+1)*col)){
if(a[x][y+1]!=0&&a[x][y+1]!=10){
btns[n+col*q].setText(a[x][y+1]+"");
a[x][y+1]=10;
btns[n+col*q].setEnabled(false);
}
else if(a[x][y+1]==0){
out(a,btns,e,n+col*q,x,y+1);
a[x][y+1]=10;
btns[n+col*q].setEnabled(false);
}
p=0;
}
}
}
}
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand()=="初級"){
row=9;
col=9;
bon=10;
a1=new int[bon];
b=bon;
//setSize(297,377);
a = new int[row+2][col+2];
this.remove(p2);
timer.stop();
b1.setText("10");
b2.setText("0");
b3.setText("");
btns=new JButton[row*col];
p2=new JPanel();
p2.setLayout(new GridLayout(row,col,0,0));
for(int i=0;i<row*col;i++){
btns[i]=new JButton(" ");
btns[i].setMargin(new Insets(0,0,0,0));
btns[i].setFont(new Font(null,Font.BOLD,25));
btns[i].addActionListener(this);
btns[i].addMouseListener(new NormoreMouseEvent());
p2.add(btns[i]);
}
contentPane.add(p2,BorderLayout.CENTER);
//setSize(297,377);
this.pack();
for(int i=0;i<row*col;i++){
btns[i].setText(" ");
btns[i].setEnabled(true);
}
for(int i=0;i<row+2;i++){
for(int j=0;j<col+2;j++){
a[i][j]=0;
}
}
}else if(e.getActionCommand()=="中級"){
row=16;
col=16;
bon=40;
//setSize(33*col,33*row+80);
a1=new int[bon];
a = new int[row+2][col+2];
b=bon;
this.remove(p2);
timer.stop();
b1.setText("40");
b2.setText("0");
b3.setText("");
btns=new JButton[row*col];
p2=new JPanel();
p2.setLayout(new GridLayout(row,col,0,0));
for(int i=0;i<row*col;i++){
btns[i]=new JButton(" ");
btns[i].setMargin(new Insets(0,0,0,0));
btns[i].setFont(new Font(null,Font.BOLD,25));
btns[i].addActionListener(this);
btns[i].addMouseListener(new NormoreMouseEvent());
p2.add(btns[i]);
}
contentPane.add(p2,BorderLayout.CENTER);
this.pack();
//setSize(33*col,33*row+80);
for(int i=0;i<row*col;i++){
btns[i].setText("");
btns[i].setEnabled(true);
}
for(int i=0;i<row+2;i++){
for(int j=0;j<col+2;j++){
a[i][j]=0;
}
}
}else if(e.getActionCommand()=="高級"){
row=16;
col=32;
bon=99;
setSize(33*col,33*row+80);
a1=new int[bon];
a = new int[row+2][col+2];
b=bon;
this.remove(p2);
timer.stop();
b1.setText("99");
b2.setText("0");
b3.setText("");
btns=new JButton[row*col];
p2=new JPanel();
p2.setLayout(new GridLayout(row,col,0,0));
for(int i=0;i<row*col;i++){
btns[i]=new JButton(" ");
btns[i].setMargin(new Insets(0,0,0,0));
btns[i].setFont(new Font(null,Font.BOLD,25));
btns[i].addActionListener(this);
btns[i].addMouseListener(new NormoreMouseEvent());
p2.add(btns[i]);
}
contentPane.add(p2,BorderLayout.CENTER);
//setSize(33*col,33*row+80);
this.pack();
for(int i=0;i<row*col;i++){
btns[i].setText("");
btns[i].setEnabled(true);
}
for(int i=0;i<row+2;i++){
for(int j=0;j<col+2;j++){
a[i][j]=0;
}
}
}
if(e.getSource()==btn){
timer.start();
b=bon;
b3.setText("");
//System.out.println(bon);
//清空
for(int i=0;i<row*col;i++){
btns[i].setText("");
btns[i].setEnabled(true);
}
for(int i=0;i<row+2;i++){
for(int j=0;j<col+2;j++){
a[i][j]=0;
}
}
//產生隨機數
for(int i=0;i<bon;i++)
{ int p=1;
int m=(int)(Math.random()*row*col);
while(p==1){
int l=1;
int j;
for( j=0;j<i&&l==1;j++){
if(a1[j]==m){
m=(int)(Math.random()*row*col);
l=0;
}
}
if(j==i){
a1[i]=m;
p=0;
}
}
}
b1.setText(bon+"");
b2.setText("0");
//布雷
for(int i=0;i<bon;i++){
int x=(a1[i]/col+1);
int y=(a1[i]%col+1);
a[x][y]=100;
}
for(int i=0;i<row+2;i++){
for(int j=0;j<col+2;j++){
if(i==0||j==0||i==row+1||j==col+1){
a[i][j]=0;
}
}
}
for(int i=1;i<=row;i++){
for(int j=1;j<=col;j++){
if(a[i][j]!=100){
for(int l=j-1;l<=j+1;l++){
if(a[i-1][l]==100){
a[i][j]++;
}
if(a[i+1][l]==100){
a[i][j]++;
}
}
if(a[i][j-1]==100){
a[i][j]++;
}
if(a[i][j+1]==100){
a[i][j]++;
}
}
}
}
}
if(e.getSource()==timer)
{
String time=b2.getText().trim();
int t=Integer.parseInt(time);
//System.out.println(t);
if(t>=600){
timer.stop();
}else{
t++;
b2.setText(t+"");
}
}
for(int i=0;i<col*row;i++){
if(btns[i].getText()!="★")
{
int x=i/col+1;
int y=i%col+1;
if(e.getSource()==btns[i]&&a[x][y]==100){
btns[i].setText("★");
btns[i].setEnabled(false);
a[x][y]=10;
for(int k=0;k<col*row;k++){
int m1=k/col+1;
int n1=k%col+1;
if(a[m1][n1]!=10&&btns[k].getText()=="★"){
btns[k].setText("*o*");
}
}
for(int j=0;j<col*row;j++){
int m=j/col+1;
int n=j%col+1;
if(a[m][n]==100){
btns[j].setText("★");
btns[j].setEnabled(false);
b3.setText("你輸了 !!");
}
btns[j].setEnabled(false);
a[m][n]=10;
}
timer.stop();
}
else if(e.getSource()==btns[i]){
if(a[x][y]==0){
out(a,btns,e,i,x,y);
a[x][y]=10;
btns[i].setEnabled(false);
}
if(a[x][y]!=0&&a[x][y]!=10){
btns[i].setText(a[x][y]+"");
btns[i].setEnabled(false);
a[x][y]=10;
}
}
}else if(btns[i].getText()=="★"){
}
}
}
class NormoreMouseEvent extends MouseAdapter{
public void mouseClicked(MouseEvent e) {
System.out.println(b);
for(int i=0;i<col*row;i++){
int x1=i/col+1;
int y1=i%col+1;
if(e.getSource()==btns[i]&&btns[i].getText()!="★"&&a[x1][y1]!=10)
{
if(e.getButton()==MouseEvent.BUTTON3){
btns[i].setText("★");
b--;
if(b==0){
int flag=0;
for(int j=0;j<col*row;j++){
int x=j/col+1;
int y=j%col+1;
if(a[x][y]==100&&btns[j].getText()=="★"){
flag++;
}
}
if(flag==bon){
timer.stop();
b3.setText("你贏了!");
}
}
b1.setText(b+"");
}
}else if(e.getSource()==btns[i]&&btns[i].getText()=="★"&&a[x1][y1]!=-1){
if(e.getButton()==MouseEvent.BUTTON3){
btns[i].setText("");
b++;
if(b>bon){
b1.setText(bon+"");
}
else{
b1.setText(b+"");
}
btns[i].setEnabled(true);
}
}
}
}
}
}
⑺ java掃雷游戲代碼怎樣加個計時器
public int time=1000* 60; //60秒倒計時
public boolean running=true;//是否一直運行
JLabel label=new JLable();//顯示時間的標簽
//啟動計時
public void startTimer(){
new java.lang.Thread(new Runnable(){
public void run(){
while(running){
try{
Thread.sleep(1000);//睡一秒
}catch(Exception e){}
time--;
lable.setText(String.valueof(time));
this.update();// 把你的界面刷新一下
if(time<0){//倒計時到零,滿足條件
//your code: 游戲失敗,做點處理
running=false;//記得置成false否則不退出
}
}
}
}).start();
}
使用時,在你需要使用的時候 調用 startTimer()方法即可
你可以看到, startTimer方法里的線程在不斷地改變time的值,每秒減一
所以你需要在你的GUI界面上安裝一個 JLabel label,不斷地改變label的內容為time就行了
⑻ 求高手幫忙一個「掃雷」游戲的JAVA的程序代碼
import javax.swing.ImageIcon; //程序入口
public class Block {
String name; //名字,比如"雷"或數字
int aroundMineNumber; //周圍雷的數目
ImageIcon mineIcon; //雷的圖標
boolean isMine=false; //是否是雷
boolean isMark=false; //是否被標記
boolean isOpen=false; //是否被挖開
public void setName(String name) {
this.name=name;
}
//設置周圍的雷數
public void setAroundMineNumber(int n) {
aroundMineNumber=n;
}
//獲得周圍的雷數
public int getAroundMineNumber() {
return aroundMineNumber;
}
public String getName() {
return name;
}
//判斷是否是雷
public boolean isMine() {
return isMine;
}
//設置是否為雷
public void setIsMine(boolean b) {
isMine=b;
}
//設置雷的圖標
public void setMineIcon(ImageIcon icon){
mineIcon=icon;
}
//獲得雷的圖標
public ImageIcon getMineicon(){
return mineIcon;
}
//確定雷是否被挖開
public boolean getIsOpen() {
return isOpen;
}
//設置為已經被挖開
public void setIsOpen(boolean p) {
isOpen=p;
}
//返回此處是否已經被標記
public boolean getIsMark() {
return isMark;
}
//設置此處是否已經被標記
public void setIsMark(boolean m) {
isMark=m;
}
import javax.swing.*;
import java.awt.*;
public class BlockView extends JPanel{
JLabel blockNameOrIcon; //用來顯示Block對象的name、number和mineIcon屬性
JButton blockCover; //用來遮擋blockNameOrIcon.
CardLayout card; //卡片式布局
BlockView(){
card=new CardLayout();
setLayout(card);
blockNameOrIcon=new JLabel("",JLabel.CENTER);
blockNameOrIcon.setHorizontalTextPosition(AbstractButton.CENTER);
blockNameOrIcon.setVerticalTextPosition(AbstractButton.CENTER);
blockCover=new JButton();
add("cover",blockCover);
add("view",blockNameOrIcon);
}
//給出視覺效果變化
public void giveView(Block block){
// 如果是雷,將對應的圖標和文字更改
if(block.isMine){
blockNameOrIcon.setText(block.getName());
blockNameOrIcon.setIcon(block.getMineicon());
}
else {
int n=block.getAroundMineNumber();
if(n>=1)
blockNameOrIcon.setText(""+n);
else
blockNameOrIcon.setText(" ");
}
}
public void seeBlockNameOrIcon(){
card.show(this,"view");
validate();
}
public void seeBlockCover(){
card.show(this,"cover");
validate();
}
public JButton getBlockCover(){
return blockCover;
}
}