private void RestartGameCommandHandle(object obj) { _cells .SelectMany(cells => cells) .ToList() .ForEach(cell => cell.SetPiece(EChessPieceType.Empty, EChessPieceColor.Empty)); _gameLogic.StartGame(); _activePlayer = _gameLogic.ActivePlayer; }
private void nextTurn() { if (_activePlayer == EActivePlayer.White) { _activePlayer = EActivePlayer.Black; } else { _activePlayer = EActivePlayer.White; } }
private EConnectFourCellContent playerToColorConverter(EActivePlayer player) { if (player == EActivePlayer.Black) { return(EConnectFourCellContent.Black); } else { return(EConnectFourCellContent.White); } }
public void StartGame() { _chessboard.InitializeBoard(); _activePlayer = EActivePlayer.White; }
public GameEndedEventArgs(EActivePlayer winner) { Winner = winner; }
private void _gameLogic_GameFinished(object sender, GameEndedEventArgs e) { Winner = e.Winner; IsGameFinished = true; Task.Delay(2000).ContinueWith((x) => { IsGameFinished = false; }); }
private void Cell_CellSelected(object sender, CellId selectedCellIdentifier) { if (_isGameFinished) { return; } // If an empty cell or a cell of the opponent color was selected // unselect the previous cell. // var cell = fetchCell(selectedCellIdentifier); if (_isPieceSelected == true) // The user previously selected a valid piece. { if (_gameLogic.IsValidMove(_selectedPiece.Identifier, selectedCellIdentifier)) { _gameLogic.MovePiece(_selectedPiece.Identifier, selectedCellIdentifier); unselectAllCells(); clearValidMoves(); _isPieceSelected = false; ActivePlayer = _gameLogic.ActivePlayer; } else { // It is not a valid move. If another valid piece was selected change the selection. // if (!cell.IsEmpty) { if (ActivePlayer == EActivePlayer.Black && cell.ChessPieceColor == EChessPieceColor.Black || ActivePlayer == EActivePlayer.White && cell.ChessPieceColor == EChessPieceColor.White) { unselectAllCells(); clearValidMoves(); _selectedPiece = cell; _selectedPiece.IsCellSelected = true; displayValidMovesForPiece(_selectedPiece); } } } } if (_isPieceSelected == false) // We have no selected piece. { if (cell.IsEmpty) // Nothing to do here { return; } // Check the user selected a valid piece. // if (_gameLogic.ActivePlayer == EActivePlayer.White && cell.ChessPieceColor == EChessPieceColor.White || _gameLogic.ActivePlayer == EActivePlayer.Black && cell.ChessPieceColor == EChessPieceColor.Black) { _selectedPiece = cell; _selectedPiece.IsCellSelected = true; _isPieceSelected = true; displayValidMovesForPiece(_selectedPiece); } // User selected a an invalid piece. // else { return; } } }