Android Open Source - GhostStories Game Board 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;
//from  w w w.  j  av  a2 s. co m
import games.ghoststories.data.interfaces.IGameBoardListener;
import games.ghoststories.enums.EBoardLocation;
import games.ghoststories.enums.ECardLocation;
import games.ghoststories.enums.EColor;
import games.ghoststories.enums.EGhostAbility;
import games.ghoststories.enums.EHaunterLocation;
import games.ghoststories.enums.EPlayerAbility;

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

/**
 * Data class representing one of the player game boards
 */
public class GameBoardData {

   /**
    * Constructor
    * @param pColor The color of the game board
    * @param pAbility The player ability associated with this game board
    * @param pLeftImageId The image resource id to use for the left space
    * @param pMiddleImageId The image resource id to use for the middle space
    * @param pRightImageId The image resource id to use for the right space
    */
   public GameBoardData(EColor pColor, EPlayerAbility pAbility, int pLeftImageId,
         int pMiddleImageId, int pRightImageId) {
      mColor = pColor;
      mAbility = pAbility;
      mEmptyImageIds.put(ECardLocation.LEFT, pLeftImageId);
      mEmptyImageIds.put(ECardLocation.MIDDLE, pMiddleImageId);
      mEmptyImageIds.put(ECardLocation.RIGHT, pRightImageId);
   }

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

   /**
    * Adds a listener for updates to this game board
    * @param pListener The listener to add
    */
   public void addGameBoardListener(IGameBoardListener pListener) {
      mListeners.add(pListener);
   }

   /**
    * Adds the ghost to this board at the given location
    * @param pGhost
    * @param pLocation
    */
   public void addGhost(GhostData pGhost, ECardLocation pLocation) {
      mGhosts.put(pLocation, pGhost);
      notifyListeners();
   }

   /**
    * @return The ability of this game board
    */
   public EPlayerAbility getAbility() {
      return mAbility;
   }

   /**
    * @return The color of this game board
    */
   public EColor getColor() {
      return mColor;
   }

   /**
    * @return How many times the player must roll the cursed die based on
    * the number of haunters with that ability on the board.
    */
   public int getCursedDieRollCount() {
      int count = 0;
      for(GhostData gd : mGhosts.values()) {
         if(gd.getTurnAbilities().contains(EGhostAbility.ROLL_CURSE_DIE)) {
            count++;
         }
      }
      return count;
   }

   /**
    * @param pCardLocation The card location to get the ghost data for
    * @return The data for the ghost at the specified card location or null
    * if no ghost currently at the given location
    */
   public GhostData getGhostData(ECardLocation pCardLocation) {
      return mGhosts.get(pCardLocation);
   }

   /**
    * @param pCardLocation The card location to get the empty id for
    * @return The empty image resource id
    */
   public int getEmptyImageId(ECardLocation pCardLocation) {
      return mEmptyImageIds.get(pCardLocation);
   }

   /**
    * @param pCardLocation The card location to get the id for
    * @return The image id for the specified location
    */
   public int getImageId(ECardLocation pCardLocation) {
      GhostData data = mGhosts.get(pCardLocation);
      if(data == null) {
         return mEmptyImageIds.get(pCardLocation);
      } else {
         return data.getImageId();
      }
   }

   /**
    * @return The location of this game board
    */
   public EBoardLocation getLocation() {
      return mLocation;
   }

   /**
    * @return The number of haunters on the current board
    */
   public int getNumHaunters() {
      int numHaunters = 0;
      for(GhostData gd : mGhosts.values()) {
         if(gd.getHaunterLocation() != EHaunterLocation.NONE) {
            numHaunters++;
         }
      }
      return numHaunters;
   }

   /**
    * @return Whether or not this board is filled with ghosts
    */
   public boolean isBoardFilled() {
      return mGhosts.values().size() == 3;
   }

   /**
    * Removes a listener for updates to this game board
    * @param pListener The listener to remove
    */
   public void removeGameBoardListener(IGameBoardListener pListener) {
      mListeners.remove(pListener);
   }

   /**
    * Removes the ghost from the given card location
    * @param pLocation The location to remove the card from
    */
   public void removeGhost(ECardLocation pLocation) {
      mGhosts.remove(pLocation);
      notifyListeners();
   }

   /**
    * @param pLocation The location of this game board
    */
   public void setLocation(EBoardLocation pLocation) {
      mLocation = pLocation;
   }

   /*
    * (non-Javadoc)
    * @see java.lang.Object#toString()
    */
   @Override
   public String toString() {
      StringBuilder sb = new StringBuilder("GameBoard:");
      sb.append(" color = ").append(mColor);
      sb.append(" ability = ").append(mAbility);
      for(ECardLocation loc : ECardLocation.values()) {
         if(mGhosts.containsKey(loc)) {
            sb.append(" ").append(loc.toString()).append(" = ").append(
                  mGhosts.get(loc).toString());
         } else {
            sb.append(" ").append(loc.toString()).append(" = ").append(
                  mEmptyImageIds.get(loc));
         }
      }
      return sb.toString();
   }

   /**
    * Notify listeners that the ghost deck has been updated
    */
   private void notifyListeners() {
      for(IGameBoardListener listener : mListeners) {
         listener.gameBoardUpdated();
      }
   }

   /** The player ability associated with this game board **/
   private final EPlayerAbility mAbility;
   /** The color of the game board **/
   private final EColor mColor;
   /** The image resource ids to use for this board when no card is present **/
   private final Map<ECardLocation, Integer> mEmptyImageIds =
         new EnumMap<ECardLocation, Integer>(ECardLocation.class);
   /** The card on the board **/
   private final Map<ECardLocation, GhostData> mGhosts =
         new EnumMap<ECardLocation, GhostData>(ECardLocation.class);
   /** The location of the game board **/
   private EBoardLocation mLocation;
   /** The set of listeners for ghost deck updates **/
   private final Set<IGameBoardListener> mListeners =
         new CopyOnWriteArraySet<IGameBoardListener>();
}




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