Playin' in the Maze

Submitted by Bill St. Clair on Sat, 25 Jan 2003 13:00:00 GMT
My Maze applet is ready for single-player play. It now works with Microsoft's Java, at least with the one on my Windows machine. It works in Mac OSX as well, but the refresh is slow, so the animation doesn't look very good there. The applet is up to a whopping 33K. More on the applet page. Enjoy!

I stayed up very late last night and worked on it most of the day today. I have to mop floors and get some sleep, so no blogging today.

I'm proud of the architecture of this game. I'll write it up sometime, but for now, here's the code that determines the behavior of the missiles:
public class MissileBehavior extends Robot {

protected Physob owner;

/** * A missile defaults to a delay of zero. Bloody fast. */ public MissileBehavior(Physob owner) { this(owner, 0); }

/** * Make a missile that moves every "delay" clock ticks. */ public MissileBehavior(Physob owner, int delay) { super(delay); this.owner = owner; }

public Physob getOwner() { return owner; }

public Action doSomething(Physob ob, MazeModel maze, int x, int y, int dir) { if (maze.isCellShared(ob)) return explode(ob, maze, x, y); else if (maze.forwardWallP(x, y, dir)) return DIE; else { x += maze.deltaX(dir); y += maze.deltaY(dir); if (maze.isCellOccupied(x, y)) { return explode(ob, maze, x, y); } else return FORWARD; } }

protected Action explode(Physob ob, MazeModel maze, int x, int y) { Physob[] obs = maze.getOccupants(x, y); for (int i=0; i<obs.length; i++) { Physob o = obs[i]; if ((o != ob) && (o != owner)) o.kill(owner); } return DIE; } }

Add comment Edit post Add post