「扫雷java类」扫雷java程序详细解析

博主:adminadmin 2022-11-25 22:39:06 62

今天给各位分享扫雷java类的知识,其中也会对扫雷java程序详细解析进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

怎样用JAVA实现扫雷游戏

要详细代码?还是只要启动?

java编写实现,代码如下: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) ][];

for(int i = 0 ; i (int)Math.sqrt(BlockNum) ; i++)

{

bombButton[ i ]=new Bomb[ (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 ].setForeground( Color.gray);

bombButton[ i ][ j ].addActionListener(this);

bombButton[ i ][ j ].addMouseListener(this);

}

for(int i = 0 ; i (int)Math.sqrt(BlockNum) ; i++ )

for(int j = 0 ; j (int)Math.sqrt(BlockNum) ; j++ )

mainPanel.add(bombButton[ i ][ j ]);

c.add(mainPanel,"Center");

startBomb();

setSize(400,400);

setLocation(350,200);

setResizable(false);

}

/*布雷*/

public void startBomb()

{

for(int i=0;iBombNum;i++)

{

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)

i--;

else

bombButton[ x ][ y ].isBomb=true ;

}

}

/*重新开始*/

public void replay()

{

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 ].setEnabled(true);

bombButton[ i ][ j ].setText("");

bombButton[ i ][ j ].setIcon(null);

}

startBomb();

}

/*是否挖完了所有的雷*/

public void isWin()

{

int findBomb=0; //找到的地雷数

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 ].isRight == true)

findBomb++;

}

if( findBomb == Integer.parseInt(text.getText().trim()) )

{

JOptionPane msg = new JOptionPane();

JOptionPane.showMessageDialog(this,"您挖完了所有的雷,您胜利了!","您胜利了",2);

}

}

/*计算方块周围雷数 */

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) {

if ( (i - 1 = 0) (j - 1 = 0)) {

if (bombButton[i - 1][j - 1].isBomb == true) {

count += 1; //检测左上方空格是否是地雷

}

}

if ( (i - 1 = 0)) {

if (bombButton[i - 1][ j ].isBomb == true) {

count += 1; //检测上方空格是否为地雷

}

}

if ( (i - 1 = 0) (j + 1 = (int)Math.sqrt(BlockNum)-1)) {

if (bombButton[i - 1][j + 1] .isBomb == true) {

count += 1; //检测右上方是否为地雷

}

}

if ( (j - 1 = 0)) {

if (bombButton[ i ][j - 1] .isBomb == true) {

count += 1; //检测左边是否为地雷

}

}

if ( (i = 0) (j + 1 = (int)Math.sqrt(BlockNum)-1)) {

if (bombButton[ i ][j + 1].isBomb == true) {

count += 1; //右边

}

}

if ( (j - 1 = 0) (i + 1 = (int)Math.sqrt(BlockNum)-1)) {

if (bombButton[i + 1][j - 1].isBomb == true) {

count += 1; //左下

}

}

if ( (i + 1 = (int)Math.sqrt(BlockNum)-1)) {

if (bombButton[i + 1][ j ].isBomb == true) {

count += 1; //下

}

}

if ( (j + 1 = (int)Math.sqrt(BlockNum)-1) (i + 1 = Math.sqrt(BlockNum)-1)) {

if (bombButton[i + 1][j + 1].isBomb == true) {

count += 1; //右下

}

}

bombButton[ i ][ j ].BombRoundCount = count;

}

}

}

}

/**当选中的位置为空,则翻开周围的地图**/

public void isNull(Bomb[][] bombButton,Bomb ClickecButton)

{

int i,j;

i=ClickecButton.num_x;

j=ClickecButton.num_y;

if (ClickecButton.isBomb==true) {

}

else {

if ( (i - 1 = 0) (j - 1 = 0)) { //检测左上方空格是否是空

if (bombButton[i - 1][j - 1].isBomb == false bombButton[i - 1][j - 1].isClicked == false bombButton[i - 1][j - 1].isRight == false) {

bombButton[i - 1][j - 1].setText((bombButton[i - 1][j - 1].BombRoundCount)+"");

bombButton[i - 1][j - 1].setEnabled(false);

bombButton[i - 1][j - 1].isClicked=true;

}

}

if ( (i - 1 = 0)) { //检测上方空格是否为空

if (bombButton[i - 1][ j ] .isBomb == false bombButton[i - 1][ j ].isClicked == false bombButton[i - 1][ j ].isRight == false) {

bombButton[i - 1][ j ].setText((bombButton[i - 1][ j ].BombRoundCount)+"");

bombButton[i - 1][ j ].setEnabled(false);

bombButton[i - 1][ j ].isClicked=true;

}

}

if ( (i - 1 = 0) (j + 1 = ((int)Math.sqrt(BlockNum)-1)) ) { //检测右上方是否为空

if (bombButton[i - 1][j + 1] .isBomb == false bombButton[i - 1][j + 1].isClicked == false bombButton[i - 1][j + 1].isRight == false) {

bombButton[i - 1][j + 1].setText((bombButton[i - 1][j + 1].BombRoundCount)+"");

bombButton[i - 1][j + 1].setEnabled(false);

bombButton[i - 1][j + 1].isClicked=true;

}

}

if ( (j - 1 = 0)) { //检测左边是否为空

if (bombButton[ i ][j - 1].isBomb == false bombButton[ i ][j - 1].isClicked == false bombButton[ i ][j - 1].isRight == false) {

bombButton[ i ][j - 1].setText((bombButton[ i ][j - 1].BombRoundCount)+"");

bombButton[ i ][j - 1].setEnabled(false);

bombButton[ i ][j - 1].isClicked=true;

}

}

if ( (i = 0) (j + 1 = ((int)Math.sqrt(BlockNum)-1)) ) { //检测右边空格是否是空

if (bombButton[ i ][j + 1].isBomb == false bombButton[ i ][j + 1].isClicked == false bombButton[ i ][j + 1].isRight == false) {

bombButton[ i ][j + 1].setText((bombButton[ i ][j + 1].BombRoundCount)+"");

bombButton[ i ][j + 1].setEnabled(false);

bombButton[ i ][j + 1].isClicked=true;

}

}

if ( (j - 1 = 0) (i + 1 = ((int)Math.sqrt(BlockNum)-1)) ) { //检测左下空格是否是空

if (bombButton[i + 1][j - 1].isBomb == false bombButton[i + 1][j - 1].isClicked == false bombButton[i + 1][j - 1].isRight == false) {

bombButton[i + 1][j - 1].setText((bombButton[i + 1][j - 1].BombRoundCount)+"");

bombButton[i + 1][j - 1].setEnabled(false);

bombButton[i + 1][j - 1].isClicked=true;

}

}

if ( (i + 1 = ((int)Math.sqrt(BlockNum)-1)) ) { //检测下边空格是否是空

if (bombButton[i + 1][ j ].isBomb == false bombButton[i + 1][ j ].isClicked == false bombButton[i + 1][ j ].isRight == false) {

bombButton[i + 1][ j ].setText((bombButton[i + 1][ j ].BombRoundCount)+"");

bombButton[i + 1][ j ].setEnabled(false);

bombButton[i + 1][ j ].isClicked=true;

}

}

if ( (j + 1 = ((int)Math.sqrt(BlockNum)-1) ) (i + 1 = ((int)Math.sqrt(BlockNum)-1)) ) { //检测右下边空格是否是空

if (bombButton[i + 1][j + 1].isBomb == false bombButton[i + 1][j + 1].isClicked == false bombButton[i + 1][j + 1].isRight == false) {

bombButton[i + 1][j + 1].setText((bombButton[i + 1][j + 1].BombRoundCount)+"");

bombButton[i + 1][j + 1].setEnabled(false);

bombButton[i + 1][j + 1].isClicked=true;

}

}

if ( (i - 1 = 0) (j - 1 = 0))//检测左上

isNull(bombButton,bombButton[i - 1][j - 1]);

if ( (i - 1 = 0))

isNull( bombButton,bombButton[i - 1][ j ]);//检测上方

if ( (i - 1 = 0) (j + 1 = (int)Math.sqrt(BlockNum)-1))

isNull( bombButton,bombButton[i - 1][j + 1]);//检测右上

if ( (j - 1 = 0))

isNull(bombButton,bombButton[i][j - 1]);//检测左边

if ( (i = 0) (j + 1 = ((int)Math.sqrt(BlockNum)-1)) )

isNull(bombButton,bombButton[i][j + 1]);//检测右边

if ( (j - 1 = 0) (i + 1 = ((int)Math.sqrt(BlockNum)-1)) )

isNull(bombButton,bombButton[i + 1][j - 1]); //检测左下

if ( (i + 1 = ((int)Math.sqrt(BlockNum)-1)) ) //检测下

isNull(bombButton,bombButton[i + 1][ j ]);

if ( (j + 1 = ((int)Math.sqrt(BlockNum)-1)) (i + 1 = ((int)Math.sqrt(BlockNum)-1)) ) //检测右下

isNull(bombButton,bombButton[i + 1][j + 1]);

}

}

public void actionPerformed(ActionEvent e)

{

CountRoundBomb();

if(((Bomb)e.getSource()).isBomb==false ((Bomb)e.getSource()).isClicked == false)

{

((Bomb)e.getSource()).setText(( ((Bomb)e.getSource()).BombRoundCount )+"");

((Bomb)e.getSource()).isClicked=true;

((Bomb)e.getSource()).setIcon(null);

((Bomb)e.getSource()).setEnabled(false);

if((((Bomb)e.getSource()).BombRoundCount) == 0)

isNull(bombButton,(Bomb)e.getSource());

isWin();

}

else if(((Bomb)e.getSource()).isBomb == true)

{

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 ].setIcon(icon_bomb);

}

((Bomb)e.getSource()).setIcon(icon_bomb_big);

JOptionPane msg = new JOptionPane();

JOptionPane.showMessageDialog(this,"你踩到地雷了,按确定重来","你踩到地雷了",2);

replay();

}

}

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(BombNum 0 bombSource.isRight == false ){

bombSource.setIcon(icon_flag);

bombSource.isRight = true;

BombNum--;

}

isWin();

nowBomb.setText("当前雷数"+" "+BombNum+"");

}

else if(bombSource.BombFlag == 2)

{

if( (BombNum !=0 ) ||(BombNum ==0 (bombSource.getIcon()==icon_flag)) )

BombNum++;

bombSource.setIcon(icon_question);

nowBomb.setText("当前雷数"+" "+BombNum+"");

}

else if(bombSource.BombFlag == 0)

{

bombSource.setIcon(null);

bombSource.isRight = false;

}

}

}

public void mouseEntered(MouseEvent e)

{}

public void mouseReleased(MouseEvent e)

{}

public void mouseExited(MouseEvent e)

{}

public void mousePressed(MouseEvent e)

{}

}

/*主类*/

public class Main

{

public static void main(String args[])

{

(new MainBomb()).show();

}

}

运行在Eclipse环境下的java扫雷游戏的初级代码是什么?

import java.awt.Button;\x0d\x0aimport java.util.Set;\x0d\x0a// 每一个小方块类\x0d\x0apublic class Diamond extends Button {\x0d\x0aprivate Diamond[] diamonds;\x0d\x0a\x0d\x0a// 该小方块周围的八个方向上的小方块\x0d\x0aprivate Diamond east;\x0d\x0aprivate Diamond north;\x0d\x0aprivate Diamond northEast;\x0d\x0aprivate Diamond northWest;\x0d\x0aprivate Diamond south;\x0d\x0aprivate Diamond southEast;\x0d\x0aprivate Diamond southWest;\x0d\x0aprivate Diamond west;\x0d\x0a\x0d\x0aprivate boolean isBomb;// 是否是雷\x0d\x0aprivate boolean isChange;// 又没有被翻过\x0d\x0aprivate int no;// 产生的方块的编号\x0d\x0a\x0d\x0a// 持有所有小方块的引用,方便进行操作\x0d\x0apublic Diamond(Diamond[] diamonds) {\x0d\x0athis.diamonds = diamonds;\x0d\x0a}\x0d\x0a\x0d\x0a// 按键时方块发生改变\x0d\x0apublic boolean change() {\x0d\x0athis.isChange = true;// 说明已经翻过了\x0d\x0aif(isBomb) {// 触雷\x0d\x0a//this.setBackground(Color.red);\x0d\x0areturn true;\x0d\x0a} else {// 不是雷,就显示周围雷的数目\x0d\x0a//this.setLabel(this.getNearBombNo() + "");\x0d\x0athis.setLabel(this.getNearBombNo() + "");\x0d\x0a//if(this.getNearBombNo() == 0) {\x0d\x0a//this.moveon();\x0d\x0a//}\x0d\x0areturn false;\x0d\x0a}\x0d\x0a}\x0d\x0a\x0d\x0a// 获得该小方块周围雷的数量\x0d\x0apublic int getNearBombNo() {\x0d\x0aint no = 0;\x0d\x0aif(this.northWest != null this.northWest.isBomb) no++;\x0d\x0aif(this.north != null this.north.isBomb) no++;\x0d\x0aif(this.northEast != null this.northEast.isBomb) no++;\x0d\x0aif(this.east != null this.east.isBomb) no++;\x0d\x0aif(this.southEast != null this.southEast.isBomb) no++;\x0d\x0aif(this.south != null this.south.isBomb) no++;\x0d\x0aif(this.southWest != null this.southWest.isBomb) no++;\x0d\x0aif(this.west != null this.west.isBomb) no++;\x0d\x0a\x0d\x0areturn no;\x0d\x0a}\x0d\x0a\x0d\x0a// 获得该小方块周围的小方块\x0d\x0apublic Diamond getNearDimaond(int i) {\x0d\x0aint index = -1;\x0d\x0aswitch (i) {\x0d\x0acase 1:// 1表示西北,2,表示北,以此类推\x0d\x0aindex = no - 10;\x0d\x0aif(index return null;\x0d\x0a} else {\x0d\x0areturn diamonds[index];\x0d\x0a}\x0d\x0acase 2:\x0d\x0aindex = no - 9;\x0d\x0aif(index return null;\x0d\x0a} else {\x0d\x0areturn diamonds[index];\x0d\x0a}\x0d\x0acase 3:\x0d\x0aindex = no - 8;\x0d\x0aif(index return null;\x0d\x0a} else {\x0d\x0areturn diamonds[index];\x0d\x0a}\x0d\x0acase 4:\x0d\x0aindex = no + 1;\x0d\x0aif(no == 9 || no == 18 || no == 27 || no == 36 || no == 45 || no == 54 || no == 63 || no == 72 || no == 81) {\x0d\x0areturn null;\x0d\x0a} else {\x0d\x0areturn diamonds[index];\x0d\x0a}\x0d\x0acase 5:\x0d\x0aindex = no + 10;\x0d\x0aif(index = 81 ||no == 9 || no == 18 || no == 27 || no == 36 || no == 45 || no == 54 || no == 63 || no == 72 || no == 81) {\x0d\x0areturn null;\x0d\x0a} else {\x0d\x0areturn diamonds[index];\x0d\x0a}\x0d\x0acase 6:\x0d\x0aindex = no + 9;\x0d\x0aif(index 81) {\x0d\x0areturn null;\x0d\x0a} else {\x0d\x0areturn diamonds[index];\x0d\x0a}\x0d\x0acase 7:\x0d\x0aindex = no + 8;\x0d\x0aif(index = 81 || no==1 || no == 10 || no == 19 || no == 28 || no == 37 || no == 46 || no == 55 || no == 64 || no == 73) {\x0d\x0areturn null;\x0d\x0a} else {\x0d\x0areturn diamonds[index];\x0d\x0a}\x0d\x0acase 8:\x0d\x0aindex = no - 1;\x0d\x0aif(no==1 || no==10 || no == 19 || no == 28 || no == 37 || no == 46 || no == 55 || no == 64 || no == 73) {\x0d\x0areturn null;\x0d\x0a} else {\x0d\x0areturn diamonds[index];\x0d\x0a}\x0d\x0a}\x0d\x0areturn null;\x0d\x0a}\x0d\x0a\x0d\x0a// 递归,set是用来装已经翻过的小方块的,不然会死循环,为什么用set,因为set是不重复的\x0d\x0apublic void moveon(Set set) {\x0d\x0a\x0d\x0aset.add(this);// 先把自己加上\x0d\x0aif(this.getNorthWest() != null this.getNorthWest().isBomb == false) {\x0d\x0athis.getNorthWest().change();\x0d\x0a\x0d\x0aif(this.getNorthWest().getNearBombNo() == 0) {\x0d\x0aif(set.contains(this.getNorthWest()) == false)\x0d\x0athis.getNorthWest().moveon(set);\x0d\x0a}\x0d\x0a\x0d\x0aset.add(this.getNorthWest());\x0d\x0a}\x0d\x0a\x0d\x0aif(this.getNorth() != null this.getNorth().isBomb == false) {\x0d\x0athis.getNorth().change();\x0d\x0aif(this.getNorth().getNearBombNo() == 0) {\x0d\x0aif(set.contains(this.getNorth()) == false)\x0d\x0athis.getNorth().moveon(set);\x0d\x0a}\x0d\x0a\x0d\x0aset.add(this.getNorth());\x0d\x0a} \x0d\x0a\x0d\x0aif(this.getNorthEast() != null this.getNorthEast().isBomb == false) {\x0d\x0athis.getNorthEast().change();\x0d\x0aif(this.getNorthEast().getNearBombNo() == 0) {\x0d\x0aif(set.contains(this.getNorthEast()) == false)\x0d\x0athis.getNorthEast().moveon(set);\x0d\x0a}\x0d\x0a\x0d\x0aset.add(this.getNorthEast());\x0d\x0a} \x0d\x0a\x0d\x0aif(this.getEast() != null this.getEast().isBomb == false) {\x0d\x0athis.getEast().change();\x0d\x0aif(this.getEast().getNearBombNo() == 0) {\x0d\x0aif(set.contains(this.getEast()) == false)\x0d\x0athis.getEast().moveon(set);\x0d\x0a}\x0d\x0a\x0d\x0aset.add(this.getEast());\x0d\x0a} \x0d\x0a\x0d\x0aif(this.getSouthEast() != null this.getSouthEast().isBomb == false) {\x0d\x0athis.getSouthEast().change();\x0d\x0aif(this.getSouthEast().getNearBombNo() == 0) {\x0d\x0aif(set.contains(this.getSouthEast()) == false)\x0d\x0athis.getSouthEast().moveon(set);\x0d\x0a}\x0d\x0a\x0d\x0aset.add(this.getSouthEast());\x0d\x0a} \x0d\x0a\x0d\x0aif(this.getSouth() != null this.getSouth().isBomb == false) {\x0d\x0athis.getSouth().change();\x0d\x0aif(this.getSouth().getNearBombNo() == 0) {\x0d\x0aif(set.contains(this.getSouth()) == false)\x0d\x0athis.getSouth().moveon(set);\x0d\x0a}\x0d\x0a\x0d\x0aset.add(this.getSouth());\x0d\x0a} \x0d\x0a\x0d\x0aif(this.getSouthWest() != null this.getSouthWest().isBomb == false) {\x0d\x0athis.getSouthWest().change();\x0d\x0aif(this.getSouthWest().getNearBombNo() == 0) {\x0d\x0aif(set.contains(this.getSouthWest()) == false)\x0d\x0athis.getSouthWest().moveon(set);\x0d\x0a}\x0d\x0a\x0d\x0aset.add(this.getSouthWest());\x0d\x0a} \x0d\x0a\x0d\x0aif(this.getWest() != null this.getWest().isBomb == false) {\x0d\x0athis.getWest().change();\x0d\x0aif(this.getWest().getNearBombNo() == 0) {\x0d\x0aif(set.contains(this.getWest()) == false)\x0d\x0athis.getWest().moveon(set);\x0d\x0a}\x0d\x0a\x0d\x0aset.add(this.getWest());\x0d\x0a} \x0d\x0a}\x0d\x0a\x0d\x0a/*public Diamond[] getDiamonds() {\x0d\x0areturn diamonds;\x0d\x0a}*/\x0d\x0a\x0d\x0apublic Diamond getEast() {\x0d\x0areturn east;\x0d\x0a}\x0d\x0a\x0d\x0apublic int getNo() {\x0d\x0areturn no;\x0d\x0a}\x0d\x0a\x0d\x0apublic Diamond getNorth() {\x0d\x0areturn north;\x0d\x0a}\x0d\x0a\x0d\x0apublic Diamond getNorthEast() {\x0d\x0areturn northEast;\x0d\x0a}\x0d\x0a\x0d\x0apublic Diamond getNorthWest() {\x0d\x0areturn northWest;\x0d\x0a}\x0d\x0a\x0d\x0apublic Diamond getSouth() {\x0d\x0areturn south;\x0d\x0a}\x0d\x0a\x0d\x0apublic Diamond getSouthEast() {\x0d\x0areturn southEast;\x0d\x0a}\x0d\x0a\x0d\x0apublic Diamond getSouthWest() {\x0d\x0areturn southWest;\x0d\x0a}\x0d\x0a\x0d\x0apublic Diamond getWest() {\x0d\x0areturn west;\x0d\x0a}\x0d\x0a\x0d\x0apublic boolean isBomb() {\x0d\x0areturn isBomb;\x0d\x0a}\x0d\x0a\x0d\x0apublic boolean isChange() {\x0d\x0areturn isChange;\x0d\x0a}\x0d\x0a\x0d\x0apublic void setBomb(boolean isBomb) {\x0d\x0athis.isBomb = isBomb;\x0d\x0a}\x0d\x0a\x0d\x0apublic void setChange(boolean isChange) {\x0d\x0athis.isChange = isChange;\x0d\x0a}\x0d\x0a\x0d\x0apublic void setDiamonds(Diamond[] diamonds) {\x0d\x0athis.diamonds = diamonds;\x0d\x0a}\x0d\x0a\x0d\x0apublic void setEast(Diamond east) {\x0d\x0athis.east = east;\x0d\x0a}\x0d\x0a\x0d\x0apublic void setNo(int no) {\x0d\x0athis.no = no;\x0d\x0a}\x0d\x0a\x0d\x0apublic void setNorth(Diamond north) {\x0d\x0athis.north = north;\x0d\x0a}\x0d\x0a\x0d\x0apublic void setNorthEast(Diamond northEast) {\x0d\x0athis.northEast = northEast;\x0d\x0a}\x0d\x0a\x0d\x0apublic void setNorthWest(Diamond northWest) {\x0d\x0athis.northWest = northWest;\x0d\x0a}\x0d\x0a\x0d\x0apublic void setSouth(Diamond south) {\x0d\x0athis.south = south;\x0d\x0a}\x0d\x0a\x0d\x0apublic void setSouthEast(Diamond southEast) {\x0d\x0athis.southEast = southEast;\x0d\x0a}\x0d\x0a\x0d\x0apublic void setSouthWest(Diamond southWest) {\x0d\x0athis.southWest = southWest;\x0d\x0a}\x0d\x0a\x0d\x0apublic void setWest(Diamond west) {\x0d\x0athis.west = west;\x0d\x0a}\x0d\x0a\x0d\x0a}

关于扫雷的Java

你用I/0 把要保存的东西,直接写到*.ini文件中不就可以了吗

这个是我 写 连连看游戏,用来保存记录的,自己参考下,很简单。

import java.awt.Point;

import java.io.*;

import java.util.*;

public class LoadAndSave {

private static final Properties prop=new Properties();

public static File recordFile=new File("record.dat");

public static File setFile=new File("setup.ini");

public static StringBuilder[] setLines;

public static int getRecord(int total) {

int seconds=999999999;

try {

BufferedReader bReader=new BufferedReader(new InputStreamReader(new FileInputStream(recordFile)));

String line=null;

while((line=bReader.readLine())!=null)

try {

String[] values=line.split("\t");

int n=Integer.parseInt(values[1]);

int s=Integer.parseInt(values[2]);

if(n==totalsseconds) seconds=s;

} catch (RuntimeException e) {

}

bReader.close();

} catch (Exception e) {

}

return seconds;

}

public static void load(){

try {

prop.loadFromXML(new FileInputStream(setFile));

} catch (Exception e) {

}

}

public static void save(){

try {

prop.storeToXML(new FileOutputStream(setFile), "no comment");

} catch (Exception e) {

}

}

public static void saveLevel(int level){

prop.setProperty("level", level+"");

save();

}

public static void saveLocation(Point p) {

prop.setProperty("frameX", p.x+"");

prop.setProperty("frameY", p.y+"");

save();

}

public static void saveRecord(int total, int seconds) {

try {

FileOutputStream fos=new FileOutputStream(recordFile,true);

PrintWriter out=new PrintWriter(fos,true);

out.println(new Date(System.currentTimeMillis())+"\t"+total+"\t"+seconds);

out.close();

} catch (FileNotFoundException e) {

}

}

}

用java怎么写扫雷程序

首先要写一个UI,也就是操作界面,使用java.swing.*内的东西就可以搞定;

其次写一个hander,也就是具体的按钮响应,UI的初始化(哪里有雷),怎么触发雷和其他的;

一般来说简单的扫雷模型就好了,如果需要更有意思点,可以写一些数据库的操作内容的tool类具体的就是处理历史操作记录,场均数据或多人竞技的特点。

如果你是说你没有设计思路,我可以给你个提示:递归算法是触发扫雷的方法,初始化用随机数来做。

扫雷java类的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于扫雷java程序详细解析、扫雷java类的信息别忘了在本站进行查找喔。

The End

发布于:2022-11-25,除非注明,否则均为首码项目网原创文章,转载请注明出处。