Android Open Source - GhostStories Gameboard Fragment






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.fragments;
// w  w w  .j a va2 s .c  o m
import games.ghoststories.R;
import games.ghoststories.controllers.HaunterController;
import games.ghoststories.controllers.PlayerBoardCardController;
import games.ghoststories.controllers.VillageTileController;
import games.ghoststories.data.GameBoardData;
import games.ghoststories.data.GhostStoriesGameManager;
import games.ghoststories.data.PlayerData;
import games.ghoststories.data.village.VillageTileData;
import games.ghoststories.enums.EBoardLocation;
import games.ghoststories.enums.ECardLocation;
import games.ghoststories.enums.EColor;
import games.ghoststories.enums.ETileLocation;
import games.ghoststories.views.gameboard.PlayerAreaView;
import games.ghoststories.views.gameboard.PlayerBoardCardView;
import games.ghoststories.views.gameboard.PlayerBoardView;
import games.ghoststories.views.gameboard.PlayerTokenAreaView;
import games.ghoststories.views.gameboard.VillageTileView;

import java.util.Map;

import android.graphics.Point;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridLayout;
import android.widget.GridLayout.Spec;

/**
 * Fragment representing the game board area. The game board contains the four
 * different player areas and the village tile area. The player areas include
 * the card locations and player token areas.
 */
//TODO This class is pretty ugly in the way it builds the layout. Look to try
//and improve this.
public class GameboardFragment extends Fragment {
   
   /*
    * (non-Javadoc)
    * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
    */
   @Override
   public View onCreateView(LayoutInflater pInflater, ViewGroup pContainer,
         Bundle pSavedInstanceState) {            
      Point size = new Point();
      getActivity().getWindowManager().getDefaultDisplay().getSize(size);
      //final int screenHeight = size.y*4;
      final int screenHeight = size.y;

      //final int boardHeight = (int)((float)screenHeight * (2.0f/7.0f));
      //final int boardWidth = (int)((float)screenHeight * (5.0f/7.0f));
      //int villageSize = (int)((float)screenHeight * (3.0f/7.0f));
      
      final int boardHeight = (int)((float)screenHeight * (13.0f/56.0f));
      final int boardWidth = (int)((float)screenHeight * (43.0f/56.0f));
      int villageSize = (int)((float)screenHeight * (30.0f/56.0f));
      
      GridLayout gridLayout = new GridLayout(getActivity());
      gridLayout.setClipChildren(false);
      gridLayout.setColumnCount(sNumCols);
      gridLayout.setColumnCount(sNumRows);
           
      //1280x752      Log.d("GameboardFragment", "screenHeight = " + screenHeight);
      Log.d("GameboardFragment", "screenWidth = " + size.x);
      GhostStoriesGameManager gm = GhostStoriesGameManager.getInstance();
      
      /*
      createPlayerArea(pInflater, pContainer, gridLayout, R.layout.top_player_area, 
            GridLayout.spec(0, 2), GridLayout.spec(0, 5), boardWidth, boardHeight,
            gm.getGameBoard(EBoardLocation.TOP));
      createPlayerArea(pInflater, pContainer, gridLayout, R.layout.left_player_area,
            GridLayout.spec(2, 5), GridLayout.spec(0, 2), boardHeight, boardWidth,
            gm.getGameBoard(EBoardLocation.LEFT));
      createPlayerArea(pInflater, pContainer, gridLayout, R.layout.right_player_area, 
            GridLayout.spec(0, 5), GridLayout.spec(5, 2), boardHeight, boardWidth,
            gm.getGameBoard(EBoardLocation.RIGHT));
      createPlayerArea(pInflater, pContainer, gridLayout, R.layout.bottom_player_area, 
            GridLayout.spec(5, 2), GridLayout.spec(2, 5), boardWidth, boardHeight,
            gm.getGameBoard(EBoardLocation.BOTTOM));      
      createVillageArea(pInflater, pContainer, gridLayout, R.layout.village, 
            GridLayout.spec(2, 3), GridLayout.spec(2, 3), villageSize, villageSize);
      */
      
      createVillageArea(pInflater, pContainer, gridLayout, R.layout.village, 
            GridLayout.spec(13, 30), GridLayout.spec(13, 30), villageSize, villageSize);
      createPlayerArea(pInflater, pContainer, gridLayout, R.layout.top_player_area, 
            GridLayout.spec(0, 13), GridLayout.spec(0, 43), boardWidth, boardHeight,
            gm.getGameBoard(EBoardLocation.TOP));
      createPlayerArea(pInflater, pContainer, gridLayout, R.layout.left_player_area,
            GridLayout.spec(13, 43), GridLayout.spec(0, 13), boardHeight, boardWidth,
            gm.getGameBoard(EBoardLocation.LEFT));
      createPlayerArea(pInflater, pContainer, gridLayout, R.layout.right_player_area, 
            GridLayout.spec(0, 43), GridLayout.spec(43, 13), boardHeight, boardWidth,
            gm.getGameBoard(EBoardLocation.RIGHT));
      createPlayerArea(pInflater, pContainer, gridLayout, R.layout.bottom_player_area, 
            GridLayout.spec(43, 13), GridLayout.spec(13, 43), boardWidth, boardHeight,
            gm.getGameBoard(EBoardLocation.BOTTOM));      
      
      //Set the game board graphics
      initGameBoards(gridLayout);
      
      //Set the village tile graphics
      initVillageTiles(gridLayout);
      
      //Setup the player token areas
      initPlayerTokenAreas(gridLayout);         
      
      return gridLayout;
   }
   
   private void createPlayerArea(LayoutInflater pInflater, ViewGroup pContainer, 
         GridLayout pLayout, int pPlayerAreaId, Spec pRowSpec, Spec pColSpec, 
         int pWidth, int pHeight, GameBoardData pData) {
      PlayerAreaView view = 
            (PlayerAreaView)pInflater.inflate(pPlayerAreaId, pContainer, false);
      GridLayout.LayoutParams parms = 
            new GridLayout.LayoutParams(pRowSpec, pColSpec);
      parms.width = pWidth;
      parms.height = pHeight;
      view.setLayoutParams(parms);      
      pLayout.addView(view, parms);
      view.setGameBoardData(pData);
   }
   
   private void createVillageArea(LayoutInflater pInflater, ViewGroup pContainer,
         GridLayout pLayout, int pVillageAreaId, Spec pRowSpec, Spec pColSpec,
         int pWidth, int pHeight) {
      View view = pInflater.inflate(pVillageAreaId, pContainer, false);
      GridLayout.LayoutParams parms = 
            new GridLayout.LayoutParams(pRowSpec, pColSpec);
      parms.width = pWidth;
      parms.height = pHeight;
      view.setLayoutParams(parms);
      pLayout.addView(view, parms);
   }
   
   /**
    * Initialize the game board views
    * @param pView The parent view
    */
   private void initGameBoards(View pView) {      
      Map<EColor, GameBoardData> gameBoards =
            GhostStoriesGameManager.getInstance().getGameBoards();
      for(GameBoardData gb : gameBoards.values()) {
         PlayerBoardView board = 
               (PlayerBoardView)pView.findViewById(gb.getLocation().getBoardId());
         board.setGameBoardData(gb);   
         for(ECardLocation cardLoc : ECardLocation.values()) {
            PlayerBoardCardView view = (PlayerBoardCardView)board.findViewById(
                  cardLoc.getCardLocationId());
            view.setGameBoardData(gb);            
            new PlayerBoardCardController(gb, view, cardLoc);
         }                  
      }     
      new HaunterController();
   }
   
   /**
    * Initialize the player token area views
    * @param pView The parent view
    */
   private void initPlayerTokenAreas(View pView) {
      for(EColor color : EColor.getPlayerColors()) {
         PlayerData pd = 
               GhostStoriesGameManager.getInstance().getPlayerData(color);
         PlayerTokenAreaView view = (PlayerTokenAreaView)pView.findViewById(
               pd.getBoardLocation().getTokenAreaId());
         view.setPlayerData(pd);
      }
   }
   
   /**
    * Initialize the village tile views
    * @param pView The parent view
    */
   private void initVillageTiles(View pView) {
      Map<ETileLocation, VillageTileData> villageTiles = 
            GhostStoriesGameManager.getInstance().getVillageTiles();
      for(VillageTileData tileData : villageTiles.values()) {
         VillageTileView tileView = 
               (VillageTileView)pView.findViewById(tileData.getLocation().getLayoutId());
         tileData.setViewId(tileView.getId());         
         tileView.setVillageTileData(tileData);
         new VillageTileController(tileData, tileView);
      }
      
   }
   
   //private static final int sNumRows = 7;
   //private static final int sNumCols = 7;
   
   private static final int sNumRows = 56;
   private static final int sNumCols = 56;
}




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