示例#1
0
        public void ChangeStatusCell(object parameter)
        {
            if (parameter.GetType() != typeof(CellViewModel))
            {
                throw new ArgumentException("parameter");
            }

            CellViewModel cell = parameter as CellViewModel;

            if (cell.Status == CellStatus.Empty)
            {
                SetStatusCell(cell);
                lastUsedCell = cell;

                if (IsGameOver(Cells))
                {
                    System.Windows.MessageBox.Show("Игра окончена");
                    ResetAllStatus();
                }
                else if (IsDraw(Cells))
                {
                    System.Windows.MessageBox.Show("Ничья");
                    ResetAllStatus();
                }
            }
            else
            {
                if (cell == lastUsedCell)
                {
                    cell.Status = CellStatus.Empty;
                    GameStatus  = (GameStatus == GameStatus.Cross) ? GameStatus.Zero : GameStatus.Cross;
                }
            }
        }
示例#2
0
        private void InitializationCells()
        {
            Cell1 = new CellViewModel();
            Cell2 = new CellViewModel();
            Cell3 = new CellViewModel();

            Cell4 = new CellViewModel();
            Cell5 = new CellViewModel();
            Cell6 = new CellViewModel();

            Cell7 = new CellViewModel();
            Cell8 = new CellViewModel();
            Cell9 = new CellViewModel();

            Cells = new CellViewModel[, ]
            {
                {
                    Cell1,
                    Cell2,
                    Cell3
                },
                {
                    Cell4,
                    Cell5,
                    Cell6
                },
                {
                    Cell7,
                    Cell8,
                    Cell9
                }
            };
        }
示例#3
0
        private bool IsDraw(CellViewModel[,] cells)
        {
            bool result = true;

            for (int i = 0; i < cells.GetLength(0); i++)
            {
                for (int j = 0; j < cells.GetLength(0); j++)
                {
                    CellViewModel cell = cells[i, j];
                    if (cell.Status == CellStatus.Empty)
                    {
                        result = false;
                        break;
                    }
                }
            }
            return(result);
        }
示例#4
0
        private void SetStatusCell(CellViewModel cell)
        {
            switch (GameStatus)
            {
            case GameStatus.Cross:
                if (cell.Status == CellStatus.Empty)
                {
                    cell.Status = CellStatus.Cross;
                }
                GameStatus = GameStatus.Zero;
                break;

            case GameStatus.Zero:
                if (cell.Status == CellStatus.Empty)
                {
                    cell.Status = CellStatus.Zero;
                }
                GameStatus = GameStatus.Cross;
                break;
            }
        }