Android Open Source - RPGWorld Player






From Project

Back to project page RPGWorld.

License

The source code is released under:

MIT License

If you think the Android project RPGWorld listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * Jun 13, 2013/*  www .  j a v  a 2 s  .co m*/
 * Player.java
 * Daniel Pok
 * AP Java 6th
 */
package com.nokarateclass.rpgworld.characters;

import android.util.Log;

import com.nokarateclass.rpgworld.io.SettingsHolder;

/**
 * @author poler_000
 *
 */
public class Player {

  //variables
  private int mHealth;
  private int mMaxHealth;
  private CharacterActor mCharacter;
  
  /*CharacterActor will support the following callback methods:
   * onDeath()          called when the hp drops =< 0
   * onHealthChange(int change)  called when the health changes, includes the amount it changed by
   * onMaxHealthChange(int change)ditto for MaxHealth
   * onOverHeal(int amount)    called when hp exceeds maxHP, amount is how much it exceeded max by
   */
  
  public Player() {
    
  }
  
  public Player(CharacterActor character){
    mCharacter = character;
  }
  
  public int getHealth(){
    return mHealth;
  }
  
  public synchronized void setHealth(int health){
    int change = health - mHealth;
    int overHeal = health - mMaxHealth;
    mHealth = health;
    Log.d("Player", "SET HEALTH(" + health + "): " + mCharacter.toString() + String.format(" HP: %d/%d, change: %d, overheal: %d", mHealth, mMaxHealth, change, overHeal));
    if(change != 0 && mCharacter != null){
      Log.d("Player", "ON HEALTH CHANGE: " + mCharacter.toString() + String.format(" HP: %d/%d, change: %d, overheal: %d", mHealth, mMaxHealth, change, overHeal));
      mCharacter.onHealthChange(change);
    }
    if(overHeal > 0 && mCharacter != null){
      Log.d("Player", "ON OVERHEAL: " + mCharacter.toString() + String.format(" HP: %d/%d, change: %d, overheal: %d", mHealth, mMaxHealth, change, overHeal));
      mCharacter.onOverHeal(overHeal);
    }
    if(mHealth <= 0 && mCharacter != null){
      Log.d("Player", "ON DEATH: " + mCharacter.toString() + String.format(" HP: %d/%d, change: %d, overheal: %d", mHealth, mMaxHealth, change, overHeal));
      mCharacter.onDeath();
      Log.d("Player", "ON DEATH COMPLETE: " + mCharacter.toString() + String.format(" HP: %d/%d, change: %d, overheal: %d", mHealth, mMaxHealth, change, overHeal));
    }
    
  }
  
  public void addHealth(int add){
    Log.d("Player", "ADDING HEALTH(" + add + "): " + mCharacter.toString() + String.format(" HP: %d/%d", mHealth, mMaxHealth));
    setHealth(mHealth + add);
  }
  
  public int getMaxHealth(){
    return mMaxHealth;
  }
  
  public synchronized void setMaxHealth(int health){
    int change = health - mMaxHealth;
    mMaxHealth = health;
    if(health != 0 && mCharacter != null){
      Log.d("Player", "ON MAX HEALTH CHANGE: " + mCharacter.toString() + String.format(" HP: %d/%d, max health change: %d", mHealth, mMaxHealth, change));
      mCharacter.onMaxHealthChange(change);
    }

  }
  
  public void addMaxHealth(int add){
    setMaxHealth(mMaxHealth + add);
  }
  
  public SettingsHolder saveValues(){
    SettingsHolder settings = new SettingsHolder();
    
    settings.put("player:health", mHealth);
    settings.put("player:maxhealth", mMaxHealth);
    
    return settings;
  }
  
  public void restoreValues(SettingsHolder settings){
    if(settings.containsKey("player:health")) mHealth = settings.<Integer>getType("player:health");
    if(settings.containsKey("player:maxhealth")) mMaxHealth = settings.<Integer>getType("player:maxhealth");
  }

}




Java Source Code List

com.nokarateclass.rpgworld.Grid.java
com.nokarateclass.rpgworld.MapEditor.java
com.nokarateclass.rpgworld.backgrounds.BackgroundCharacter.java
com.nokarateclass.rpgworld.backgrounds.GrassBackground.java
com.nokarateclass.rpgworld.backgrounds.SandBackground.java
com.nokarateclass.rpgworld.characters.AndroidCharacter.java
com.nokarateclass.rpgworld.characters.CactusCharacter.java
com.nokarateclass.rpgworld.characters.CharacterActor.java
com.nokarateclass.rpgworld.characters.HeroCharacter.java
com.nokarateclass.rpgworld.characters.MonsterCharacter.java
com.nokarateclass.rpgworld.characters.Player.java
com.nokarateclass.rpgworld.characters.RockCharacter.java
com.nokarateclass.rpgworld.characters.Status.java
com.nokarateclass.rpgworld.characters.TreeCharacter.java
com.nokarateclass.rpgworld.editor.CharacterFactory.java
com.nokarateclass.rpgworld.editor.EditorGrid.java
com.nokarateclass.rpgworld.grid.BackgroundGrid.java
com.nokarateclass.rpgworld.grid.BeatTask.java
com.nokarateclass.rpgworld.grid.CharacterGrid.java
com.nokarateclass.rpgworld.grid.Location.java
com.nokarateclass.rpgworld.grid.MainCharacterGrid.java
com.nokarateclass.rpgworld.io.FileExporter.java
com.nokarateclass.rpgworld.io.FileIO.java
com.nokarateclass.rpgworld.io.FileImporter.java
com.nokarateclass.rpgworld.io.GridSerializer.java
com.nokarateclass.rpgworld.io.SettingsHolder.java
com.nokarateclass.rpgworld.ui.GridClickListener.java
com.nokarateclass.rpgworld.ui.ImageGridView.java
com.nokarateclass.rpgworld.world.Region.java
com.nokarateclass.rpgworld.world.World.java
com.nokarateclass.rpgworld.world.Zone.java