@Test public void shouldKillAliveCellWhenKillIsCalled() { Cell cell = new Cell(true); cell.kill(); assertEquals(new Cell(false).format(), cell.format()); }
@Test public void shouldRemainDeadWhenKillIsCalledOnDeadCell() { Cell cell = new Cell(false); cell.kill(); assertEquals(new Cell(false).format(), cell.format()); }
protected void makeMove() { MoveOptions options = Actor.world.getMoveOptions(cell); boolean moved = false; while (!moved) { Move move = move(options); if (move == null) return; Cell lock1, lock2; Move.Direction direction = move.getMove(); Cell center = options.getOption(Move.Direction.CENTER), newCell = options.getOption(direction); switch (direction) { case DOWN: lock1 = center; lock2 = newCell; break; case CENTER: lock1 = center; lock2 = center; newCell = center; default: lock1 = newCell; lock2 = center; } synchronized (lock1) { synchronized (lock2) { if (alive) { // if the new location already has an object of the same class as us find another set of // moves. if (newCell != center && newCell.hasClass(this.getClass())) { continue; } moved = true; // kill to actor on the cell you are moving to // this can be "this", as in a flower has reached the end of its life Class<?> toKill = move.getClassToConsume(); if (toKill != null) newCell.kill(toKill); if (newCell != center) { center.remove(this.getClass()); newCell.add(this); } cell = newCell; if (this instanceof HasLife) { Class<?> kill = ((HasLife) this).getClassToKill(cell); if (kill != null) { cell.kill(kill); } } Actor toCreate = move.getActorToCreate(); if (toCreate != null) { center.add(toCreate); world.startActor(toCreate); } world.redrawCell(newCell); world.redrawCell(center); } else { moved = true; } } } } }
public static Cell getDeadCell() { Cell cell = new Cell(); cell.kill(); return cell; }