Ejemplo n.º 1
0
 public int interpretCommand(String command, GameCharacter actor) {
   if (command.toLowerCase().equals("use") || command.toLowerCase().startsWith("go")) {
     if (actor.moveTo(target))
       actor.getLastRoom().receiveMessage(actor.getName() + " goes through the " + this.getName());
     else actor.receiveMessage("This door doesn't go anywhere.");
     return 1;
   } else return 0;
 }
 /**
  * Load the GameCharacter from the database.
  *
  * @param name The (unique) name of the game character.
  * @return A GameCharacter object holding all information.
  * @exception UnknownUserException If no entry with the given name could be found in the database.
  */
 public static GameCharacter load(String name) throws UnknownUserException {
   // Load user state from database. This method throws a
   // UserNotFoundException if the user is not in the database.
   Log.info("CharacterState", "load", "Load data of character: " + name);
   try {
     GameCharacter character = JdbcUtil.loadCharacter(name);
     character.setStateful(true);
     Log.info("CharacterState", "load", "Character data loaded.");
     return character;
   } catch (NoRecordFoundException e) {
     throw new UnknownUserException("Character name: " + name);
   }
 }
Ejemplo n.º 3
0
  /**
   * get xp and gold from killing characters
   *
   * @param Charac collision characters
   */
  public void KillXP(GameCharacter Charac) {
    // When the character dies
    if (Charac.ISDEAD && Charac.COLL_LISTENER) {

      Charac.COLL_LISTENER = false;
      audDEATH.playAudio("death.wav");

      // Remove collision listener
      for (int j = 0; j < FIREBALL.length; j++) {
        FIREBALL[j].removeCollChar(Charac);
      }
      for (int j = 0; j < SHOCK.length; j++) {
        SHOCK[j].removeCollChar(Charac);
      }
      for (int j = 0; j < DARKNESS.length; j++) {
        DARKNESS[j].removeCollChar(Charac);
      }
      for (int j = 0; j < LIFE_DRAIN.length; j++) {
        LIFE_DRAIN[j].removeCollChar(Charac);
      }

      // Add Xp
      STATS.IncreaseXP(10 * Charac.STATS.LEVEL);
      // Add Gold
      this.GOLD += Charac.GOLD;
    }
  }
Ejemplo n.º 4
0
  @Override
  public void attack(GameCharacter other) throws OutOfEnergyException {

    if (other == this) {
      throw new IllegalStateException("Cannot attack itself");
    }

    if (this.getEnergy() < this.getAttackCost()) {
      throw new OutOfEnergyException(this.getName() + " is out of energy. Battle over.");
    }

    boolean isCritical = Math.random() < CRITICAL_HIT_TRESHOLD;

    int damage = this.getPower();

    if (isCritical) {
      System.out.println("Critical hit by the mage!");
      damage *= 2;
    }

    this.setEnergy(this.getEnergy() - this.getAttackCost());

    other.respond(damage);
  }
Ejemplo n.º 5
0
  public static void main(String[] args) {

    GameCharacter player1 = new GameCharacter();
    player1.setName("Felix");
    player1.setRace("Dwarf");
    player1.setHealthPoints(75);
    player1.setManaPoints(50);

    String direction;
    Scanner keyboard = new Scanner(System.in);
    System.out.println("Which direction would you like to head? North, South, East, or West.");
    direction = keyboard.nextLine();

    player1.goOnAnAdventure(direction);

    Game game1 = new Game();

    game1.playGame();
  }
Ejemplo n.º 6
0
  /**
   * Takes a loaded XML document and creates a new World out of it. At the moment loads NPCs but not
   * Player Characters.
   *
   * @param XMLFilePrefix
   * @param latestDate
   * @param df
   * @return
   */
  public void restoreStateFromXML(Document doc) {
    Game.setWorld(new World());

    NodeList wmessageList = doc.getElementsByTagName("welcome-message");
    Element wmessageElement = (Element) wmessageList.item(0);
    NodeList wmessageChildList = wmessageElement.getChildNodes();
    if (((Node) wmessageChildList.item(0)) != null)
      welcomeMessage = ((Node) wmessageChildList.item(0)).getNodeValue().trim();

    NodeList gmessageList = doc.getElementsByTagName("goodbye-message");
    Element gmessageElement = (Element) gmessageList.item(0);
    NodeList gmessageChildList = gmessageElement.getChildNodes();
    if (((Node) gmessageChildList.item(0)) != null)
      goodbyeMessage = ((Node) gmessageChildList.item(0)).getNodeValue().trim();

    // ------ LOAD ROOMS ------- //

    NodeList listOfRooms = doc.getElementsByTagName("room");
    int totalRooms = listOfRooms.getLength();
    if (Game.isDebug()) Game.logMessage("Number of rooms read: " + totalRooms);

    for (int s = 0; s < listOfRooms.getLength(); s++) {

      Node firstRoomNode = listOfRooms.item(s);
      if (firstRoomNode.getNodeType() == Node.ELEMENT_NODE) {

        Element firstRoomElement = (Element) firstRoomNode;

        // -------
        NodeList nameList = firstRoomElement.getElementsByTagName("name");
        Element nameElement = (Element) nameList.item(0);

        NodeList textNameList = nameElement.getChildNodes();
        if (Game.isDebug())
          Game.logMessage("Name : " + ((Node) textNameList.item(0)).getNodeValue().trim());
        String thisName = ((Node) textNameList.item(0)).getNodeValue().trim();

        // -------
        NodeList descriptionList = firstRoomElement.getElementsByTagName("description");
        Element descriptionElement = (Element) descriptionList.item(0);

        NodeList textDescList = descriptionElement.getChildNodes();
        if (Game.isDebug())
          Game.logMessage("Description : " + ((Node) textDescList.item(0)).getNodeValue().trim());
        String thisDesc = ((Node) textDescList.item(0)).getNodeValue().trim();

        Game.getWorld().getRooms().add(new Room(thisName, thisDesc));

        // ------ LOAD DOORS ------- //
        List<Door> newDoors = Door.loadStateFromXML(firstRoomElement);

        // ------ LOAD STANDARD ITEMS ------- //
        List<Item> newItems = Item.loadStateFromXML(firstRoomElement);

        // ----- LOAD GCS -------------//
        List<GameCharacter> newGCs = GameCharacter.loadStateFromXML(firstRoomElement);

        // ----- LOAD NPCS -------------//
        // List<NPCharacter> newNPCs = NPCharacter.loadStateFromXML(firstRoomElement);

        // ------ LOAD MAP ITEMS ------- //
        List<Item> newMapItems = MapItem.loadStateFromXML(firstRoomElement);

        for (int k = 0; k < newDoors.size(); k++)
          Game.getWorld()
              .getRooms()
              .get(Game.getWorld().getRooms().size() - 1)
              .objectEntered(newDoors.get(k));
        for (int k = 0; k < newItems.size(); k++)
          newItems
              .get(k)
              .moveTo(Game.getWorld().getRooms().get(Game.getWorld().getRooms().size() - 1));
        for (int k = 0; k < newMapItems.size(); k++)
          newMapItems
              .get(k)
              .moveTo(Game.getWorld().getRooms().get(Game.getWorld().getRooms().size() - 1));
        for (int k = 0; k < newGCs.size(); k++)
          newGCs.get(k).moveTo(Game.getWorld().getRooms().get(0));
      }
    }

    for (Room room : Game.getWorld().getRooms()) {
      for (Door door : room.getDoors()) {
        if (!door.findTarget(Game.getWorld().getRooms())) {
          Game.logError(
              "Warning: Failed at door "
                  + door.getName()
                  + " in room "
                  + room.getName()
                  + " due to bad target name "
                  + door.getTargetName(),
              null);
          //	return null;
        }
      }
    }

    for (Room room : Game.getWorld().getRooms())
      for (GameCharacter gc : room.getGameCharacters()) gc.lastRoomFromID();

    /*
    // Bert as yet not in any save file
    List<Dialogue> convo2x = new ArrayList<Dialogue>();
    convo2x.add(new Dialogue(1,"\"I will heal you.\"","heal 10 actor"));
    convo2x.add(new Dialogue(2,"\"You said Verb\"","shout dance!"));

    List<Dialogue> convo1x = new ArrayList<Dialogue>();
    convo1x.add(new Dialogue(1,"\"You said Cheese\""));
    convo1x.add(new Dialogue(2,"\"You said Apples\""));

    List<Dialogue> convox = new ArrayList<Dialogue>();
    convox.add(new Dialogue(1,"\"I am Bert, an NPC in this world.\"\n1 Cheese\n2 Apples", convo1x));
    convox.add(new Dialogue(2,"\"What do you need?\"\n1 Healing, please.\n2 A verb, please.", convo2x));

    newWorld.getRooms().get(1).objectEntered(new NPCharacter("Bert","A small green man.","\"Hi there!\"\n1 Tell me about yourself.\n2 Help me!","Farewell then!",convox));

    */
  }
Ejemplo n.º 7
0
 /**
  * Adds or updates a entity of the map
  *
  * @param character
  */
 public void addEntity(GameCharacter character) {
   if (mapCharacterEntities.containsKey(character.getEntityID())) {
     mapCharacterEntities.remove(character.getEntityID());
   }
   mapCharacterEntities.put(character.getEntityID(), character);
 }