예제 #1
0
        static void Main(string[] args)
        {
            var boardModel = new BoardModel();

            BoardView.ShowBoard(boardModel);

            foreach (var c in boardModel.BoxContents)
            {
                Console.WriteLine(c);
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            _brett   = new BoardModel();
            _visning = new BoardView(_brett);
            var  finished = false;
            bool ai;
            Tuple <bool, char> result = new Tuple <bool, char>(false, ' ');

            Console.WriteLine("Play against the computer? (Y/N):");
            while (true)
            {
                var userSelect = Console.ReadLine();
                if (userSelect == "y" || userSelect == "Y")
                {
                    ai = true;
                    break;
                }
                if (userSelect == "n" || userSelect == "N")
                {
                    ai = false;
                    break;
                }
            }

            _visning.Show();
            while (!finished)
            {
                var selectX = false;
                var selectY = false;
                while (!selectX)
                {
                    if (!AddChar('x'))
                    {
                        continue;
                    }
                    result   = IsGameOver(_brett);
                    finished = result.Item1;
                    _visning.Show();
                    selectX = true;
                }

                while (!selectY)
                {
                    if (!ai)
                    {
                        if (!AddChar('o'))
                        {
                            continue;
                        }
                        result   = IsGameOver(_brett);
                        finished = result.Item1;
                        _visning.Show();
                        selectY = true;
                    }
                    else
                    {
                        selectY  = SetRandomO();
                        result   = IsGameOver(_brett);
                        finished = result.Item1;
                        _visning.Show();
                    }
                }
            }
            Console.WriteLine($"Game over! Winner is: {result.Item2}");
        }