Package battleTank

Examples of battleTank.EnemyTank


  public ClientModel(ClientView cv, MasterView m, Object o) {
    ip = "127.0.0.1";
    this.m = m;

    p = new PlayerTank(new Point(-100, -100), new Level1());
    e = new EnemyTank(new Point(-100, -100), new Level1());
    if (o instanceof String) {
      ip = (String) o;
    }
    try {
      System.out.println("Trying to connect to remote host on " + ip);
View Full Code Here


  public HostModel(HostView hv, MasterView m) {
    this.hv = hv;
    this.m = m;
    p = new PlayerTank(new Point(-100, -100), new Level1());
    e = new EnemyTank(new Point(-100, -100), new Level1());
    try {
      host = new ServerSocket(4000);
      client = host.accept();
      out = new ObjectOutputStream(client.getOutputStream());
      in = new ObjectInputStream(client.getInputStream());
View Full Code Here

    }
  }

  public void setEnemyStart(Point p) {

    enemy = new EnemyTank(p, map, 1);
    enemy.addObserver(this);
    map.enemyList.add(enemy);

  }
View Full Code Here

   
    // Whenever the EnemyTank moves this will check to see if it has collided with anything. Depeding
    // on the object it has collided with the proper action will occur.
   
    if (o instanceof EnemyTank) {
      EnemyTank p = (EnemyTank) o;
      TankRectangle rect = p.getRectangle();
     
      // When the EnemyTank collides with an item it will activate the item's effect on that EnemyTank
     
      for (Item i : itemList) {
        if (i instanceof BubbleShield) {
          BubbleShield c = (BubbleShield) i;
          if (c.getRectangle().intersects(p.getRectangle())) {
            // Can not have more than one BubbleShield active at a time
            if (p.getHealth() == 1) {
              c.activateEffect(p);
            }
            itemList.remove(c);
            notifyObservers();
            setChanged();
            break;
          }
        }
        if (i instanceof SpeedBoost) {
          SpeedBoost c = (SpeedBoost) i;
          if (c.getRectangle().intersects(p.getRectangle())) {
            c.activateEffect(p);
            itemList.remove(c);
            notifyObservers();
            setChanged();
            break;
          }
        }
        if (i instanceof IceBlock) {
          IceBlock c = (IceBlock) i;
          if (c.getRectangle().intersects(p.getRectangle())) {
            c.activateEffect(p);
            itemList.remove(c);
            notifyObservers();
            setChanged();
            break;
          }
        }
      }
      for (Obstacle obs : obstacleList) {
        // This tank will push the crate if the crate is movable
        if (obs instanceof Crate) {
          Crate c = (Crate) obs;
          if (rect.intersects(c.getRectangle())) {
            c.move(tankList.getFirst().getDirection());
          }
        }
        // This tank will push the TNT if the TNT is movable
        if (obs instanceof TNT) {
          TNT c = (TNT) obs;
          if (rect.intersects(c.getRectangle())) {
            c.move(tankList.getFirst().getDirection());
          }
        }
        // FireRing's can not kill the AI for difficulty purposes
        if (obs instanceof FireRing) {
          FireRing c = (FireRing) obs;
          if (rect.intersects(c.getRectangle())) {
            p.recieveDamage(1);
            notifyObservers();
            setChanged();
           
          }
        }
        // SpikePit's can not kill the AI either for difficulty purposes
        if (obs instanceof SpikePit) {
          SpikePit c = (SpikePit) obs;
          if (rect.intersects(c.getRectangle())) {
            p.recieveDamage(1);
            notifyObservers();
            setChanged();
          }
        }
      }
      notifyObservers();
      setChanged();
    }
   
    // Whenever the EnemyTank moves this will check to see if it has collided with anything. Depeding
    // on the object it has collided with the proper action will occur.
   
    if (o instanceof PlayerTank) {
      PlayerTank p = (PlayerTank) o;
      TankRectangle rect = p.getRectangle();
      for (Item i : itemList) {
        // Only one BubbleShield can be active at a time
        if (i instanceof BubbleShield) {
          BubbleShield c = (BubbleShield) i;
          if (c.getRectangle().intersects(p.getRectangle())) {
            if (p.getHealth() == 1) {
              c.activateEffect(p);
            }
            itemList.remove(c);
            notifyObservers();
            setChanged();
            break;
          }
        }
        if (i instanceof SpeedBoost) {
          SpeedBoost c = (SpeedBoost) i;
          if (c.getRectangle().intersects(p.getRectangle())) {
            if(!p.isActiveBoost()) {
            c.activateEffect(p);
            }
            itemList.remove(c);
            notifyObservers();
            setChanged();
            break;
          }
        }
        if (i instanceof IceBlock) {
          IceBlock c = (IceBlock) i;
          if (c.getRectangle().intersects(p.getRectangle())) {
            c.activateEffect(p);
            itemList.remove(c);
            notifyObservers();
            setChanged();
            break;
          }
        }
      }
      for (Obstacle obs : obstacleList) {
        // The PlayerTank will push the crate if it is movable
        if (obs instanceof Crate) {
          Crate c = (Crate) obs;
          if (rect.intersects(c.getRectangle())) {
            c.move(tankList.getFirst().getDirection());
          }
        }
        // The PlayerTank will push the TNT if it is movable
        if (obs instanceof TNT) {
          TNT c = (TNT) obs;
          if (rect.intersects(c.getRectangle())) {
            c.move(tankList.getFirst().getDirection());
          }
        }
        // If the PlayerTank collides with a FireRing it will die
        if (obs instanceof FireRing) {
          FireRing c = (FireRing) obs;
          if (rect.intersects(c.getRectangle())) {
            notifyObservers(new Point(p.getLocation().row - 12, p.getLocation().col - 12));
            p.recieveDamage(1);
          }
        }
        // If the PlayerTank collides with a SpikePit it will die
        if (obs instanceof SpikePit) {
          SpikePit c = (SpikePit) obs;
          if (rect.intersects(c.getRectangle())) {
            notifyObservers(new Point(p.getLocation().row - 12, p.getLocation().col - 12));
            p.recieveDamage(1);
          }
        }
      }
       
      notifyObservers();
View Full Code Here

TOP

Related Classes of battleTank.EnemyTank

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.