public static void VictoryFlash(Board board, Dictionary <int, int> winningMoveValues, bool playerOnesTurn) { var winningPositions = winningMoveValues.Select(positionValue => new BoardPosition(positionValue.Key, positionValue.Value)) .ToList(); for (int i = 0; i < 6; i++) { foreach (var position in winningPositions) { if (playerOnesTurn) { ReplaceHistory(board.BoardHistory, position, CustomComparer.PositionHistoryCompare(board.BoardHistory, position, PositionHistory.Player1Piece) ? PositionHistory.Player1PieceHighlighted : PositionHistory.Player1Piece); } else { ReplaceHistory(board.BoardHistory, position, CustomComparer.PositionHistoryCompare(board.BoardHistory, position, PositionHistory.Player2Piece) ? PositionHistory.Player2PieceHighlighted : PositionHistory.Player2Piece); } } BoardUI.DisplayGameBoard(board); System.Threading.Thread.Sleep(300); Console.Clear(); } BoardUI.DisplayGameBoard(board); }
public static void PieceDrop(Board board, BoardPosition position, bool isPlayerOnesTurn) { var history = PositionHistory.Player2Piece; if (isPlayerOnesTurn) { history = PositionHistory.Player1Piece; } for (int i = 6; i > position.RowPosition; i--) { var fallingPiece = new BoardPosition(i, position.ColumnPosition); ReplaceHistory(board.BoardHistory, fallingPiece, history); BoardUI.DisplayGameBoard(board); System.Threading.Thread.Sleep(100); ReplaceHistory(board.BoardHistory, fallingPiece, PositionHistory.Empty); Console.Clear(); } }
private void TakeTurn(string currentPlayerName) // only need a name, only one board. turn bool is global { string columnInput; bool inputIsValid; do { BoardUI.DisplayGameBoard(_model.GameBoard); Console.WriteLine(); Console.Write("{0}, select a column : ", currentPlayerName); columnInput = Console.ReadLine(); inputIsValid = IsValidColumnInput(columnInput); Console.Clear(); if (!inputIsValid) { Console.WriteLine("That is not a valid column!"); Console.WriteLine("Press enter to try again"); Console.ReadLine(); Console.Clear(); } } while (!inputIsValid); var column = int.Parse(columnInput); var response = _model.GameBoard.PlaceGamePiece(column, _isPlayerOnesTurn); switch (response.PositionStatus) { case PositionStatus.Invalid: Console.WriteLine("Invalid input! (Press enter)"); Console.ReadLine(); Console.Clear(); break; case PositionStatus.ColumnFull: Console.WriteLine("That column is full! Choose again (Press enter)"); Console.ReadLine(); Console.Clear(); break; case PositionStatus.Ok: Animations.PieceDrop(_model.GameBoard, response.BoardPosition, _isPlayerOnesTurn); _model.GameBoard.AddPieceToBoard(response.BoardPosition, _isPlayerOnesTurn); if (_isPlayerOnesTurn) { _isPlayerOnesTurn = false; } else if (!_isPlayerOnesTurn) { _isPlayerOnesTurn = true; } break; case PositionStatus.WinningMove: Animations.PieceDrop(_model.GameBoard, response.BoardPosition, _isPlayerOnesTurn); _model.GameBoard.AddPieceToBoard(response.BoardPosition, _isPlayerOnesTurn); BoardUI.DisplayGameBoard(_model.GameBoard); Console.WriteLine(); Console.Clear(); if (_isPlayerOnesTurn) { Animations.VictoryFlash(_model.GameBoard, response.WinningPositionValues, _isPlayerOnesTurn); Console.WriteLine(); Console.WriteLine("Congratulations {0}, you won!!", _model.Player1Name); Console.WriteLine("Press Enter"); Console.ReadLine(); Console.Clear(); _gameOver = true; } else if (!_isPlayerOnesTurn) { Animations.VictoryFlash(_model.GameBoard, response.WinningPositionValues, _isPlayerOnesTurn); Console.WriteLine(); Console.WriteLine("Congratulations {0}, you won!!", _model.Player2Name); Console.WriteLine("Press Enter"); Console.ReadLine(); Console.Clear(); _gameOver = true; } break; default: Console.WriteLine("Invalid input! (Press enter)"); Console.ReadLine(); Console.Clear(); break; } }