//Draws a half moon, of the specified radius, on the specified location. //The moon will become visible on the specified frame. import java.awt.*; // use graphics // EXTRA EFFORT PROBLEM: draw the other half of the moon in the color of // the background. To do this , you need to pass 'delay' as another parameter // to the constructor and keep track of the current color of the background // The color of the half-moon may be passed as an argument to the constructor. //otherwise, its color is yellow public class Moon extends Sprite { int x; //(x,y) is the point of the moon's center int y; int radius; int appearTime; int currentFrame; //number of the current frame in the animation NightBackground bg; // add more instance variables if needed //constructors public Moon(int x, int y, int radius, int appearTime, NightBackground bg) { this.x = x; this.y = y; this.radius = radius; this.appearTime = appearTime; currentFrame = 0; this.bg = bg; } public void drawState(Graphics g) { // if the moon has not appeared yet, do nothing // otherwise draw the moon as a vertical half-circle at the position (x,y) // add your code here if (currentFrame < appearTime) return; //do nothing //otherwise, draw the first half of the moon in yellow g.setColor(Color.yellow); g.fillArc(x-radius, y-radius, 2*radius, 2*radius, 90,180); //and the other half of it in the background color, //so it will hide any stars behind it. g.setColor(bg.color); //this accesses the instance var "color" in the // "ColorBackground" class, which is protected g.fillArc(x-radius, y-radius, 2*radius, 2*radius, 270,180); } public void updateState() { // add your code here currentFrame = currentFrame+1; } public void resetState() { // add your code here currentFrame = 0; } // For debugging: public String className() { return "Moon"; } public String toString() { return className() + "[" + "x=" + x + "; y=" + y + "; radius=" + radius + "; appearTime=" + appearTime + "]"; } }