Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 22nd, 2010 | Syntax: None | Size: 2.28 KB | Hits: 26 | Expires: Never
Copy text to clipboard
  1. import draw.*;
  2. import colors.*;
  3. import geometry.*;
  4. import java.util.Random;
  5.  
  6. // the world of UFO's, AUPs, and Shots
  7. class UFOWorld {
  8.   UFO ufo;
  9.   AUP aup;
  10.   IShots shots;
  11. //  Color BACKG = new Blue();
  12.   int HEIGHT = 500;
  13.   int WIDTH = 200;
  14.  
  15.   UFOWorld(UFO ufo, AUP aup, IShots shots)
  16.   {
  17.     this.ufo = ufo;
  18.     this.aup = aup;
  19.     this.shots = shots;
  20.   }
  21. }
  22.  
  23. // an AUP: a rectangle whose upper left corner is located at (location, bottom)
  24. class AUP {
  25.   int location;
  26.   // Color aupColor = new Red();
  27.  
  28.   AUP(int location) {
  29.     this.location = location;
  30.   }
  31. }
  32.  
  33. // A UFO whose center is located at location
  34. class UFO {
  35.   Posn location;
  36.   // Color colorUFO = new Green();
  37.  
  38.   UFO(Posn location) {
  39.     this.location = location;
  40.   }
  41. }
  42.  
  43. // managing a number of shots
  44. interface IShots{}
  45.  
  46. // the empty list of shots
  47. class MTShots implements IShots{
  48.   MTShots(){}
  49. }
  50.  
  51. // a class with atleast one shot
  52. class ConsShots implements IShots {
  53.   Shot first;
  54.   IShots rest;
  55.  
  56.   ConsShots(Shot first, IShots rest)
  57.   {
  58.   this.first = first;
  59.   this.rest = rest;
  60. }}
  61.  
  62. // a shot in flight, whose upper left corner is located at location
  63. class Shot {
  64.   Posn location;
  65.   // Color shotColor = new Yellow();
  66.  
  67.   Shot(Posn location) {
  68.     this.location = location;
  69.   }
  70.   }
  71.  
  72. /*/ a Posn class
  73. class Posn {
  74.   int x;
  75.   int y;
  76.  
  77.   Posn(int x, int y){
  78.     this.x = x;
  79.     this.y = y;
  80.   }
  81. }*/
  82.  
  83. class Examples {
  84.   // an anti-UFO platform placed in the center:
  85.   AUP a = new AUP(100);
  86.  
  87.   // a IFP placed on the cemter near the top ff the world
  88.   UFO u = new UFO(new Posn(100,5));
  89.  
  90.   // a UFO placed in the center somewhat below u
  91.   UFO u2 = new UFO(new Posn(100, 8));
  92.  
  93.   // A shot, right after being fired from a
  94.   Shot s = new Shot(new Posn(110, 490));
  95.  
  96.   // another shot above s
  97.   Shot s2 = new Shot(new Posn(110, 485));
  98.  
  99.   // an empty list of shots
  100.   IShots le = new MTShots();
  101.  
  102.   // a list of one shot
  103.   IShots ls = new ConsShots(s, new MTShots());
  104.  
  105.   // a list of two shots, one above the other
  106.   IShots ls2 = new ConsShots(s2, new ConsShots(s, new MTShots()));
  107.  
  108.   // a complete world with an empty list of shots
  109.   UFOWorld w = new UFOWorld(u,a,le);
  110.  
  111.   // a complete world, with 2 shots
  112.   UFOWorld w2 = new UFOWorld(u,a,ls);
  113. }