예제 #1
0
        public void InitializeComponent()
        {
            int  boardSize  = 2;
            bool evenRow    = true;
            bool evenColumn = true;

            initBoardSettings(boardSize);
            this.r_GameLogic.ReportGameError += this.showErrorDialog;
            this.r_GameLogic.GameEnded       += this.gameEnded;
            Point buttonLocation = new Point(k_SpaceSize + 10, k_SpaceSize + (r_Player1Score.Height * 2));

            for (int i = 0; i < r_BoardDimensions; i++)
            {
                for (int j = 0; j < r_BoardDimensions; j++)
                {
                    bool       buttonEnable = evenColumn != evenRow;
                    PawnButton pawnButton   = new PawnButton(i, j, this.r_GameLogic.Board[i, j], buttonEnable);
                    pawnButton.Click += this.pawnButton_Click;
                    this.r_GameLogic.AddListenerToGameObject(i, j, pawnButton.OnChange);
                    pawnButton.Size     = r_ButtonSize;
                    pawnButton.Location = buttonLocation;
                    buttonLocation.X   += r_ButtonSize.Width;

                    this.Controls.Add(pawnButton);
                    evenColumn = !evenColumn;
                }

                buttonLocation.X  = k_SpaceSize + 10;
                buttonLocation.Y += r_ButtonSize.Height;
                evenRow           = !evenRow;
            }
        }
예제 #2
0
        private void pawnButton_Click(object sender, EventArgs e)
        {
            PawnButton    pawnButton                 = sender as PawnButton;
            List <string> currentPlayerSymbols       = this.r_GameLogic.GetCurrentPlayerSymbol();
            bool          isCurrentSymbolMatchButton = false;

            if (pawnButton != null)
            {
                foreach (string symbol in currentPlayerSymbols)
                {
                    if (symbol == pawnButton.Text)
                    {
                        isCurrentSymbolMatchButton = true;
                    }
                }

                if (this.m_SelectedPawn == null && isCurrentSymbolMatchButton)
                {
                    this.m_SelectedPawn = pawnButton;
                    this.m_SelectedPawn.PawnSelectedToggle();
                }
                else if (this.m_SelectedPawn != null && this.m_SelectedPawn == pawnButton)
                {
                    this.m_SelectedPawn.PawnSelectedToggle();
                    this.m_SelectedPawn = null;
                }
                else if (this.m_SelectedPawn != null && pawnButton.Text == ((char)eTeam.Empty).ToString())
                {
                    this.r_GameLogic.MakeMove(
                        this.m_SelectedPawn.Row,
                        this.m_SelectedPawn.Col,
                        pawnButton.Row,
                        pawnButton.Col);
                    this.m_SelectedPawn.PawnSelectedToggle();
                    this.m_SelectedPawn = null;
                }
            }
        }