void setGameOverKeyState()
        {
            actions.Remove(Keys.Left);
            actions.Remove(Keys.Right);
            actions.Remove(Keys.Space);

            actions.Set(Keys.N, () =>
            {
                // starts a new game
                board.Clear();
                Winner          = Winner.None;
                NewChipNeeded   = true;
                desiredKeyState = KeyState.InGame;
            });
            currentKeyState = KeyState.GameOver;
        }
Example #2
0
        static Task Task4()
        {
            Console.Clear();
            var   numberOfColumns = 9;
            var   numberOfRows    = 9;
            Board board           = new Board(numberOfRows, numberOfColumns);

            Player p1 = new Player("Clive", 'O');
            Player p2 = new Player("Sharon", 'X');

            Random rnd = new Random();
            int    i   = 0;

            var winnerProvider = new WinnerProvider(board);

            while (true)
            {
                while (!board.IsFull())
                {
                    i++;
                    var randomColumn = rnd.Next(0, numberOfColumns);

                    var position = board.Add(i % 2 == 0 ? new Counter(p1) : new Counter(p2), randomColumn);
                    {
                        Thread.Sleep(TimeSpan.FromMilliseconds(25));
                    }
                    Console.WriteLine(string.Empty);
                    Console.Clear();
                    board.Display();
                    var winner = winnerProvider.Provide();
                    if (winner.IsWinner)
                    {
                        Console.WriteLine($"We have a winner!!! Congrats {winner.Player.Name}, '{winner.Player.Counter}' !!!");
                        break;
                    }
                }

                Console.WriteLine("Press enter to close...");
                Console.ReadLine();
                board.Clear();
            }
            return(Task.CompletedTask);
        }