我正在用Java编写游戏Breakout。一开始我的背景是灰色的,但是当我赢时我希望它变成绿色。但是,我无法实现这一目标。有人可以帮我吗?

这里声明了颜色;

// Those are the basic statements and properties of the game and prepares the game to start
    int numberlost =0;
    Graphics gContext;
    Image buffer;
    Thread thread;
    boolean leftArrow = false;
    boolean rightArrow = false;
    boolean ballready = true;
    boolean extraball=false;
    Ball ball;
    Field brick;
    Paddle paddle;

    public static final Color
    PaddleColor=Color.black,
    ObstacleColor=Color.red,
    BallColor=Color.red;
    public static Color FieldColor = new Color(0xcccccc); // background is hexidemal color grey


这是我的win()方法:

// This method is called when you win
        public void win() {
            ball=null;
            paddle=null;
            // the background is set to green
            FieldColor= Color.green;
        }

最佳答案

public void win() {
        ball=null;
        paddle=null;
        // the background is set to green
        FieldColor= Color.green;
}


此方法只是将Color.green颜色分配给FieldColor。相反,您应该将其设置为JPanel或用作背景颜色的任何容器。

09-25 19:54