Package battleTank

Examples of battleTank.Point


   */
  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


              setChanged();
            }
          }
          if (o instanceof SimpleShoot) {
            SimpleShoot ss = (SimpleShoot) o;
            e.shoot(new Point(ss.c, ss.r), ss.x, ss.y);

          }
        }

        catch (SocketException e) {
View Full Code Here

  public boolean connected = false;

  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

              setChanged();
            }
          }
          if (o instanceof SimpleShoot) {
            SimpleShoot ss = (SimpleShoot) o;
            e.shoot(new Point(ss.c, ss.r), ss.x, ss.y);
            notifyObservers();
            setChanged();
          }
        } catch (SocketException e) {
          System.out.println("Socket Exception, connection lost");
View Full Code Here

        // create a new shot, with position relative to location of
        // tank,
        // the speed in the x and y directions

        player.shoot(
            new Point(player.getLocation().row, player
                .getLocation().col),
            (int) (xdiff * (5 / length)),
            (int) (ydiff * (5 / length)));
       
        if(i==1)cm.sendObject(new SimpleShoot(player.getLocation().col, player
View Full Code Here

    if (arg1 instanceof String) {
      String s = (String)arg1;
      System.out.println(s);
    }
    if (arg1 instanceof Point) {
      Point p = (Point)arg1;
      Explosion et = new Explosion(p, model.getMap());
      model.addExplosion(et);
     
    }
  }
View Full Code Here

   
    //Creates a new explosion at the passed Point
   
    if (o instanceof Point) {
      Point p = (Point)o;
      notifyObservers(p);
      setChanged();
     
    }
   
   
    // Calls for the view to be repainted whenever a PlayerTank or EnemyTank is pushing a crate or TNT
   
    if (o instanceof String) {
      String s = (String) o;
      if (s.equals("moveCrate")) {
        notifyObservers();
        setChanged();
      }
     
      if (s.equals("moveTNT")) {
        notifyObservers();
        setChanged();
      }
      if (s.equals("Boom")) {
        System.out.println("?");
        notifyObservers();
        setChanged();
      }
    }
   
    /* Whenever a FireRing moves it is passed to this method which then determines whether or not
     it has collided with the player
    */
    if (o instanceof FireRing) {
      FireRing fr = (FireRing) o;
      for (int i = 0; i < tankList.size(); i++) {
        PlayerTank t = tankList.get(i);
        if (t.getRectangle().intersects(fr.getRectangle())) {
          notifyObservers(new Point(t.getLocation().row - 12, t.getLocation().col - 12));
          t.recieveDamage(1);
          setChanged();
          break;
        }
      }
      notifyObservers("Fire " + fr.getLocation().col + " " + fr.getLocation().row);
      setChanged();
    }
   
    // Adds the created PlayerProjectile to the map whenever the player's shoot method is called. If there is
    // already a PlayerProjectile on the map this will keep track of that projectile's location and will determine
    // whether or not it has collided with any objects.

    if (o instanceof PlayerProjectile) {
      PlayerProjectile p = (PlayerProjectile) o;

      if (!projectileList.contains(p)) {
        projectileList.add(p);
        p.addObserver(this);
       
      } else {
       
        // The xCoord will be set to -1 when the Projectile goes off the screen. This will make sure it is properly removed from the map.
       
        if (p.getRectangle().xCoord() <= 0) {
          projectileList.remove(p);
         
        }
       
        // The projectile will destroy any item it collides with
       
        for (Item i : itemList) {
         
          if (i instanceof BubbleShield) {
            BubbleShield c = (BubbleShield) i;
            if (c.getRectangle().intersects(p.getRectangle())) {
              p.collided();
              projectileList.remove(p);
              itemList.remove(c);
              notifyObservers(new Point(p.getLocation().row - 12, p.getLocation().col - 12));
              setChanged();
              break;
            }
          }
          if (i instanceof IceBlock) {
            IceBlock c = (IceBlock) i;
            if (c.getRectangle().intersects(p.getRectangle())) {
              p.collided();
              projectileList.remove(p);
              itemList.remove(c);
              notifyObservers(new Point(c.getLocation().row - 12, c.getLocation().col - 12));
              setChanged();
              break;
            }
          }
          if (i instanceof SpeedBoost) {
            SpeedBoost c = (SpeedBoost) i;
            if (c.getRectangle().intersects(p.getRectangle())) {
              p.collided();
              projectileList.remove(p);
              itemList.remove(c);
              notifyObservers(new Point(p.getLocation().row - 12, p.getLocation().col - 12));
              setChanged();
              break;
            }
          }
        }
       
        //Removes the EnemyTank if it is hit by the PlayerTank's projectile
       
        for (EnemyTank h : enemyList) {
          if (h.getRectangle().intersects(p.getRectangle())) {
            p.collided();
            projectileList.remove(p);
            h.recieveDamage(p.getDamage());
            notifyObservers(new Point(p.getLocation().row - 12, p.getLocation().col - 12));
            setChanged();
            break;
          }
        }
        for (Obstacle obs : obstacleList) {
         
          // Crate's are destroyed when a projectile collides with them
         
          if (obs instanceof Crate) {
            Crate c = (Crate) obs;
            if (c.getRectangle().intersects(p.getRectangle())) {
              p.collided();
              projectileList.remove(p);
              c.recieveDamage(p.getDamage());
              notifyObservers(new Point(p.getLocation().row - 12, p.getLocation().col - 12));
              setChanged();
              break;
            }
          }
         
          // TNT's are destroyed when a projectile collides with them, they also create a blast radius
          // that will cause any object somewhat near the exploded TNT to take damage
         
          if (obs instanceof TNT) {
            TNT c = (TNT) obs;
            if (c.getRectangle().intersects(p.getRectangle())) {
              p.collided();
              projectileList.remove(p);
              c.recieveDamage(p.getDamage());
              notifyObservers(new Point(p.getLocation().row - 12, p.getLocation().col - 12));
              setChanged();
              break;
            }
          }
         
          //ImmovableBlock's can not be destroyed. If a projectile collides with one, the projectile is removed.
         
          if (obs instanceof ImmovableBlock) {
            ImmovableBlock c = (ImmovableBlock) obs;
            if (c.getRectangle().intersects(p.getRectangle())) {
              p.collided();
              projectileList.remove(p);
              c.recieveDamage(p.getDamage());
              notifyObservers(new Point(p.getLocation().row - 12, p.getLocation().col - 12));
              setChanged();
              break;

            }
          }

          //FireRing's can not be destroyed. If a projectile collides with one, the projectile is removed.
         
          if (obs instanceof FireRing) {
            FireRing c = (FireRing) obs;
            if (c.getRectangle().intersects(p.getRectangle())) {
              p.collided();
              projectileList.remove(p);
              c.recieveDamage(p.getDamage());
              notifyObservers(new Point(p.getLocation().row - 12, p.getLocation().col - 12));
              setChanged();
              break;

            }
          }

        }

        notifyObservers();
        setChanged();
      }
    }
   
    // Adds the created EnemyProjectile to the map whenever the enemy's shoot method is called. If there is
    // already a EnemyProjectile on the map this will keep track of that projectile's location and will determine
    // whether or not it has collided with any objects.
   
    if (o instanceof EnemyProjectile) {
      EnemyProjectile p = (EnemyProjectile) o;

      if (!projectileList.contains(p)) {
        projectileList.add(p);
        p.addObserver(this);
        notifyObservers();
        setChanged();
      } else {
       
        // The xCoord will be set to -1 when the Projectile goes off the screen. This will make sure it is properly removed from the map.
       
        if (p.getRectangle().xCoord() <= 0) {
          projectileList.remove(p);
          notifyObservers();
          setChanged();
        }
       
        // The projectile will destroy any item it collides with
       
        for (Item i : itemList) {
          if (i instanceof BubbleShield) {
            BubbleShield c = (BubbleShield) i;
            if (c.getRectangle().intersects(p.getRectangle())) {
              p.collided();
              projectileList.remove(p);
              itemList.remove(c);
              notifyObservers(new Point(c.getLocation().row - 12, c.getLocation().col - 12));
              setChanged();
              break;
            }
          }
          if (i instanceof IceBlock) {
            IceBlock c = (IceBlock) i;
            if (c.getRectangle().intersects(p.getRectangle())) {
              p.collided();
              projectileList.remove(p);
              itemList.remove(c);
              notifyObservers(new Point(c.getLocation().row - 12, c.getLocation().col - 12));
              setChanged();
              break;
            }
          }
          if (i instanceof SpeedBoost) {
            SpeedBoost c = (SpeedBoost) i;
            if (c.getRectangle().intersects(p.getRectangle())) {
              p.collided();
              projectileList.remove(p);
              itemList.remove(c);
              notifyObservers(new Point(c.getLocation().row - 12, c.getLocation().col - 12));
              setChanged();
              break;
            }
          }
        }
       
        //Removes the PlayerTank if it is hit by the EnemyTank's projectile
       
        for (PlayerTank h : tankList) {
          if (h.getRectangle().intersects(p.getRectangle())) {
            p.collided();
            projectileList.remove(p);
            notifyObservers(new Point(h.getLocation().row - 12, h.getLocation().col - 12));
            setChanged();
            h.recieveDamage(p.getDamage());
            break;
          }
        }

        for (Obstacle obs : obstacleList) {
         
          // Crate's are destroyed when a projectile collides with them
         
          if (obs instanceof Crate) {
            Crate c = (Crate) obs;
            if (c.getRectangle().intersects(p.getRectangle())) {
              p.collided();
              projectileList.remove(p);
              notifyObservers(new Point(c.getLocation().row - 12, c.getLocation().col - 12));
              setChanged();
              c.recieveDamage(p.getDamage());
              break;
            }
          }
         
          // TNT's are destroyed when a projectile collides with them, they also create a blast radius
          // that will cause any object somewhat near the exploded TNT to take damage
         
          if (obs instanceof TNT) {
            TNT c = (TNT) obs;
            if (c.getRectangle().intersects(p.getRectangle())) {
              p.collided();
              projectileList.remove(p);
              notifyObservers(new Point(c.getLocation().row - 12, c.getLocation().col - 12));
              setChanged();
              c.recieveDamage(p.getDamage());
              break;
            }
          }
         
          // ImmovableBlock's can not be destroyed. If a projectile collides with one, the projectile is removed.
         
          if (obs instanceof ImmovableBlock) {
            ImmovableBlock c = (ImmovableBlock) obs;
            if (c.getRectangle().intersects(p.getRectangle())) {
              p.collided();
              projectileList.remove(p);
              c.recieveDamage(p.getDamage());
              notifyObservers(new Point(p.getLocation().row - 12, p.getLocation().col - 12));
              setChanged();
              break;

            }
          }
         
          //FireRing's can not be destroyed. If a projectile collides with one, the projectile is removed.
         
          if (obs instanceof FireRing) {
            FireRing c = (FireRing) obs;
            if (c.getRectangle().intersects(p.getRectangle())) {
              p.collided();
              projectileList.remove(p);
              c.recieveDamage(p.getDamage());
              notifyObservers(new Point(p.getLocation().row - 12, p.getLocation().col - 12));
              setChanged();
              break;

            }
          }

        }

        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 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.Point

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.