Android Open Source - GhostStories Combat View






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.views.combat;
/*from   w  w w. java 2s  . co  m*/
import games.ghoststories.R;
import games.ghoststories.controllers.combat.CombatAreaController;
import games.ghoststories.data.GhostData;
import games.ghoststories.data.PlayerData;
import games.ghoststories.views.aux_area.PlayerInfoView;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout;

/**
 * Top level view for the combat area that shows during the combat phase of
 * the game.
 */
public class CombatView extends RelativeLayout {

   /**
    * Constructor
    * @param pContext
    */
   public CombatView(Context pContext) {
      super(pContext);
      init();
   }

   /**
    * Constructor
    * @param pContext
    * @param pAttrs
    */
   public CombatView(Context pContext, AttributeSet pAttrs) {
      super(pContext, pAttrs);
      init();
   }

   /**
    * Constructor
    * @param pContext
    * @param pAttrs
    * @param pDefStyle
    */
   public CombatView(Context pContext, AttributeSet pAttrs, int pDefStyle) {
      super(pContext, pAttrs, pDefStyle);
      init();
   }

   /**
    * Dispose this view
    */
   public void dispose() {
      mController.dispose();
   }

   /**
    * Sets the data that is used for the combat.
    * @param pPrimaryAttacker The primary attacker during this combat phase
    * @param pSecondaryAttackers The list of secondary attackers during this combat phase
    * @param pGhost1 The first ghost being attacked
    * @param pGhost2 The second ghost being attacked or <code>null</code> if N/A
    */
   public void setCombatData(PlayerData pPrimaryAttacker,
         List<PlayerData> pSecondaryAttackers, GhostData pGhost1,
         GhostData pGhost2) {
      //Info area 1 is for the primary player
      PlayerInfoView pi1 = (PlayerInfoView)findViewById(R.id.info_area_1);
      pi1.setPlayerData(pPrimaryAttacker);
      pi1.setVisibility(VISIBLE);

      //Info area 2-4 are for any supporting players
      List<PlayerInfoView> playerViews = new ArrayList<PlayerInfoView>();
      playerViews.add((PlayerInfoView)findViewById(R.id.info_area_2));
      playerViews.add((PlayerInfoView)findViewById(R.id.info_area_3));
      playerViews.add((PlayerInfoView)findViewById(R.id.info_area_4));
      for(PlayerInfoView piv : playerViews) {
         piv.setVisibility(INVISIBLE);
      }
      for(int i = 0; i < pSecondaryAttackers.size(); ++i) {
         PlayerInfoView view = playerViews.get(i);
         PlayerData data = pSecondaryAttackers.get(i);
         view.setVisibility(VISIBLE);
         view.setPlayerData(data);
      }

      //Set the ghost data
      CombatGhostView ghost1 = (CombatGhostView)findViewById(R.id.ghost1);
      ghost1.setVisibility(GONE);
      CombatGhostView ghost2 = (CombatGhostView)findViewById(R.id.ghost2);
      ghost2.setVisibility(GONE);

      if(pGhost1 != null) {
         ghost1.setGhostData(pGhost1);
         ghost1.setVisibility(VISIBLE);
      }
      if(pGhost2 != null) {
         ghost2.setGhostData(pGhost2);
         ghost2.setVisibility(VISIBLE);
      }

      CombatDiceAreaView diceContainer =
            (CombatDiceAreaView)findViewById(R.id.combat_dice);
      diceContainer.setPrimaryAttacker(pPrimaryAttacker);

      //TODO Should this really be creating the controller?
      //Probably should be passed in.
      mController = new CombatAreaController(this, pPrimaryAttacker,
            pSecondaryAttackers, pGhost1, pGhost2);
   }

   /**
    * Initialize this view
    */
   private void init() {
      //Ignore touches so they don't propagate to the background
      setOnTouchListener(new OnTouchListener() {
         public boolean onTouch(View v, MotionEvent event) {
            return true;
         }
      });
   }

   /** Controller for the combat area **/
   private CombatAreaController mController = null;
}




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