Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. import image.Circle;
  2. import image.Image;
  3. import image.Scene;
  4. import image.Square;
  5. import world.Posn;
  6.  
  7. // Represents a Grid Position
  8. abstract class AGrid extends Posn
  9. {
  10. int CELL_SIZE = 20;
  11. int CELL_WIDTH = 20;
  12. int CELL_HEIGHT = 20;
  13.  
  14. int WIDTH = this.CELL_WIDTH * this.CELL_SIZE;
  15. int HEIGHT = this.CELL_HEIGHT * this.CELL_SIZE;
  16.  
  17. Image segImage = new Circle(this.CELL_SIZE, "solid", "red");
  18. Image foodImage = new Square(this.CELL_SIZE, "solid", "green");
  19.  
  20. AGrid(int x, int y)
  21. {
  22. super(x,y);
  23. } // AGrid(int, int) ctor
  24.  
  25. /* Inventory:
  26. * Fields:
  27. * ... this.x ... -- int
  28. * ... this.y ... -- int
  29. *
  30. * Methods:
  31. * ... this.cell2Pixel() ... -- Posn
  32. * ... this.tock(String) ... -- AGrid abstract
  33. * ... this.drawAGrid(Scene) ... -- AGrid abstract
  34. */
  35.  
  36. // Calculate the pixel-coords from cell-coord
  37. Posn cell2Pixel()
  38. {
  39. /*
  40. * Design:
  41. *
  42. */
  43. return new Posn(this.CELL_SIZE * this.x + this.CELL_SIZE / 2,
  44. this.CELL_SIZE * this.y + this.CELL_SIZE / 2);
  45. } // cell2Pixel()
  46.  
  47. // return AGrid tocked according to the direction
  48. public abstract AGrid tock(String dir);
  49.  
  50. // return AGrid drawn onto the scene according to its x & y
  51. public abstract Scene drawAGrid(Scene scene);
  52.  
  53. // return AGrid onKeyed according to the key event
  54. public abstract AGrid onKey(String ke);
  55.  
  56. // is this AGrid off the screen?
  57. public abstract boolean offScreen();
  58.  
  59. // is this AGrid hitting the rest?
  60. public abstract boolean hitSelf(ILoS rest);
  61.  
  62. } // AGrid abstract class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement