示例#1
0
  public Optional<Shot> findPotentialShotMatch(List<Shot> actualShots, Shot testedShot) {
    for (Shot shot : actualShots) {
      if (Math.abs(shot.getX() - testedShot.getX()) <= ALLOWED_COORD_VARIANCE
          && Math.abs(shot.getY() - testedShot.getY()) <= ALLOWED_COORD_VARIANCE) {

        return Optional.of(shot);
      }
    }

    return Optional.empty();
  }
示例#2
0
  public void Shoot(Point Position, Point Speed, int Faction, Time Life) {
    ArrayList AnimationList = new ArrayList();
    Animation a = new Animation();
    Shot sh =
        new Shot(
            new Point(Position), new Point(32, 32), Util.m_imGravImage, 1, m_iOwner, false, false);
    sh.AddImage(Util.m_imGravImageNV);
    sh.m_iDamage = m_iBaseDamage + m_iPowerLevel;
    if (Life != null) {
      sh.m_tLife = new Time(Life);
      sh.m_tLife.AddMilliseconds(m_iPowerLevel * 20);
    }
    AnimationList = new ArrayList();
    a = new Animation("IDLE", 1, 8, true, 34);
    AnimationList.add(a);

    sh.SetAnimations(AnimationList);
    sh.PlayAnimation("IDLE");

    sh.m_pSpeed.x = Speed.x;
    sh.m_pSpeed.y = Speed.y;

    sh.m_iFaction = Faction;
    sh.SetImage(Util.m_iVision);
    Util.m_alSprite.add(sh);

    m_tLastShotTime = new Time(Util.m_tTime);
  }
示例#3
0
  private void Shot() {

    int index = playerAmmunition.indexOf(playerAmmo);

    if (Greenfoot.isKeyDown("space") && shotInterval > playerAmmo.interval && ammo[index] > 0) {

      int f = getRotation();
      Shot p = Shot.create(playerAmmo, Inimigo.class);
      addObjectAtOffset(p, getX(), getY(), 70, f);
      p.setRotation(f);
      // !--------------!\\
      shotInterval = 0;
      ammo[index]--;
      ammoUI.addPoints(-1);
    }

    shotInterval++;
  }
示例#4
0
  @Override
  public void paint(Graphics graphics) {
    super.paint(graphics);

    Graphics2D g = (Graphics2D) graphics;

    if (shot != null) {
      for (Zone zone : shot.getZones().getZonesList()) {
        if (!"default-zone".equalsIgnoreCase(zone.getId())) {
          try {
            Polygon p = zone.getShape().getPolygon();

            if (zone.getId() == null) g.setColor(Color.BLUE);
            else if (zone.getId().equalsIgnoreCase("stumps")) g.setColor(Color.GREEN);
            else g.setColor(Color.RED);

            g.fillPolygon(p);
            g.setColor(g.getColor().darker());
            g.drawPolygon(p);
          } catch (Exception ex) {
            //					ex.printStackTrace();
          }
        }
      }
    }

    Stroke s = g.getStroke();
    g.setColor(Color.ORANGE);
    g.setStroke(new BasicStroke(5));
    g.drawRect(150, 250, 100, 150);
    g.setStroke(s);

    if (ballLoc != null) {
      g.setColor(Color.BLACK);
      g.fillOval((int) ballLoc.getX() - 5, (int) ballLoc.getY() - 5, 10, 10);
    }
  }
示例#5
0
  public void checkShots(
      ErrorCollector collector,
      final List<Shot> actualShots,
      List<Shot> requiredShots,
      List<Shot> optionalShots,
      boolean isColorWarning) {

    List<Shot> mutableActualShots = new ArrayList<Shot>(actualShots);

    for (Shot shot : requiredShots) {
      Optional<Shot> potentialShotMatch = findPotentialShotMatch(mutableActualShots, shot);

      collector.checkThat(
          String.format(
              "Shot (%.2f, %.2f, %s) not found",
              shot.getX(), shot.getY(), shot.getColor().toString()),
          potentialShotMatch.isPresent(),
          equalTo(true));

      if (potentialShotMatch.isPresent()) {
        if (isColorWarning && !potentialShotMatch.get().getColor().equals(shot.getColor())) {
          System.err.println(
              String.format(
                  "Shot (%.2f, %.2f, %s) detected with wrong color",
                  shot.getX(), shot.getY(), shot.getColor().toString()));
        } else {
          collector.checkThat(
              String.format(
                  "Shot (%.2f, %.2f, %s) has wrong color",
                  shot.getX(), shot.getY(), shot.getColor().toString()),
              potentialShotMatch.get().getColor(),
              equalTo(shot.getColor()));
        }

        mutableActualShots.remove(potentialShotMatch.get());
      }
    }

    for (Shot shot : optionalShots) {
      Optional<Shot> potentialShotMatch = findPotentialShotMatch(mutableActualShots, shot);

      if (potentialShotMatch.isPresent()) {
        if (isColorWarning && !potentialShotMatch.get().getColor().equals(shot.getColor())) {
          System.err.println(
              String.format(
                  "Optional shot (%.2f, %.2f, %s) detected with wrong color",
                  shot.getX(), shot.getY(), shot.getColor().toString()));
        } else {
          collector.checkThat(
              String.format(
                  "Optional shot (%.2f, %.2f, %s) has wrong color",
                  shot.getX(), shot.getY(), shot.getColor().toString()),
              potentialShotMatch.get().getColor(),
              equalTo(shot.getColor()));
        }

        mutableActualShots.remove(potentialShotMatch.get());
      } else {
        System.err.println(
            String.format(
                "Optional shot (%.2f, %.2f, %s) not found",
                shot.getX(), shot.getY(), shot.getColor().toString()));
      }
    }

    // If you are getting this failure you're either detecting noise that
    // wasn't detected before
    // or you found a shot that was previously missed and not accounted for,
    // thus you should
    // add it to the required shot list for the respective test.
    StringBuilder reason = new StringBuilder();

    if (mutableActualShots.size() == 1) {
      reason.append(
          String.format(
              "There was %d shot that was detected that isn't account for: ",
              mutableActualShots.size()));
    } else if (mutableActualShots.size() > 1) {
      reason.append(
          String.format(
              "There are %d shots that were detected that aren't account for: ",
              mutableActualShots.size()));
    }

    if (!mutableActualShots.isEmpty()) {
      Iterator<Shot> it = mutableActualShots.iterator();

      while (it.hasNext()) {
        Shot s = it.next();
        reason.append(
            String.format("(%.2f, %.2f, %s)", s.getX(), s.getY(), s.getColor().toString()));
        if (it.hasNext()) reason.append(", ");
      }
    }

    collector.checkThat(reason.toString(), mutableActualShots.isEmpty(), equalTo(true));
  }
示例#6
0
 private void setShot(Shot shot) {
   lblTitle.setText(shot.getName());
   pnlZone.setShot(shot);
 }
示例#7
0
  public void ShootMissile(Point Position, Point Speed, int Faction, Time Life) {
    Shot sh;
    ArrayList AnimationList = new ArrayList();
    Animation a = new Animation();
    if (m_iPowerLevel2 > 0) {
      sh =
          new Shot(
              new Point(Position),
              new Point(32, 32),
              Util.m_imMissileImage,
              1,
              m_iOwner,
              false,
              false);
      sh.AddImage(Util.m_imMissileImageNV);
      sh.m_iDamage = m_iMissileBaseDamage + m_iPowerLevel2;
      sh.m_tLife = null;
      AnimationList = new ArrayList();
      a = new Animation("IDLE", 1, 3, true, 6);
      AnimationList.add(a);

      sh.SetAnimations(AnimationList);
      sh.PlayAnimation("IDLE");

      sh.m_pSpeed.x = -5;
      sh.m_pSpeed.y = 0;

      sh.m_iFaction = Faction;
      sh.SetImage(Util.m_iVision);
      Util.m_alSprite.add(sh);
      // -------------------------------
      sh =
          new Shot(
              new Point(Position),
              new Point(32, 32),
              Util.m_imMissileImage,
              1,
              m_iOwner,
              false,
              false);
      sh.AddImage(Util.m_imMissileImageNV);
      sh.m_iDamage = m_iMissileBaseDamage + m_iPowerLevel2;
      sh.m_tLife = null;
      AnimationList = new ArrayList();
      a = new Animation("IDLE", 1, 3, true, 6);
      AnimationList.add(a);

      sh.SetAnimations(AnimationList);
      sh.PlayAnimation("IDLE");

      sh.m_pSpeed.x = 5;
      sh.m_pSpeed.y = 0;

      sh.m_iFaction = Faction;
      sh.SetImage(Util.m_iVision);
      Util.m_alSprite.add(sh);
    }
    m_tMissileLastShotTime = new Time(Util.m_tTime);
  }
示例#8
0
  @Override
  public void run() {
    running = true;
    messages.write("Defend your home planet!", 500);
    messages.write("Press O and D to set research focus.", 600);
    while (true) {
      if (!running) {
        setChanged();
        notifyObservers();
        try {
          Thread.sleep(DELAY);
        } catch (InterruptedException e) {
          System.out.println("Interrupted.");
          return;
        }
        continue;
      }
      synchronized (this) {
        research.step();

        /* Shoot the weapon. */
        if (firing) {
          long now = System.currentTimeMillis();
          long diff = now - lastFire;
          if (diff >= weapon.getSpeed()) {
            shots.add(weapon.fire(fireX, fireY));
            lastFire = now;
          }
        }

        /* Spawn meteoroids. */
        danger += difficulty;
        double spawn = danger;
        while (spawn > 0) {
          if (RNG.nextFloat() < danger) {
            double d = SIDE / 2d * Math.sqrt(2);
            double a = RNG.nextDouble() * Math.PI * 2;
            double x = Math.cos(a) * d;
            double y = Math.sin(a) * d;
            meteoroids.add(new Meteoroid(x, y));
          }
          spawn -= 1d;
        }

        /* Step debris forward. */
        Set<Debris> old = new HashSet<Debris>();
        for (Debris d : debris) {
          d.step();
          if (d.getTTL() <= 0f) {
            old.add(d);
          }
        }
        debris.removeAll(old);

        /* Step meteoroids forward. */
        Set<Meteoroid> dead = new HashSet<Meteoroid>();
        for (Meteoroid m : meteoroids) {
          if (m.step(home)) {
            dead.add(m);
            home.absorb(m);
            m.setAlive(false);
          }
        }

        /* Step weapon shots forward. */
        Set<Shot> spent = new HashSet<Shot>();
        for (Shot s : shots) {
          Meteoroid m = s.step(this);
          if (m != null && !dead.contains(m)) {
            dead.add(m);
            m.setAlive(false);
            s.setAlive(false);
            debris.addAll(m.breakup());
            score += m.getSize();
          } else if (s.getDistance() > SIDE) {
            spent.add(s);
          }
        }
        shots.removeAll(spent);
        meteoroids.removeAll(dead);

        /* Manage incoming and outgoing objects. */
        while (outgoing.peek() != null) {
          SpaceObject o = outgoing.poll();
          if (o instanceof Shot) {
            shots.remove((Shot) o);
          } else if (o instanceof Meteoroid) {
            meteoroids.remove((Meteoroid) o);
          } else if (o instanceof Debris) {
            debris.remove((Debris) o);
          }
        }
        while (incoming.peek() != null) {
          SpaceObject o = incoming.poll();
          if (o instanceof Shot) {
            shots.add((Shot) o);
          } else if (o instanceof Meteoroid) {
            meteoroids.add((Meteoroid) o);
          } else if (o instanceof Debris) {
            debris.add((Debris) o);
          }
        }

        /* Check game over status. */
        if (home.getHealth() <= 0) {
          System.out.println("Game over");
          running = false;
          meteoroids.clear();
          shots.clear();
          debris.clear();
        }
      }
      setChanged();
      notifyObservers();
      try {
        Thread.sleep(DELAY);
      } catch (InterruptedException e) {
        System.out.println("Interrupted.");
        return;
      }
    }
  }