コード例 #1
0
ファイル: Board.cs プロジェクト: lebull/CheckEye
 /// <summary>
 /// Returns the BoardSquare at this position.  Returns null if the position isn't on the board.
 /// </summary>
 /// <param name="pos"></param>
 /// <returns></returns>
 public BoardSquare getSquare(BoardPosition pos)
 {
     if(!pos.inBoard)
     {
         return null;
     }
     return squareGrid[pos.horizontal, pos.vertical].GetComponent<BoardSquare>();
 }
コード例 #2
0
ファイル: BoardMove.cs プロジェクト: lebull/CheckEye
        public BoardMove(BoardPiece movingPiece, 
                                BoardPosition destination,
                                List<BoardPiece> destroyedPieces = null, 
                                BoardPiece transformTo = null)
        {
            this.movingPiece = movingPiece;
            this.destination = destination;
            this.transformTo = transformTo;

            if (destroyedPieces == null)
            {
                this.destroyedPieces = new List<BoardPiece>();
            }
            else
            {
                this.destroyedPieces = destroyedPieces;
            }
        }
コード例 #3
0
ファイル: Board.cs プロジェクト: lebull/CheckEye
        public List<BoardPiece> allPieces()
        {
            List<BoardPiece> returnList = new List<BoardPiece>();
            for (int horz = 0; horz < GRIDSIZE; horz++)
            {
                for (int vert = 0; vert < GRIDSIZE; vert++)
                {
                    BoardPosition boardPosition = new BoardPosition(horz, vert);
                    if (getSquare(boardPosition).occupied)
                    {
                        returnList.Add(getSquare(boardPosition).gamePiece);
                    }

                }
            }

            return returnList;
        }
コード例 #4
0
ファイル: BoardSquare.cs プロジェクト: lebull/CheckEye
 //TODO: This should move the piece if it already has a nonequivilant boardPosition
 public void setBoardPosition(BoardPosition pos)
 {
     _boardPosition = pos;
     string newName = string.Format("BoardSquare ({0}, {1})", pos.horizontal, pos.vertical);
     transform.name = newName;
 }
コード例 #5
0
ファイル: Board.cs プロジェクト: lebull/CheckEye
 /// <summary>
 /// Returns true if the square has a gamepiece.
 /// </summary>
 /// <param name="pos"></param>
 /// <returns></returns>
 public bool isPositionIsOccupied(BoardPosition pos)
 {
     if (!pos.inBoard)
     {
         return false;
     }
     return getSquare(pos).occupied;
 }
コード例 #6
0
ファイル: Board.cs プロジェクト: lebull/CheckEye
        private void spawnBoardSquares()
        {
            //Spawn boardSquares.
            //GameObject blackSquarePrefab = Resources.Load<GameObject>("Prefabs/BlackSquare");
            //GameObject whiteSquarePrefab = Resources.Load<GameObject>("Prefabs/WhiteSquare");

            GameObject newSquarePrefab = new GameObject();
            newSquarePrefab.transform.localScale = new Vector3(1 / GRIDSIZE * PLANESCALE, 0.5f, 1 / GRIDSIZE * PLANESCALE);
            newSquarePrefab.AddComponent<BoardSquare>();
            newSquarePrefab.name = "BoardSquare";
            newSquarePrefab.AddComponent<BoxCollider>();
            newSquarePrefab.layer = LayerMask.NameToLayer("BoardSquare");

            squareGrid = new GameObject[GRIDSIZE, GRIDSIZE];

            //Spawn our grid
            float separation = squarewidth;
            Vector3 squareScale = new Vector3(
                separation,
                newSquarePrefab.transform.localScale.y * transform.localScale.y,
                separation
                );

            //1 to 8
            for (int vertical_index = 0; vertical_index < GRIDSIZE; vertical_index++)
            {
                //a to h
                for (int horizontal_index = 0; horizontal_index < GRIDSIZE; horizontal_index++)
                {
                    //This should be local to this.transform
                    Vector3 spawnPosition = new Vector3(
                        (horizontal_index - (GRIDSIZE / 2)) * separation + separation / 2,
                        0,
                        (vertical_index - (GRIDSIZE / 2)) * separation + separation / 2
                        );

                    GameObject newSquare = (GameObject)Instantiate(newSquarePrefab, transform.position + spawnPosition, transform.rotation);
                    squareGrid[horizontal_index, vertical_index] = newSquare;
                    BoardPosition newBoardPosition = new BoardPosition(horizontal_index, vertical_index);
                    newSquare.transform.localScale = squareScale;
                    newSquare.transform.parent = transform;
                    newSquare.GetComponent<BoardSquare>().setBoardPosition(newBoardPosition);
                }
            }
        }