예제 #1
0
        public bool Move(GameGrid _gameGrid)
        {
            while (true)
            {
                Random randomSeed   = new Random();
                Random random       = new Random(randomSeed.Next());
                int    rownumber    = random.Next(0, 3);
                int    columnnumber = random.Next(0, 3);

                if (_gameGrid.Grid[columnnumber, rownumber].Content.ToString() == " ")
                {
                    _gameGrid.Grid[columnnumber, rownumber].Content   = "O";
                    _gameGrid.Grid[columnnumber, rownumber].IsEnabled = false;
                    return(_referee.CheckGrid(_gameGrid, "", Computer));
                }
            }
        }
예제 #2
0
        public bool CheckGrid(GameGrid gameGrid, string player, string computer)
        {
            _player   = player;
            _computer = computer;

            if (CompareThree(gameGrid.Grid[0, 0], gameGrid.Grid[0, 1], gameGrid.Grid[0, 2]))
            {
                return(true);
            }
            else if (CompareThree(gameGrid.Grid[0, 1], gameGrid.Grid[1, 1], gameGrid.Grid[2, 1]))
            {
                return(true);
            }
            else if (CompareThree(gameGrid.Grid[0, 2], gameGrid.Grid[1, 2], gameGrid.Grid[2, 2]))
            {
                return(true);
            }
            else if (CompareThree(gameGrid.Grid[0, 0], gameGrid.Grid[1, 0], gameGrid.Grid[2, 0]))
            {
                return(true);
            }
            else if (CompareThree(gameGrid.Grid[1, 0], gameGrid.Grid[1, 1], gameGrid.Grid[1, 2]))
            {
                return(true);
            }
            else if (CompareThree(gameGrid.Grid[2, 0], gameGrid.Grid[2, 1], gameGrid.Grid[2, 2]))
            {
                return(true);
            }
            else if (CompareThree(gameGrid.Grid[0, 0], gameGrid.Grid[1, 1], gameGrid.Grid[2, 2]))
            {
                return(true);
            }
            else if (CompareThree(gameGrid.Grid[2, 0], gameGrid.Grid[1, 1], gameGrid.Grid[0, 2]))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }