TargetSeeker

TargetSeeker - /* * File: TargetSeeker.java * -* This...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * File: TargetSeeker.java * ----------------------- * This program simulates a seeker moving toward a target */ import acm.graphics.*; import acm.program.*; import java.awt.*; import java.awt.event.*; public class TargetSeeker extends GraphicsProgram { public void run() { initTarget(); initSeeker(); addMouseListeners(); // Always keep seeking the target while (true) { seek(); } } // Target is filled red square that starts in center // of screen private void initTarget() { targetSquare = new GRect(TARGET_SIZE, TARGET_SIZE); targetSquare.setColor(Color.RED); targetSquare.setFilled(true); targetX = getWidth() / 2; targetY = getHeight() / 2; add(targetSquare, targetX - TARGET_SIZE/2, targetY - TARGET_SIZE/2); } // Seeker is unfilled black square that starts at origin private void initSeeker() { seeker = new GRect(SEEKER_SIZE, SEEKER_SIZE); add(seeker, 0, 0); } // Determine direction for seekerPos to move to get // closer to targetPos private int moveAmount(double seekerPos, double targetPos) {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

TargetSeeker - /* * File: TargetSeeker.java * -* This...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online