示例#1
0
 public synchronized boolean moveClientBackward(Client client) {
   assert (client != null);
   Object o = clientMap.get(client);
   assert (o instanceof DirectedPoint);
   DirectedPoint dp = (DirectedPoint) o;
   return moveClient(client, dp.getDirection().invert());
 }
示例#2
0
 public synchronized Direction getClientOrientation(Client client) {
   assert (client != null);
   Object o = clientMap.get(client);
   assert (o instanceof DirectedPoint);
   DirectedPoint dp = (DirectedPoint) o;
   return dp.getDirection();
 }
示例#3
0
 /**
  * Internal helper called when a {@link Client} emits a turnRight action.
  *
  * @param client The {@link Client} to rotate.
  */
 private synchronized void rotateClientRight(Client client) {
   assert (client != null);
   Object o = clientMap.get(client);
   assert (o instanceof DirectedPoint);
   DirectedPoint dp = (DirectedPoint) o;
   clientMap.put(client, new DirectedPoint(dp, dp.getDirection().turnRight()));
   update();
 }
示例#4
0
  private synchronized Collection moveProjectile(Projectile prj) {
    Collection deadPrj = new LinkedList();
    assert (prj != null);

    Object o = projectileMap.get(prj);
    assert (o instanceof DirectedPoint);
    DirectedPoint dp = (DirectedPoint) o;
    Direction d = dp.getDirection();
    CellImpl cell = getCellImpl(dp);

    /* Check for a wall */
    if (cell.isWall(d)) {
      // If there is a wall, the projectile goes away.
      cell.setContents(null);
      deadPrj.add(prj);
      update();
      return deadPrj;
    }

    DirectedPoint newPoint = new DirectedPoint(dp.move(d), d);
    /* Is the point within the bounds of maze? */
    assert (checkBounds(newPoint));

    CellImpl newCell = getCellImpl(newPoint);
    Object contents = newCell.getContents();
    if (contents != null) {
      // If it is a Client, kill it outright
      if (contents instanceof Client) {
        System.out.println(
            "KILL ENEMY!!!!"
                + prj.getOwner().getName()
                + " kills "
                + ((Client) contents).getName());
        killClient(prj.getOwner(), (Client) contents);
        System.out.println("Set content to null");
        cell.setContents(null);
        deadPrj.add(prj);
        System.out.println("Add to deadPrj");
        update();
        System.out.println("moveProjectile() returns!!!");
        return deadPrj;

        /*killClient(prj.getOwner(), (Client)contents);
        cell.setContents(null);
        deadPrj.add(prj);
        update();
        return deadPrj;*/
      } else {
        // Bullets destroy each other
        System.out.println("BULLETS destroyED!!!!");
        assert (contents instanceof Projectile);
        newCell.setContents(null);
        cell.setContents(null);
        deadPrj.add(prj);
        deadPrj.add(contents);
        update();
        return deadPrj;

        /*assert(contents instanceof Projectile);
        newCell.setContents(null);
        cell.setContents(null);
        deadPrj.add(prj);
        deadPrj.add(contents);
        update();
        return deadPrj;*/
      }
    }

    /* Clear the old cell */
    cell.setContents(null);
    /* Write the new cell */
    projectileMap.put(prj, newPoint);
    newCell.setContents(prj);
    update();
    return deadPrj;
  }