/**
   * Test fight stage.
   *
   * <p>Use debugStat on units to mess with fights, is also useful for testing animations.
   * Intentionally crashes at the end for lack of session info, so don't worry about it.
   *
   * <p>range can be set by messing with map.addUnit(), and you can change all the other
   * unit-related things to test them out. I can see us using this to use this bit for speed testing
   * in the future, if I ever make a gui or something for it.
   *
   * <p>TODO: gui for speed balancing
   */
  public void testFightStage() {
    Player p1 = localPlayer;
    testSession =
        new Session(new Seize(), "test", 8, new java.util.HashSet<>(), new net.fe.pick.Draft());
    Player p2 = new Player("p2", (byte) 1);
    p2.getParty().setColor(Party.TEAM_RED);
    p1.getParty().setColor(Party.TEAM_BLUE);
    p2.setTeam(2);
    p1.setTeam(1);

    testSession.addPlayer(p1);
    testSession.addPlayer(p2);

    final ClientOverworldStage map = new ClientOverworldStage(testSession);
    Unit u1 = UnitFactory.getUnit("Eirika");
    u1.getInventory().add(WeaponFactory.getWeapon("Silver Sword"));
    u1.equip(0);
    map.addUnit(u1, 0, 0);
    u1.setLevel(20);
    u1.loadMapSprites();
    p1.getParty().addUnit(u1);

    Unit u2 = UnitFactory.getUnit("Dart");
    u2.getInventory().add(WeaponFactory.getWeapon("Tomahawk"));
    map.addUnit(u2, 1, 0);
    u2.equip(0);
    u2.setLevel(1);
    u2.loadMapSprites();
    p2.getParty().addUnit(u2);

    map.processAddStack();
    int u2Uses = u2.getWeapon().getMaxUses();

    // u1.debugStat("Skl");
    // u1.debugStat("Str");

    // ^------- put all pre-calc stuff here

    CombatCalculator calc =
        new CombatCalculator(
            new UnitIdentifier(u1), new UnitIdentifier(u2), FEMultiplayer::getUnit);
    System.out.println(calc.getAttackQueue());

    u2.getWeapon().setUsesDEBUGGING(u2Uses);
    u1.fillHp();
    u2.fillHp();

    setCurrentStage(
        new FightStage(
            new UnitIdentifier(u1),
            new UnitIdentifier(u2),
            calc.getAttackQueue(),
            map,
            new EmptyRunnable()));
  }
  /** Test overworld stage. */
  public void testOverworldStage() {
    testSession =
        new Session(new Seize(), "test", 8, new java.util.HashSet<>(), new net.fe.pick.Draft());
    testSession.addPlayer(localPlayer);

    Player p2 = new Player("P2", (byte) 1);
    p2.getParty().setColor(Party.TEAM_RED);
    testSession.addPlayer(p2);
    localPlayer.getParty().setColor(Party.TEAM_BLUE);
    p2.setTeam(2);
    localPlayer.setTeam(1);

    Unit u1 = UnitFactory.getUnit("Natasha");
    u1.addToInventory(WeaponFactory.getWeapon("Physic"));
    u1.setHp(1);
    localPlayer.getParty().addUnit(u1);

    Unit u3 = UnitFactory.getUnit("Oswin");
    u3.addToInventory(WeaponFactory.getWeapon("Silver Axe"));
    u3.equip(0);
    u3.setHp(1);
    p2.getParty().addUnit(u3);

    Unit u4 = UnitFactory.getUnit("Eirika");
    u4.addToInventory(WeaponFactory.getWeapon("Silver Sword"));
    u4.equip(0);
    u4.setHp(1);
    p2.getParty().addUnit(u4);

    Unit u2 = UnitFactory.getUnit("Lute");
    u2.addToInventory(WeaponFactory.getWeapon("Physic"));
    u2.setHp(1);
    localPlayer.getParty().addUnit(u2);

    currentStage = new ClientOverworldStage(testSession);

    this.client =
        new Client("nope", 12345) {
          @Override
          public void sendMessage(Message message) {
            if (message instanceof CommandMessage) {
              ((ClientOverworldStage) currentStage).processCommands((CommandMessage) message);
            }
          }
        };
  }
Beispiel #3
0
 /** Test of setTeam method, of class Player. */
 @Test
 public void testSetTeam() {
   System.out.println("setTeam");
   String team = "";
   Player instance = null;
   instance.setTeam(team);
   // TODO review the generated test code and remove the default call to fail.
   fail("The test case is a prototype.");
 }
 public void addPlayer(Player val) {
   players.add(val);
   val.setTeam(this);
 }
Beispiel #5
0
  public static void main(String[] args) {
    JSONParser parser = new JSONParser();
    ArrayList<Player> playerList = new ArrayList<>();
    Player[] playerArray;
    ArrayList<Player> mvpList = new ArrayList<>();
    try {

      BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
      String inputPath = reader.readLine();

      FileReader fileReader = new FileReader(inputPath);
      Object inputObject = parser.parse(fileReader);
      JSONObject jsonObject = (JSONObject) inputObject;
      JSONArray jsonArray = (JSONArray) jsonObject.get("players");

      Iterator<JSONObject> playerIterator = jsonArray.iterator();

      while (playerIterator.hasNext()) {

        JSONObject playerObject = (JSONObject) playerIterator.next();
        Player player = new Player();

        player.setId((String) playerObject.get("id"));
        player.setFirstname((String) playerObject.get("firstname"));
        player.setLastname((String) playerObject.get("lastname"));
        player.setTeam((String) playerObject.get("team"));
        player.setGp((int) (long) playerObject.get("gp"));
        player.setMin((int) (long) playerObject.get("min"));
        player.setPts((int) (long) playerObject.get("pts"));
        player.setOreb((int) (long) playerObject.get("oreb"));
        player.setDreb((int) (long) playerObject.get("dreb"));
        player.setAsts((int) (long) playerObject.get("asts"));
        player.setStl((int) (long) playerObject.get("stl"));
        player.setBlk((int) (long) playerObject.get("blk"));
        player.setTo((int) (long) playerObject.get("to"));
        player.setPf((int) (long) playerObject.get("pf"));
        player.setFga((int) (long) playerObject.get("fga"));
        player.setFgm((int) (long) playerObject.get("fgm"));
        player.setFta((int) (long) playerObject.get("fta"));
        player.setFtm((int) (long) playerObject.get("ftm"));
        player.setTpa((int) (long) playerObject.get("tpa"));
        player.setTpm((int) (long) playerObject.get("tpm"));

        JSONArray jsonPosArray = (JSONArray) playerObject.get("pos");
        Iterator<String> posIterator = jsonPosArray.iterator();
        ArrayList<String> posArray = new ArrayList<>();
        while (posIterator.hasNext()) {
          posArray.add((String) posIterator.next());
        }
        player.setPos(posArray);
        int result =
            player.getPts()
                + player.getOreb()
                + player.getDreb()
                + player.getAsts()
                + player.getStl()
                + player.getBlk()
                - player.getFga()
                + player.getFgm()
                - player.getFta()
                + player.getFtm()
                - player.getTo();
        player.setResult(result);
        playerList.add(player);
      }
      playerArray = new Player[playerList.size()];
      playerArray = playerList.toArray(playerArray);

      Player swapTemp;
      for (int i = 0; i < playerArray.length; i++) {
        for (int j = i; j < playerArray.length; j++) {
          if (playerArray[i].getResult() < playerArray[j].getResult()) {
            swapTemp = playerArray[i];
            playerArray[i] = playerArray[j];
            playerArray[j] = swapTemp;
          }
        }
      }

      int brojMvp = 0;
      Player mvp = playerArray[0];
      boolean bool = false;
      boolean bool1 = false;
      for (int i = 0; i < playerArray.length; i++) {
        if (playerArray[i] == null) {
          continue;
        }
        for (int j = 0; j < playerArray[i].getPos().size(); j++) {
          if (playerArray[i].getPos().contains("SG")) {
            out:
            for (int j2 = 0; j2 < mvpList.size(); j2++) {
              for (int k = j2 + 1; k < mvpList.size(); k++) {
                if (playerArray[i].getTeam().equals(mvpList.indexOf(j2))
                    && playerArray[i].getTeam().equals(mvpList.indexOf(k))) {
                  bool1 = true;
                  break out;
                }
              }
            }
            mvpList.add(playerArray[i]);
            brojMvp++;
            playerArray[i] = null;
            bool = true;
            break;
          }
        }
        if (bool) {
          bool = false;
          break;
        }
      }
      for (int i = 0; i < playerArray.length; i++) {
        if (playerArray[i] == null) {
          continue;
        }
        for (int j = 0; j < playerArray[i].getPos().size(); j++) {
          if (playerArray[i].getPos().contains("PG")) {
            mvpList.add(playerArray[i]);
            brojMvp++;
            playerArray[i] = null;
            bool = true;
            break;
          }
        }
        if (bool) {
          bool = false;
          break;
        }
      }
      for (int i = 0; i < playerArray.length; i++) {
        if (playerArray[i] == null) {
          continue;
        }
        for (int j = 0; j < playerArray[i].getPos().size(); j++) {
          if (playerArray[i].getPos().contains("SF")) {
            mvpList.add(playerArray[i]);
            brojMvp++;
            playerArray[i] = null;
            bool = true;
            break;
          }
        }
        if (bool) {
          bool = false;
          break;
        }
      }
      for (int i = 0; i < playerArray.length; i++) {
        if (playerArray[i] == null) {
          continue;
        }
        for (int j = 0; j < playerArray[i].getPos().size(); j++) {
          if (playerArray[i].getPos().contains("PF")) {
            mvpList.add(playerArray[i]);
            brojMvp++;
            playerArray[i] = null;
            bool = true;
            break;
          }
        }
        if (bool) {
          bool = false;
          break;
        }
      }
      for (int i = 0; i < playerArray.length; i++) {
        if (playerArray[i] == null) {
          continue;
        }
        for (int j = 0; j < playerArray[i].getPos().size(); j++) {
          if (playerArray[i].getPos().contains("C")) {
            mvpList.add(playerArray[i]);
            brojMvp++;
            playerArray[i] = null;
            bool = true;
            break;
          }
        }
        if (bool) {
          bool = false;
          break;
        }
      }
      if (brojMvp < 5) {
        System.out.println("Broj igraca u dream team-u je nedovoljan(" + brojMvp + ")");
        System.exit(0);
      }

      JSONObject outputObject = new JSONObject();
      JSONObject outputMvpObject = new JSONObject();

      Iterator<Player> mvpIterator = mvpList.iterator();
      FileWriter writer = new FileWriter("autputdzejson.json");

      outputMvpObject.put("id", mvp.getId());
      outputMvpObject.put("firstname", mvp.getFirstname());
      outputMvpObject.put("lastname", mvp.getLastname());
      outputMvpObject.put("team", mvp.getTeam());
      JSONArray mvpPosArray = new JSONArray();
      Iterator<String> mvpPosIterator = mvp.getPos().iterator();
      while (mvpPosIterator.hasNext()) {
        mvpPosArray.add(mvpPosIterator.next());
      }
      outputMvpObject.put("pos", mvpPosArray);
      outputObject.put("MVP", outputMvpObject);

      JSONArray outputDreamTeamArray = new JSONArray();
      while (mvpIterator.hasNext()) {
        JSONObject outputDreamTeamObject = new JSONObject();
        Player innerPlayer = mvpIterator.next();
        outputDreamTeamObject.put("id", innerPlayer.getId());
        outputDreamTeamObject.put("firstname", innerPlayer.getFirstname());
        outputDreamTeamObject.put("lastname", innerPlayer.getLastname());
        outputDreamTeamObject.put("team", innerPlayer.getTeam());
        JSONArray dreamTeamPosArray = new JSONArray();
        Iterator<String> dreamTeamPosIterator = innerPlayer.getPos().iterator();
        while (dreamTeamPosIterator.hasNext()) {
          dreamTeamPosArray.add(dreamTeamPosIterator.next());
        }
        outputDreamTeamObject.put("pos", dreamTeamPosArray);
        outputDreamTeamArray.add(outputDreamTeamObject);
      }
      outputObject.put("dreamTeam", outputDreamTeamArray);

      writer.write(outputObject.toJSONString());
      writer.flush();
      writer.close();

    } catch (FileNotFoundException e) {
      System.out.println("Pogresna putanja za ulazni fajl.");
    } catch (IOException e) {
      System.out.println("Greska pri unosu putanje.");
    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }