Android Open Source - GhostStories Token Supply Data






From Project

Back to project page GhostStories.

License

The source code is released under:

GNU General Public License

If you think the Android project GhostStories 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

package games.ghoststories.data;
// w  ww  .  j a va 2s  . c  om
import games.ghoststories.data.interfaces.ITokenListener;
import games.ghoststories.enums.EColor;

import java.util.EnumMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * Data model for a token supply. This is used for the main game token supply
 * as well as each player token supply.
 */
public class TokenSupplyData {

   /**
    * Dispose of the data
    */
   public void dispose() {
      mListeners.clear();
   }

   /**
    * Adds a Qi to the supply
    */
   public void addQi() {
      addQi(1);
   }

   /**
    * Adds the specified number of Qi to the supply
    * @param pNumQi The number of Qi to add to the supply
    */
   public void addQi(int pNumQi) {
      mNumQi += pNumQi;
      notifyListeners();
   }

   /**
    * Adds a single Tao Token of the given color to the supply
    * @param pColor The color of token to add
    */
   public void addTaoToken(EColor pColor) {
      addTaoTokens(pColor, 1);
   }

   /**
    * Adds the specified number of Tao Tokens of the given color to the supply
    * @param pColor The color of token to add
    * @param pNum The number of tokens to add
    */
   public void addTaoTokens(EColor pColor, int pNum) {
      if(!mTaoTokens.containsKey(pColor)) {
         mTaoTokens.put(pColor, pNum);
      } else {
         int numTokens = mTaoTokens.get(pColor);
         mTaoTokens.put(pColor, numTokens + pNum);
      }
      notifyListeners();
   }

   /**
    * Adds a listener for token supply updates
    * @param pListener The listener to add
    */
   public void addTokenListener(ITokenListener pListener) {
      mListeners.add(pListener);
   }

   /**
    * @return The number of Qi in this supply
    */
   public int getNumQi() {
      return mNumQi;
   }

   /**
    * Gets the number of tao tokens of the specified color
    * @param pColor The color of token to get
    * @return The number of tao tokens of the given color
    */
   public int getNumTaoTokens(EColor pColor) {
      return mTaoTokens.get(pColor);
   }

   /**
    * Removes a single Qi from the supply
    */
   public void removeQi() {
      removeQi(1);
   }

   /**
    * Removes the specified number of Qi from the supply
    * @param pNum The number of Qi to remove
    */
   public void removeQi(int pNum) {
      mNumQi = Math.max(0, mNumQi - pNum);
      notifyListeners();
   }

   /**
    * Removes a single Tao Token of the given color from the supply
    * @param pColor The color of the token to remove
    */
   public void removeTaoToken(EColor pColor) {
      removeTaoTokens(pColor, 1);
   }

   /**
    * Removes the specified number of Tao Tokens from the supply for the
    * given color
    * @param pColor The color of token to remove
    * @param pNum The number of tokens to remove
    */
   public void removeTaoTokens(EColor pColor, int pNum) {
      if(mTaoTokens.containsKey(pColor)) {
         int numTokens = mTaoTokens.get(pColor);
         mTaoTokens.put(pColor, Math.max(0, numTokens - pNum));
         notifyListeners();
      }
   }

   /**
    * Removes a token listener
    * @param pListener The listener to remove
    */
   public void removeTokenListener(ITokenListener pListener) {
      mListeners.remove(pListener);
   }

   /**
    * Sets the number of tao tokens of a particular color
    * @param pColor The color of the token to set
    * @param pNumTokens The number of tokens
    */
   public void setNumTaoTokens(EColor pColor, int pNumTokens) {
      mTaoTokens.put(pColor, pNumTokens);
      notifyListeners();
   }

   /**
    * Sets the number of qi
    * @param pNumQi The number of qi
    */
   public void setNumQi(int pNumQi) {
      mNumQi = pNumQi;
      notifyListeners();
   }

   /**
    * Sets the tao tokens to use for the supply
    * @param pTokenMap The new set of tao tokens to use
    */
   public void setTaoTokens(Map<EColor, Integer> pTokenMap) {
      mTaoTokens.putAll(pTokenMap);
      notifyListeners();
   }

   /**
    * Notify listeners that the token supply was updated
    */
   protected void notifyListeners() {
      for(ITokenListener listener : mListeners) {
         listener.tokenDataUpdated();
      }
   }

   /** Set of token supply listeners **/
   protected Set<ITokenListener> mListeners =
         new CopyOnWriteArraySet<ITokenListener>();
   /** The number of qi in the supply **/
   protected int mNumQi = 0;
   /** The number of tao tokens in the supply **/
   protected final Map<EColor, Integer> mTaoTokens =
         new EnumMap<EColor, Integer>(EColor.class);
}




Java Source Code List

com.drawable.shapes.GradientRectangle.java
com.interfaces.IDraggable.java
com.utils.AndroidUtils.java
com.utils.AnimationUtils2.java
com.utils.ImageLoadingTask.java
com.utils.ImageRotationTask.java
com.utils.ImageViewUtils.java
com.views.NumberedImageView.java
com.views.ToggledImageView.java
com.views.layouts.ScaledLinearLayout.java
com.views.layouts.ScaledRelativeLayout.java
com.views.layouts.SquareGridLayout.java
com.views.layouts.SquareLinearLayout.java
com.views.layouts.SquareTableLayout.java
com.views.layouts.ZoomableRelativeLayout.java
com.views.listeners.DragTouchListener.java
games.ghoststories.activities.GameLoadingActivity.java
games.ghoststories.activities.GameScreenActivity.java
games.ghoststories.activities.TitleActivity.java
games.ghoststories.controllers.GhostDeckController.java
games.ghoststories.controllers.HaunterController.java
games.ghoststories.controllers.PlayerBoardCardController.java
games.ghoststories.controllers.VillageTileController.java
games.ghoststories.controllers.combat.CombatAreaController.java
games.ghoststories.controllers.combat.DiceDragListener.java
games.ghoststories.controllers.combat.GhostDragListener.java
games.ghoststories.controllers.combat.TaoTokenDragListener.java
games.ghoststories.data.DragData.java
games.ghoststories.data.GameBoardData.java
games.ghoststories.data.GhostData.java
games.ghoststories.data.GhostDeckData.java
games.ghoststories.data.GhostGraveyardData.java
games.ghoststories.data.GhostStoriesBitmaps.java
games.ghoststories.data.GhostStoriesConstants.java
games.ghoststories.data.GhostStoriesGameManager.java
games.ghoststories.data.PlayerData.java
games.ghoststories.data.TokenSupplyData.java
games.ghoststories.data.interfaces.IGameBoardListener.java
games.ghoststories.data.interfaces.IGamePhaseListener.java
games.ghoststories.data.interfaces.IGameTokenListener.java
games.ghoststories.data.interfaces.IGhostDeckListener.java
games.ghoststories.data.interfaces.IGhostListener.java
games.ghoststories.data.interfaces.ITokenListener.java
games.ghoststories.data.interfaces.IVillageTileListener.java
games.ghoststories.data.village.BuddhistTempleTileData.java
games.ghoststories.data.village.CircleOfPrayerTileData.java
games.ghoststories.data.village.VillageTileDataFactory.java
games.ghoststories.data.village.VillageTileData.java
games.ghoststories.enums.EBoardLocation.java
games.ghoststories.enums.ECardLocation.java
games.ghoststories.enums.EColor.java
games.ghoststories.enums.ECombatPhase.java
games.ghoststories.enums.EDiceSide.java
games.ghoststories.enums.EDice.java
games.ghoststories.enums.EDifficulty.java
games.ghoststories.enums.EDragItem.java
games.ghoststories.enums.EGamePhase.java
games.ghoststories.enums.EGhostAbility.java
games.ghoststories.enums.EHaunterLocation.java
games.ghoststories.enums.EPlayerAbility.java
games.ghoststories.enums.ETileLocation.java
games.ghoststories.enums.EVillageTile.java
games.ghoststories.fragments.AuxAreaFragment.java
games.ghoststories.fragments.GameboardFragment.java
games.ghoststories.utils.BitmapUtils.java
games.ghoststories.utils.GameUtils.java
games.ghoststories.utils.XmlUtils.java
games.ghoststories.views.GameScreen.java
games.ghoststories.views.aux_area.CardInfoView.java
games.ghoststories.views.aux_area.GamePhaseDetailsView.java
games.ghoststories.views.aux_area.GamePhaseView.java
games.ghoststories.views.aux_area.GhostDeckView.java
games.ghoststories.views.aux_area.GhostGraveyardCardView.java
games.ghoststories.views.aux_area.PlayerInfoView.java
games.ghoststories.views.combat.CombatDamageView.java
games.ghoststories.views.combat.CombatDiceAreaView.java
games.ghoststories.views.combat.CombatDiceView.java
games.ghoststories.views.combat.CombatGhostView.java
games.ghoststories.views.combat.CombatInstructionsView.java
games.ghoststories.views.combat.CombatRollView.java
games.ghoststories.views.combat.CombatView.java
games.ghoststories.views.combat.ExtraCombatDiceView.java
games.ghoststories.views.combat.GhostHealthView.java
games.ghoststories.views.common.AbstractNumberedTokenView.java
games.ghoststories.views.common.BuddhaTokenView.java
games.ghoststories.views.common.QiTokenView.java
games.ghoststories.views.common.TaoTokenView.java
games.ghoststories.views.common.YinYangTokenView.java
games.ghoststories.views.gameboard.PlayerAreaView.java
games.ghoststories.views.gameboard.PlayerBoardCardView.java
games.ghoststories.views.gameboard.PlayerBoardView.java
games.ghoststories.views.gameboard.PlayerTokenAreaView.java
games.ghoststories.views.gameboard.VillageTileView.java
games.ghoststories.views.graveyard.GraveyardScrollView.java
games.ghoststories.views.graveyard.GraveyardView.java
games.ghoststories.views.title.TitleButton.java
games.ghoststories.views.title.TitleScreen.java
games.ghoststories.views.village.CircleOfPrayerView.java