Ejemplo n.º 1
0
  public void drawVictory(Graphics g) {
    g.setColor(new Color(0, 0, 0, 200));
    g.fillRect(195, 220, 410, 110);
    g.setColor(new Color(255, 255, 255, 200));
    g.fillRect(200, 225, 400, 100);
    g.setColor(new Color(0, 0, 0, 200));
    g.setFont(new Font("Bell MT", Font.BOLD, 20));
    FontMetrics metrics = g.getFontMetrics(new Font("Bell MT", Font.BOLD, 20));
    int hgt = metrics.getHeight();

    String initialMessage;
    String followupMessage;

    if (nextWindow) {
      initialMessage = "You have gotten stronger.";
      followupMessage = player.getName() + " is now level " + player.getLevel() + "!";
    } else {
      initialMessage = "You survived!";
      followupMessage = "You and your allies gain " + totalExperience + " experience!";
    }

    // Hgt = 26
    int adv = metrics.stringWidth(initialMessage);
    g.drawString(initialMessage, getWidth() / 2 - adv / 2, 234 + hgt);
    adv = metrics.stringWidth(followupMessage);
    g.drawString(followupMessage, getWidth() / 2 - adv / 2, 269 + hgt);
  }
Ejemplo n.º 2
0
  /**
   * Method notifyDead.
   *
   * @param killer Creature
   */
  void notifyDead(Creature killer) {
    if (!Config.ALLOW_DEATH_PENALTY_C5) {
      return;
    }

    if (_hasCharmOfLuck) {
      _hasCharmOfLuck = false;
      return;
    }

    if ((killer == null) || killer.isPlayable()) {
      return;
    }

    Player player = getPlayer();

    if ((player == null) || (player.getLevel() <= 9)) {
      return;
    }

    int karmaBonus = player.getKarma() / Config.ALT_DEATH_PENALTY_C5_KARMA_PENALTY;

    if (karmaBonus < 0) {
      karmaBonus = 0;
    }

    if (Rnd.chance(Config.ALT_DEATH_PENALTY_C5_CHANCE + karmaBonus)) {
      addLevel();
    }
  }
Ejemplo n.º 3
0
 /** Tests for describe. */
 @Test
 public void testDescribe() {
   final int hours = player.getAge() / 60;
   final int minutes = player.getAge() % 60;
   final String time = hours + " hours and " + minutes + " minutes";
   assertThat(
       player.describe(),
       is(
           "You see "
               + player.getTitle()
               + ".\n"
               + player.getTitle()
               + " is level "
               + player.getLevel()
               + " and has been playing "
               + time
               + "."));
 }
Ejemplo n.º 4
0
 /** Tests for describeOfPlayerWithGrumpyMessage. */
 @Test
 public void testDescribeOfPlayerWithGrumpyMessage() {
   final int hours = player.getAge() / 60;
   final int minutes = player.getAge() % 60;
   final String time = hours + " hours and " + minutes + " minutes";
   player.setGrumpyMessage("I am grumpy.");
   String description = player.describe();
   String expectedDescription =
       "You see "
           + player.getTitle()
           + ".\n"
           + player.getTitle()
           + " is level "
           + player.getLevel()
           + " and has been playing "
           + time
           + "."
           + "\nplayer is grumpy and has left a message: "
           + player.getGrumpyMessage();
   assertThat(description, is(expectedDescription));
 }
Ejemplo n.º 5
0
  public void spawnNearPlayers() {
    Monster monster = null;
    float prob, rand;
    int count;
    HashMap<String, Player> players = registry.getPlayerManager().getPlayers();
    Player player = null;
    Integer spawnCoolDown = null;
    for (String key : players.keySet()) {
      player = (Player) players.get(key);

      // check for spawning Melvin
      if (registry.currentTime >= nextBossOrcSpawn && nextBossOrcSpawn != 0) {
        // to spawn melvin, player must have 40 AP, be within a range on the map and be on the
        // surface
        if (player.getMapX() >= 2000
            && player.getMapX() <= 5000
            && player.getLevel() >= 10
            && player.getMapY() == this.findFloor(player.getMapX())) {
          spawnBossOrc(player);
        }
      }

      if (spawnCoolDowns.containsKey(key)) {
        spawnCoolDown = spawnCoolDowns.get(key);
      } else {
        spawnCoolDown = new Integer(0);
        spawnCoolDowns.put(key, spawnCoolDown);
      }
      spawnCoolDown--;
      if (spawnCoolDown < 0) {
        int x = player.getMapX();
        int y = player.getMapY();
        int groundLevel = registry.getBlockManager().getLevelByY(y);
        count = -groundLevel;
        try {
          for (String key2 : monsters.keySet()) {
            monster = (Monster) monsters.get(key2);
            if (monster.getCenterPoint().distance(player.getCenterPoint())
                < MonsterManager.mobSpawnRangeMax * 3 / 2) {
              if (monster.getTouchDamage() > 0
                  && !monster.getName().equals("BlueThorn")
                  && !monster.getName().equals("VineThorn")) {
                count++;
              }
            }
          }
        } catch (ConcurrentModificationException concEx) {
          // another thread was trying to modify monsters while iterating
          // we'll continue and the new item can be grabbed on the next update
        }
        if (count < 4) {
          for (MonsterType monsterType : MonsterType.values()) {
            if (count < 4) {
              rand = Rand.getFloat();
              prob = getShouldSpawn(monsterType, groundLevel);
              if (prob > 0.0f) {
                if ((prob - count * spawnRatioDiff) > 0.005f) {
                  prob += -count * spawnRatioDiff;
                } else {
                  prob = 0.005f;
                }
              }
              if (rand <= prob) {
                // System.out.println("spawn near player " + monsterType.name());
                spawn(monsterType.name(), "Roaming", x, y);
                count++;
              }
            }
          }
        } else {
          // EIError.debugMsg("too many to spawn");
          spawnCoolDown = 20;
        }
      }
    }
  }
  public static void main(String[] args) {
    int num1 = 0, num2 = 0;

    Scanner input = new Scanner(System.in);
    System.out.print("\nPlease enter your first name: ");
    String playerName = input.nextLine();
    player_1.setName(playerName);

    System.out.print(
        "\n\n************************************************"
            + "*************************************\n");
    System.out.printf("Welcome %s! The rules for the game are:\n", player_1.getName());
    System.out.printf(
        "The game consists of four rounds of addition problems"
            + " randomly generated. Each time the \nproblem is answered correctly"
            + " you will receive 5 points and the difficulty level\nwill increase. "
            + "If the problem is answered incorrectly you will lose 5 points and "
            + "the\ndifficulty level will be reduced.");

    for (int round = 1; round <= 4; round++) {
      // Make sure level does not go below 1.
      player_1.setLevel((player_1.getLevel() < 1) ? 1 : player_1.getLevel());

      switch (player_1.getLevel()) {
        case 1:
          num1 = randomNumber(0, 9);
          num2 = randomNumber(0, 9);
          roundResult(num1, num2, round);
          break;

        case 2:
          num1 = randomNumber(10, 99);
          num2 = randomNumber(10, 99);
          roundResult(num1, num2, round);
          break;

        case 3:
          num1 = randomNumber(100, 999);
          num2 = randomNumber(100, 999);
          roundResult(num1, num2, round);
          break;

        case 4:
          num1 = randomNumber(1000, 9999);
          num2 = randomNumber(1000, 9999);
          roundResult(num1, num2, round);
          break;
        default:
      } // End of switch.
    } // End of for loop.

    System.out.printf(
        "\n\n***************************************************"
            + "****************\n************************** Final Results ********"
            + "******************\n");
    System.out.printf(
        "%s your final score is %d points and you answered %4.1f"
            + "%% of\nthe questions correctly.",
        player_1.getName(), score, (double) numCorrect / (numCorrect + numIncorrect) * 100.0);

    input.close();
    inputAnswer.close();
  } // ************** End of MAIN method ****************************