我有三類:Mazesolver
,Hexagon
和Maze
。當我嘗試在Mazesolver
類中創建一個Hexagon
對象時,會發生錯誤。任何人都可以請幫我解決這個問題嗎?此外,在迷宮中獲得對開始Hexagon
的引用意味着什麼?當參數超出範圍時,如何在另一個類中創建對象?
public class Hexagon extends HexComponent
{
// constants
private static final Color WALL_COLOR = Color.BLACK;
private static final Color START_COLOR = Color.GREEN;
private static final Color END_COLOR = Color.YELLOW;
private static final Color UNVISITED_COLOR = Color.CYAN;
private static final Color PROCESSED_COLOR = Color.BLUE;
private static final Color PUSHED_COLOR = Color.MAGENTA;
private static final Color END_PROCESSED_COLOR = Color.RED;
private static final Color START_PROCESSED_COLOR = Color.PINK;
//enum to represent available hexagon types
public static enum HexType{WALL, START, END, UNVISITED, PROCESSED, PUSHED, END_PROCESSED, START_PROCESSED};
// Attributes
private HexType type; // Stores the type of Hexagon this currently is
private boolean isStart; // Is this the start?
private boolean isEnd; // Is this the end?
private Hexagon[] neighbors; // Stores the hexagons which surround this one on each of 6 sides
/**
* Create a Hexagon tile of the specified type
* @param t the HexType to create
*/
public Hexagon(HexType t) {
this.type = t;
this.isStart = t == HexType.START;
this.isEnd = t == HexType.END;
//set the initial color based on the initial type
this.setColor(this.type);
//allocate space for the neighbor array
this.neighbors = new Hexagon[6];
}
如何在MazeSolver中創建一個Hexagon對象?
public class MazeSolver
{
public static void main (String[] args) {
try {
if (args.length < 1) {
throw new IllegalArgumentException("No Maze Provided");
}
String maze0 = args[0];
private ArrayStack<String> steps;
Hexagon Start = new Hexagon(t); //error
}
你的'ArrayStack'實例'steps'具有非法修飾符。你不能在方法中的局部範圍變量上使用'private'。此外,您未包含任何有關您所看到的錯誤類型的詳細信息。請將這些詳細信息添加到您的帖子。因爲,不可能說出哪些錯誤是由於錯誤的複製/粘貼與實際問題所致。 – nbrooks