Android Open Source - GhostStories Ghost Deck 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   ww w .  ja  va2  s .  co m
import games.ghoststories.data.interfaces.IGhostDeckListener;
import games.ghoststories.enums.EDifficulty;

import java.util.ArrayDeque;
import java.util.Collections;
import java.util.Deque;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * <p>Data representation of the current deck of ghost cards. Upon creation,
 * the Ghost Deck is built based on the passed in {@link EDifficulty} using the
 * contents of the {@link #sGhostXmlFile} and assets/xml/wufeng.xml file
 * in order to build the deck.
 * <p>The deck is built as follows for each of the different difficulty levels:
 * <li>{@link EDifficulty#INITIATE} : 45 ghosts, 1 incarnation, 10 ghosts
 * <li>{@link EDifficulty#NORMAL} : 45 ghosts, 1 incarnation, 10 ghosts
 * (same as Initiate)
 * <li>{@link EDifficulty#NIGHTMARE} : 10 ghosts, 1 incarnation, 10 ghosts,
 * 1 incarnation, 10 ghosts, 1 incarnation, 10 ghosts, 1 incarnation, rest of
 * the ghost deck
 * <li>{@linke EDifficulty#HELL} : 10 ghosts, 1 incarnation, 10 ghosts,
 * 1 incarnation, 10 ghosts, 1 incarnation, 10 ghosts, 1 incarnation, rest of
 * the ghost deck (Same as Nightmare)
 */
public class GhostDeckData {
   /**
    * Constructor
    * @param pDifficulty The difficulty used to build the deck
    */
   public GhostDeckData(EDifficulty pDifficulty, List<GhostData> pGhosts,
         List<GhostData> pIncarnations) {

      //Shuffle the lists
      Collections.shuffle(pGhosts);
      Collections.shuffle(pIncarnations);

      //Build the final ghost deck based on the current difficulty
      switch(pDifficulty) {
      case INITIATE:
      case NORMAL:
         mGhostDeck = new ArrayDeque<GhostData>(pGhosts.size() + 1); //1 wu feng
         mGhostDeck.addAll(pGhosts.subList(0, 45));
         mGhostDeck.add(pIncarnations.get(0));
         mGhostDeck.addAll(pGhosts.subList(45, pGhosts.size()));
         break;
      case NIGHTMARE:
      case HELL:
         mGhostDeck = new ArrayDeque<GhostData>(pGhosts.size() + 4); //4 wu feng
         mGhostDeck.addAll(pGhosts.subList(0, 10));
         mGhostDeck.add(pIncarnations.get(0));
         mGhostDeck.addAll(pGhosts.subList(10, 20));
         mGhostDeck.add(pIncarnations.get(1));
         mGhostDeck.addAll(pGhosts.subList(20, 30));
         mGhostDeck.add(pIncarnations.get(2));
         mGhostDeck.addAll(pGhosts.subList(30, 40));
         mGhostDeck.add(pIncarnations.get(3));
         mGhostDeck.addAll(pGhosts.subList(40, pGhosts.size()));
         break;
      default:
         mGhostDeck = new ArrayDeque<GhostData>();
         break;
      }
   }

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

   /**
    * Add a listener for updates to the ghost deck
    * @param pListener The listener
    */
   public void addGhostDeckListener(IGhostDeckListener pListener) {
      mListeners.add(pListener);
   }

   /**
    * Adds a card to the top of the deck.
    * @param pGhostData The data of the card to add
    */
   public void addTopCard(GhostData pGhostData) {
      mGhostDeck.push(pGhostData);
      notifyListeners();
   }

   /**
    * Sets the status of the top card to flipped
    */
   public void flipTopCard() {
      GhostData data = mGhostDeck.peek();
      if(data != null) {
         data.setIsFlipped(!data.isFlipped());
         notifyListeners();
      }
   }

   /**
    * @return The number of ghosts remaining in the deck
    */
   public int getNumGhosts() {
      return mGhostDeck.size();
   }

   /**
    * @return The current top card of the deck
    */
   public GhostData getTopCard() {
      return mGhostDeck.peek();
   }

   /**
    * Removes a listener from the listener list
    * @param pListener The listener to remove
    */
   public void removeGhostDeckListener(IGhostDeckListener pListener) {
      mListeners.remove(pListener);
   }

   /**
    * @return The new top card of the deck
    */
   public GhostData removeTopCard() {
      GhostData topCard = mGhostDeck.pop();
      notifyListeners();
      return topCard;
   }

   /**
    * Sets the dragging state of the top card
    * @param pDragging
    */
   public void setTopCardDragging(boolean pDragging) {
      GhostData topCard = mGhostDeck.peek();
      topCard.setIsDragging(pDragging);
      notifyListeners();
   }

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

   /** The ghost deck **/
   private final Deque<GhostData> mGhostDeck;

   /** The set of listeners for ghost deck updates **/
   private final Set<IGhostDeckListener> mListeners =
         new CopyOnWriteArraySet<IGhostDeckListener>();
}




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