だから今、同じパッケージに含まれているBreakoutCourt.javaで使用したいLevels列挙型を含むBrick.javaがあります。これは(デフォルトパッケージ)です。
import Brick.level; と書くと、BreakoutCourt で、The Import Brick Cannot Be Resolved というメッセージが表示されます。import static Brick.Level! と書いても、そのメッセージが表示されます。
Brick.java に含まれるレベル列挙は次のようになります。
public class Brick {
public static final int BWIDTH = 60;
public static final int BHEIGHT = 20;
private int xPos, yPos;
private Level brickLevel;
//This sets up the different levels of bricks.
enum Level{
LUNATIC (4, 40, Color.MAGENTA),
HARD (3, 30, Color.PINK),
MEDIUM (2, 20, Color.BLUE),
EASY (1, 10, Color.CYAN),
DEAD (0, 0, Color.WHITE);
private int hitpoints;
private int points;
private Color color;
Level(int hitpoints, int points, Color color){
this.hitpoints = hitpoints;
this.points = points;
this.color=color;
}
public int getPoints(){
return points;
}
public Color getColor(){
return color;
}
}
//rest of brick class goes under the enum
そして、BreakoutCourt で次のように使用します。
//Generates the bricks.
for(int i = 0; i < 8; ++i){
ArrayList<Brick> temp = new ArrayList<Brick>();
Level rowColor = null;
switch(i){
//There are two rows per type of brick.
case 0:
case 1:
rowColor = Level.EASY;
break;
case 2:
case 3:
rowColor = Level.HARD;
break;
case 4:
case 5:
rowColor = Level.LUNATIC;
break;
case 6:
case 7:
default:
rowColor = Level.MEDIUM;
break;
}
for(int j = 0; j < numBrick; j++){
Brick tempBrick = new Brick((j * Brick.BWIDTH), ((i+2) * Brick.BHEIGHT), rowColor);
temp.add(tempBrick);
}
私は何を間違っていますか?お手伝いありがとう!