Java 创建扫雷舰时,如何在更改难度时重置板。
这是瓷砖类 当我改变难度时,或者当我计划设置自定义板选项时,我不知道如何根据给定的瓷砖数量自动调整板的大小Java 创建扫雷舰时,如何在更改难度时重置板。,java,swing,jmenu,minesweeper,Java,Swing,Jmenu,Minesweeper,这是瓷砖类 当我改变难度时,或者当我计划设置自定义板选项时,我不知道如何根据给定的瓷砖数量自动调整板的大小 如果你说不出。。。我对代码很陌生。谢谢你的帮助。这在很大程度上不是已经做到了吗 import java.awt.Color; import java.awt.Image; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.SwingCon
如果你说不出。。。我对代码很陌生。谢谢你的帮助。这在很大程度上不是已经做到了吗
import java.awt.Color;
import java.awt.Image;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
// Tile class for mine sweeper
public class Tile extends JLabel
{
private char occupied;
private int column;
private int row;
private JLabel OccupiedB;
private JLabel OccupiedC;
private JLabel OccupiedE;
private JLabel OccupiedF;
//Icon flag = new ImageIcon("flag.ico");
/*
whatever.setIcon(new ImageIcon("filename.ext"));
or
Icon myIcon = new ImageIcon("filename.ext");
whatever.setIcon(myIcon);
*/
public Tile(int col, int newRow)
{
super();
setBackground(Color.GRAY);
setOpaque(true);
occupied = 'g';
column = col;
row = newRow;
}
public boolean setOccupied(char Ecolumn)
{
occupied = Ecolumn;
if(occupied == 'b') // If the tile is a bomb
{
}
else if(occupied == 'c') // If the tile is clear
{
setBackground(Color.WHITE);
}
else if(occupied == 'e') // If the tile is empty or surrounding a bomb
{
}
else if(occupied == 'f') // If the tile is a flag
{
setText("F");
//setIcon(new ImageIcon("flag.ico"));
}
return true;
}
public int getColumn()
{
return column;
}
public void setColumn(int column)
{
this.column = column;
}
public int getRow()
{
return row;
}
public JLabel getOccupiedB()
{
return OccupiedB;
}
public void setOccupiedB(JLabel occupiedB)
{
OccupiedB = occupiedB;
}
public JLabel getOccupiedC()
{
return OccupiedC;
}
public void setOccupiedC(JLabel occupiedC)
{
OccupiedC = occupiedC;
}
public JLabel getOccupiedE()
{
return OccupiedE;
}
public void setOccupiedE(JLabel occupiedE)
{
OccupiedE = occupiedE;
}
public JLabel getOccupiedF()
{
return OccupiedF;
}
public void setOccupiedF(JLabel occupiedF)
{
OccupiedF = occupiedF;
}
public void setRow(int row)
{
this.row = row;
}
public char getOccupied()
{
return occupied;
}
}
从菜单中选择选项的人将触发事件。事件处理程序包含一个if/else块,该块可以是:exit、设置为easy、设置为medium、设置为hard。makeBoard函数处理灰色瓷砖的实际显示,我能告诉你的是,占用设置为“g”灰色?适用于所有瓷砖。如果你问的是炸弹的实际生成等,我没有看到任何关于这方面的东西。它要么是为你处理的,你没有提供代码,要么是你自己写的
您需要将int easyFlags设置为针对特定难度获得的数量。
您需要将flagCounter标签设置为0。
您需要将计时器标签设置为0。
您需要将int mines设置为难度最大的地雷数
对于menu.equalsEasy if block,它类似于:
if (menu.equals("Easy"))
{
setSize(500,600);
makeBoard(9,9);
// TODO need to reset the board
}
if (menu.equals("Medium"))
{
setSize(850,950);
//TODO figure out how to change the flag counter...
makeBoard(16, 16);
}
if (menu.equals("Hard"))
{
setSize(1550,950);
makeBoard(30,16);
}
可能还有更多,但我不想做那些显然是学校为你做的项目,哈哈为了更快地得到更好的帮助,发布一篇文章。
if (menu.equals("Easy"))
{
setSize(500,600);
makeBoard(9,9);
// TODO need to reset the board
}
if (menu.equals("Medium"))
{
setSize(850,950);
//TODO figure out how to change the flag counter...
makeBoard(16, 16);
}
if (menu.equals("Hard"))
{
setSize(1550,950);
makeBoard(30,16);
}
if (menu.equals("Easy"))
{
setSize(500,600);
makeBoard(9,9);
flagCounter.setText("0");
timecounter.setText("0"); //or "0:00" or w/e
mines = 10;
easyFlags = 10;
}