예제 #1
0
        /// <summary>
        /// Tests the Initialize method for correct input
        /// Expected einitialized cells with correct colors, white colour goes first
        /// </summary>        [TestMethod()]
        public void InitializeTest_CorrectInputWhiteFirst_ReturnedInitializedCellsWithCorrectColors()
        {
            // Arrange
            int width  = 2;
            int height = 3;

            ICell[,] expectedCells =
            {
                { new ChessCell(Colors.White), new ChessCell(Colors.Black), new ChessCell(Colors.White) },
                { new ChessCell(Colors.Black), new ChessCell(Colors.White), new ChessCell(Colors.Black) },
                { new ChessCell(Colors.White), new ChessCell(Colors.Black), new ChessCell(Colors.White) },
            };
            ICell[,] actualCells = new ChessCell[width, height];

            // Act
            ICellInitializer initializer = new ChessBoardCellInitializer(true);

            initializer.Initialize(actualCells);

            // Assert
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    Assert.AreEqual(expectedCells[i, j].Colour, actualCells[i, j].Colour);
                }
            }
        }
예제 #2
0
 public void Move(ChessCell _targetCell, ChessCell _originalCell)
 {
     if (_targetCell.ChessPiece != null)
     {
         _targetCell.ChessPiece.Kill();
     }
     _targetCell.ChessPiece   = this;
     _originalCell.ChessPiece = null;
     transform.SetParent(_targetCell.transform);
     transform.localPosition = Vector3.zero;
 }
예제 #3
0
 private void OnMoveSuccess(object _data)
 {
     PieceMoveData[] pieceMoveData = JsonConvert.DeserializeObject <PieceMoveData[]>(_data.ToString());
     for (int i = 0; i < pieceMoveData.Length; i++)
     {
         ChessCell targetCell   = ChessBoard.GetChessCellByPosition(pieceMoveData[i].X, pieceMoveData[i].Y);
         ChessCell originalCell = ChessBoard.GetChessCellByChessPieceId(pieceMoveData[i].Id);
         ChessPieceManager.MovePiece(pieceMoveData[i].Id, targetCell, originalCell);
     }
     IsMyTurn = !IsMyTurn;
     TurnInfoUpdate();
 }
예제 #4
0
        public void CellInitializationTest()
        {
            //Arrange
            Colors expectedColour = Colors.Black;
            ICell  actualCell;

            // Act
            actualCell = new ChessCell(Colors.Black);

            //Assert
            Assert.AreEqual(expectedColour, actualCell.Colour);
        }
예제 #5
0
    private void OnCellClicked(object _data)
    {
        BasePieceGO selectedChessPiece = ChessPieceManager.GetSelectedPiece();

        if (selectedChessPiece == null)
        {
            return;
        }

        ChessCell chessCell = _data as ChessCell;

        selectedChessPiece.TryMove(chessCell.x, chessCell.y, GameId);
    }
예제 #6
0
    private IEnumerator MakeMove(ChessPieceManager _Pmanager, ChessBoard _Bmanager, GameHistory _gameHistory)
    {
        foreach (PieceMoveData move in _gameHistory.MoveHistory)
        {
            yield return(new WaitForSeconds(2));

            ChessCell targetCell   = _Bmanager.GetChessCellByPosition(move.X, move.Y);
            ChessCell originalCell = _Bmanager.GetChessCellByChessPieceId(move.Id);
            _Pmanager.MovePiece(move.Id, targetCell, originalCell);
        }

        yield return(new WaitForSeconds(2));

        GameEnd.SetMessageComponent("Replay over");
        GameEnd.SetActionMessageType(MessageType.OpenGameMenu);
        GameEnd.Activate();
    }
예제 #7
0
        private void h_RefreshField()
        {
            for (int iX = 0; iX < _chb.Width; iX++)
            {
                for (int iY = 0; iY < _chb.Height; iY++)
                {
                    ChessCell pCell = _chb.GetCell(iX, iY);
                    switch (pCell.Color)
                    {
                    case EColor.Black:
                        h_SetButtonBlack(iX, iY);
                        break;

                    case EColor.White:
                        h_SetButtonWhite(iX, iY);
                        break;
                    }
                }
            }
        }
예제 #8
0
    /// <summary>
    /// Uses Server Board data to create Chess Pieces on the Client board
    /// </summary>
    /// <param name="serverBoard"></param>
    /// <param name="clientBoard"></param>
    public void Initialize(BoardData serverBoard, ChessBoard clientBoard)
    {
        for (int i = 0; i < 8; i++)
        {
            for (int j = 0; j < 8; j++)
            {
                if (serverBoard.AllCells[i, j].ChessPiece != null)
                {
                    CellData  serverCell = serverBoard.AllCells[i, j];
                    ChessCell chessCell  = clientBoard.AllCells[i, j];

                    BasePieceGO basePieceGO = Instantiate(chessPiecesSO.ChessPieces[serverCell.ChessPiece.Type], chessCell.transform).GetComponent <BasePieceGO>();
                    basePieceGO.Initialize(serverCell.ChessPiece, this);

                    chessCell.ChessPiece = basePieceGO;
                    ActiveChessPieces.Add(basePieceGO);
                }
            }
        }
        Debug.Log("ChessPieces Initialized");
    }
예제 #9
0
 /// <summary>
 /// Initializes the specified cells with black and white colors
 /// </summary>
 /// <param name="cells">The array of cells</param>
 public void Initialize(ICell[,] cells)
 {
     if (this.isWhiteCellFirst == false)
     {
         for (int i = 0; i < cells.GetLength(0); i++)
         {
             for (int j = 0; j < cells.GetLength(1); j++)
             {
                 cells[i, j] = new ChessCell((Colors)((i + j) & 1));
             }
         }
     }
     else
     {
         for (int i = 0; i < cells.GetLength(0); i++)
         {
             for (int j = 0; j < cells.GetLength(1); j++)
             {
                 cells[i, j] = new ChessCell((Colors)(((i + j) & 1) ^ 1));
             }
         }
     }
 }
예제 #10
0
    public void MovePiece(int _id, ChessCell _targetCell, ChessCell _originalCell)
    {
        BasePieceGO basePieceGO = GetChessPieceById(_id);

        basePieceGO.Move(_targetCell, _originalCell);
    }
예제 #11
0
 public ChessPiece(ChessCell position)
 {
     this.Position = position;
 }
예제 #12
0
 public static IChessPiece GetKing(ChessCell position)
 {
     return new King(position);
 }
예제 #13
0
 public static IChessPiece GetPawn(ChessCell position)
 {
     return new Pawn(position);
 }