예제 #1
0
        public int SwitchPosition()
        {
            while (!WinChecker.HasWon(TokenType.Red) && !WinChecker.HasWon(TokenType.Black) && !Board.IsFull())
            {
                Console.Clear();
                Renderer.DrawHeader(_currentColumn, _currentType);
                Renderer.DrawBoard();
                var key = Console.ReadKey();
                if (key.Key != ConsoleKey.Enter)
                {
                    _currentColumn = key switch
                    {
                        { KeyChar : var k } when             k >= '1' && k <= '7' => k - '0' - 1,
                        { Key : ConsoleKey.LeftArrow } when  _currentColumn > 0 => _currentColumn - 1,
                        { Key : ConsoleKey.RightArrow } when _currentColumn < 6 => _currentColumn + 1,
                        var _ => _currentColumn,
                    };
                }
                else
                {
                    if (Board.CanAdd(_currentColumn))
                    {
                        Board.Add(_currentColumn, _currentType);
                        _currentType = _currentType == TokenType.Red ? TokenType.Black : TokenType.Red;
                    }
                }
            }

            return(_currentColumn);
        }
예제 #2
0
        public static void DrawHeader(int currentColumn, TokenType currentType)
        {
            var symbol = Board.CanAdd(currentColumn) ? "O" : "x";

            Console.ForegroundColor = currentType == TokenType.Red ? ConsoleColor.Red : ConsoleColor.DarkGray;
            Console.WriteLine("   {0} {1} {2} {3} {4} {5} {6}",
                              currentColumn == 0 ? symbol : " ",
                              currentColumn == 1 ? symbol : " ",
                              currentColumn == 2 ? symbol : " ",
                              currentColumn == 3 ? symbol : " ",
                              currentColumn == 4 ? symbol : " ",
                              currentColumn == 5 ? symbol : " ",
                              currentColumn == 6 ? symbol : " ");
        }