예제 #1
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);
        }
예제 #2
0
        static void TestTask3()
        {
            Console.WriteLine("task 3d");
            Board  board = new Board(6, 7);
            Player p1    = new Player("Clive", 'o');
            Player p2    = new Player("Sharon", 'x');

            board.Add(new Counter(p2), 6);
            board.Add(new Counter(p1), 3);
            board.Add(new Counter(p2), 4);
            board.Add(new Counter(p1), 4);
            board.Add(new Counter(p2), 5);
            board.Add(new Counter(p1), 5);
            board.Add(new Counter(p2), 6);
            board.Add(new Counter(p1), 5);
            board.Add(new Counter(p2), 6);
            board.Add(new Counter(p1), 6);

            board.Display();
            Console.WriteLine(board.IsFull());
        }