我有三类: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