Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import image.Circle;
- import image.Image;
- import image.Scene;
- import image.Square;
- import world.Posn;
- // Represents a Grid Position
- abstract class AGrid extends Posn
- {
- int CELL_SIZE = 20;
- int CELL_WIDTH = 20;
- int CELL_HEIGHT = 20;
- int WIDTH = this.CELL_WIDTH * this.CELL_SIZE;
- int HEIGHT = this.CELL_HEIGHT * this.CELL_SIZE;
- Image segImage = new Circle(this.CELL_SIZE, "solid", "red");
- Image foodImage = new Square(this.CELL_SIZE, "solid", "green");
- AGrid(int x, int y)
- {
- super(x,y);
- } // AGrid(int, int) ctor
- /* Inventory:
- * Fields:
- * ... this.x ... -- int
- * ... this.y ... -- int
- *
- * Methods:
- * ... this.cell2Pixel() ... -- Posn
- * ... this.tock(String) ... -- AGrid abstract
- * ... this.drawAGrid(Scene) ... -- AGrid abstract
- */
- // Calculate the pixel-coords from cell-coord
- Posn cell2Pixel()
- {
- /*
- * Design:
- *
- */
- return new Posn(this.CELL_SIZE * this.x + this.CELL_SIZE / 2,
- this.CELL_SIZE * this.y + this.CELL_SIZE / 2);
- } // cell2Pixel()
- // return AGrid tocked according to the direction
- public abstract AGrid tock(String dir);
- // return AGrid drawn onto the scene according to its x & y
- public abstract Scene drawAGrid(Scene scene);
- // return AGrid onKeyed according to the key event
- public abstract AGrid onKey(String ke);
- // is this AGrid off the screen?
- public abstract boolean offScreen();
- // is this AGrid hitting the rest?
- public abstract boolean hitSelf(ILoS rest);
- } // AGrid abstract class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement