import uwcse.graphics.*; // access the graphics utilities in the uw library import java.awt.Color; // access the Color class /** *

* Create a spider in a graphics window *

* * @author your name here */ public class Spider { // Your instance fields go here private int x, y; private double scale; private GWindow window; // Shape making up the spider private Oval body; // Vertical displacement of the spider private int dy = 15; // initially the spider moves down private boolean isMovingUp = false; /** * Creates a spider centered at location (x,y) in the GWindow window. The * size of the spider is the default size times scale. */ public Spider(int x, int y, double scale, GWindow window) { this.x = x; this.y = y; this.scale = scale; this.window = window; draw(); } /** * Draws in the graphics window a spider at location (x,y) with size = * default size * scale */ private void draw() { int r = (int) (50 * scale); body = new Oval(x - r, y - r, 2 * r, 2 * r, Color.WHITE, true); window.add(body); } /** * Moves the spider up and down */ public void move() { if (isMovingUp == true) { body.moveBy(0, -dy); y -= dy; } else { body.moveBy(0, dy); y += dy; } // is the spider at the bottom of the window? if (y > window.getWindowHeight()) { // go up isMovingUp = true; } // is the spider at the top of the window? if (y < 0) { // go down isMovingUp = false; } } }