Beispiel #1
0
  // Function who return weapon infos
  public String getWeaponInfos() {
    String res = "";

    res = res + activeWeapon.getName() + "(" + activeWeapon.getDamage() + ")";

    return res;
  }
Beispiel #2
0
 /** This method returns the name of the selected weapon. */
 @Raw
 public String getSelectedWeapon() {
   return weapon.getName();
 }
Beispiel #3
0
  /**
   * Converts the given CLUE game data XML Tags.
   *
   * @param gameData CLUE game data to convert
   * @return the root XML Tag
   */
  private static XMLTag convertToXML(ClueGameData gameData) {
    XMLTag rootTag = new XMLTag();
    XMLTag clueGameTag = new XMLTag("ClueGame");

    XMLTag roomsTag = new XMLTag("Rooms");
    roomsTag.addAttribute(
        "displayRoomPicturesOnBoard", Boolean.toString(gameData.getDisplayRoomPicturesOnBoard()));
    for (Room room : gameData.getRooms()) {
      XMLTag roomTag = new XMLTag("Room");
      roomTag.addAttribute("id", Integer.toString(room.getId()));
      roomTag.addAttribute("name", room.getName());
      String pictureName = room.getPictureName();
      if (pictureName != null && !pictureName.isEmpty())
        roomTag.addAttribute("pictureName", pictureName);
      if (room.getTransparentPictureColor() != null)
        roomTag.addAttribute(
            "transparentPictureColor",
            Integer.toString(room.getTransparentPictureColor().getRGB()));
      roomsTag.addSubTag(roomTag);
    }
    clueGameTag.addSubTag(roomsTag);

    XMLTag suspectsTag = new XMLTag("Suspects");
    for (Suspect suspect : gameData.getSuspects()) {
      XMLTag suspectTag = new XMLTag("Suspect");
      suspectTag.addAttribute("id", Integer.toString(suspect.getId()));
      suspectTag.addAttribute("name", suspect.getName());
      suspectTag.addAttribute("color", Integer.toString(suspect.getColor().getRGB()));
      String pictureName = suspect.getPictureName();
      if (pictureName != null && !pictureName.isEmpty())
        suspectTag.addAttribute("pictureName", pictureName);
      suspectsTag.addSubTag(suspectTag);
    }
    clueGameTag.addSubTag(suspectsTag);

    XMLTag weaponsTag = new XMLTag("Weapons");
    for (Weapon weapon : gameData.getWeapons()) {
      XMLTag weaponTag = new XMLTag("Weapon");
      weaponTag.addAttribute("id", Integer.toString(weapon.getId()));
      weaponTag.addAttribute("name", weapon.getName());
      String pictureName = weapon.getPictureName();
      if (pictureName != null && !pictureName.isEmpty())
        weaponTag.addAttribute("pictureName", pictureName);
      weaponsTag.addSubTag(weaponTag);
    }
    clueGameTag.addSubTag(weaponsTag);

    Board board = gameData.getBoard();
    XMLTag boardTag = new XMLTag("ClueBoard");
    boardTag.addAttribute("height", Integer.toString(board.getHeight()));
    boardTag.addAttribute("width", Integer.toString(board.getWidth()));
    if (gameData.getBackgroundImageFilename() != null)
      boardTag.addAttribute("backgroundImageFilename", gameData.getBackgroundImageFilename());
    boardTag.addAttribute(
        "backgroundColor", Integer.toString(gameData.getBackgroundColor().getRGB()));
    for (int row = 0; row < board.getHeight(); row++) {
      for (int col = 0; col < board.getWidth(); col++) {
        DisplayTile tile = board.getTile(row, col);
        if (tile.isFreeTile()) continue;

        XMLTag tileTag = new XMLTag("Tile");
        tileTag.addAttribute("row", Integer.toString(row));
        tileTag.addAttribute("col", Integer.toString(col));

        if (tile.isRoomTile())
          tileTag.addAttribute("roomId", Integer.toString(tile.getRoom().getId()));
        for (DisplayTile.Direction direction : DisplayTile.Direction.values()) {
          if (tile.hasDoor(direction)) {
            XMLTag doorTag = new XMLTag("Door");
            doorTag.addContent(direction.toString());
            tileTag.addSubTag(doorTag);
          }
        }

        if (tile.isRemovedTile()) tileTag.addAttribute("removed", "true");
        else if (tile.isPassage()) {
          XMLTag passageConnectionTag = new XMLTag("PassageConnection");
          Board.TilePosition tilePosition = board.getTilePosition(tile.getPassageConnection());
          passageConnectionTag.addAttribute("row", Integer.toString(tilePosition.row));
          passageConnectionTag.addAttribute("col", Integer.toString(tilePosition.col));
          tileTag.addSubTag(passageConnectionTag);
        } else if (tile.hasSuspect()) {
          tileTag.addAttribute("suspectId", Integer.toString(tile.getSuspect().getId()));
          tileTag.addAttribute("suspectDirection", tile.getSuspectDirection().toString());
        }

        boardTag.addSubTag(tileTag);
      }
    }
    clueGameTag.addSubTag(boardTag);

    XMLTag storyTag = new XMLTag("Story");
    storyTag.addContent(gameData.getStory());
    clueGameTag.addSubTag(storyTag);

    rootTag.addSubTag(clueGameTag);
    return rootTag;
  }
Beispiel #4
0
  public static void savePlayerToJSON(Player p, Context c) {
    File outputFile = new File(c.getFilesDir(), "player_stats.json");
    try {
      OutputStream os = new FileOutputStream(outputFile);

      JsonWriter writer = new JsonWriter(new OutputStreamWriter(os, "UTF-8"));
      writer.beginObject();
      writer.name("username").value(p.getName());
      writer.name("race").value(p.getPlayerRace().getName());
      writer.name("maxHealth").value(p.getPureMaxHealth());
      writer.name("level").value(p.getLevel());
      writer.name("currentExp").value(p.getExp());
      writer.name("maxExp").value(1000);
      writer.name("gold").value(p.getGold());
      writer.name("upgradePoints").value(p.getUpgradePoint());
      writer.name("floorLimit").value(p.getFloorLimit());

      Quest q = p.getQuest();
      if (q != null) writer.name("quest").value(q.getType() + " " + q.getDifficulty());
      else writer.name("quest").value("none");

      Weapon w = p.getWeapon();
      if (w != null) writer.name("weapon").value(w.getName());
      else writer.name("weapon").value("none");

      Armor a = p.getHelmet();
      if (a != null) writer.name("helmet").value(a.getName());
      else writer.name("helmet").value("none");

      a = p.getShoulder();
      if (a != null) writer.name("shoulder").value(a.getName());
      else writer.name("shoulder").value("none");

      a = p.getGloves();
      if (a != null) writer.name("gloves").value(a.getName());
      else writer.name("gloves").value("none");

      a = p.getLeggings();
      if (a != null) writer.name("leggings").value(a.getName());
      else writer.name("leggings").value("none");

      a = p.getChest();
      if (a != null) writer.name("chest").value(a.getName());
      else writer.name("chest").value("none");

      writer.name("physicalDamage").value(p.getPurePhysicalDamage());
      writer.name("physicalDefence").value(p.getPurePhysicalDefence());

      writer.name("magicalDamage").value(p.getPureMagicalDamage());
      writer.name("magicalDefence").value(p.getPureMagicalDefence());

      writer.name("critChance").value(p.getPureCritChance());
      writer.name("critDamageBonus").value(p.getPureCritDamageBonus());

      // str,int luck
      writer.name("str").value(p.getPureStr());
      writer.name("int").value(p.getPureInt());
      writer.name("luck").value(p.getPureLuck());

      writer.endObject();

      writer.close();

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }