- import draw.*;
- import colors.*;
- import geometry.*;
- import java.util.Random;
- // the world of UFO's, AUPs, and Shots
- class UFOWorld {
- UFO ufo;
- AUP aup;
- IShots shots;
- // Color BACKG = new Blue();
- int HEIGHT = 500;
- int WIDTH = 200;
- UFOWorld(UFO ufo, AUP aup, IShots shots)
- {
- this.ufo = ufo;
- this.aup = aup;
- this.shots = shots;
- }
- }
- // an AUP: a rectangle whose upper left corner is located at (location, bottom)
- class AUP {
- int location;
- // Color aupColor = new Red();
- AUP(int location) {
- this.location = location;
- }
- }
- // A UFO whose center is located at location
- class UFO {
- Posn location;
- // Color colorUFO = new Green();
- UFO(Posn location) {
- this.location = location;
- }
- }
- // managing a number of shots
- interface IShots{}
- // the empty list of shots
- class MTShots implements IShots{
- MTShots(){}
- }
- // a class with atleast one shot
- class ConsShots implements IShots {
- Shot first;
- IShots rest;
- ConsShots(Shot first, IShots rest)
- {
- this.first = first;
- this.rest = rest;
- }}
- // a shot in flight, whose upper left corner is located at location
- class Shot {
- Posn location;
- // Color shotColor = new Yellow();
- Shot(Posn location) {
- this.location = location;
- }
- }
- /*/ a Posn class
- class Posn {
- int x;
- int y;
- Posn(int x, int y){
- this.x = x;
- this.y = y;
- }
- }*/
- class Examples {
- // an anti-UFO platform placed in the center:
- AUP a = new AUP(100);
- // a IFP placed on the cemter near the top ff the world
- UFO u = new UFO(new Posn(100,5));
- // a UFO placed in the center somewhat below u
- UFO u2 = new UFO(new Posn(100, 8));
- // A shot, right after being fired from a
- Shot s = new Shot(new Posn(110, 490));
- // another shot above s
- Shot s2 = new Shot(new Posn(110, 485));
- // an empty list of shots
- IShots le = new MTShots();
- // a list of one shot
- IShots ls = new ConsShots(s, new MTShots());
- // a list of two shots, one above the other
- IShots ls2 = new ConsShots(s2, new ConsShots(s, new MTShots()));
- // a complete world with an empty list of shots
- UFOWorld w = new UFOWorld(u,a,le);
- // a complete world, with 2 shots
- UFOWorld w2 = new UFOWorld(u,a,ls);
- }
