Пример #1
0
        private void _step(TTTCheckerButton button)
        {
            string sign = null;

            if (this._isPlayer1turn)
            {
                sign = PLAYER_1_SIGN;
            }
            else
            {
                sign = PLAYER_2_SIGN;
            }

            button.Text = sign;

            string resultIfNotNullOrEmpty = this._checkFieldsForVictory();

            if (!string.IsNullOrEmpty(resultIfNotNullOrEmpty))
            {
                /// megvan a gyoztes
                string winnerName = "";
                if (resultIfNotNullOrEmpty.Equals(PLAYER_1_SIGN))
                {
                    winnerName = this._player1name;
                }
                else
                {
                    winnerName = this._player2name;
                }

                this.WinnerButton.Text      = winnerName;
                this.WinnerButton.IsVisible = true;

                foreach (TTTCheckerButton item in this._buttonFieldList)
                {
                    if (item.IsClickingEnabled)
                    {
                        item.IsClickingEnabled = false;
                    }
                }

                return;
            }

            button.IsClickingEnabled = false;

            this._isPlayer1turn = !this._isPlayer1turn;
        }
Пример #2
0
        private void _initTheGrid()
        {
            this.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            this.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            this.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });

            this.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            this.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            this.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });

            this._isPlayer1turn = true;

            //this._buttonArray = new TTTCheckerButton[SIZE*SIZE][];

            this._buttonFieldList = new List <TTTCheckerButton>();
            for (int i = 0; i < SIZE; ++i)
            {
                for (int j = 0; j < SIZE; ++j)
                {
                    TTTCheckerButton button = new TTTCheckerButton(i, j);
                    button.Clicked += TTTCheckerButton_Clicked;
                    this._setElementGridPosition(button, i, j);
                    this._buttonFieldList.Add(button);

                    Grid.SetRow(button, i);
                    Grid.SetColumn(button, j);
                }
            }

            this.WinnerButton = new MyButton()
            {
                IsVisible = false
            };
        }