Exemplo n.º 1
0
        public void initUIBoard(int i_BoardSize)
        {
            Point anchor = new Point(k_SquareSize / 2, k_SquareSize);

            m_BoardButtons = new BoardButton[i_BoardSize, i_BoardSize];

            for (int i = 0; i < i_BoardSize; i++)
            {
                for (int j = 0; j < i_BoardSize; j++)
                {
                    m_BoardButtons[i, j] = new BoardButton(i, j);
                    BoardButton currentButton = m_BoardButtons[i, j];

                    currentButton.Location = new Point(
                        anchor.X + (j * currentButton.Width),
                        anchor.Y + (i * currentButton.Height));

                    this.Controls.Add(currentButton);

                    currentButton.Click +=
                        new EventHandler(currentButton_Click);
                }
            }

            m_Engine.Checkers.Board.ClearLogicBoard();
            m_Engine.ResetGame();
        }
Exemplo n.º 2
0
        private void currentButton_Click(object sender, EventArgs e)
        {
            bool        enable = true;
            BoardButton button = sender as BoardButton;

            m_Engine.SourceCoordinate = button.Coordinate;

            if (button.Enabled)
            {
                // Unselect the current Coin
                if (m_Engine.SourceCoordinate.Equals(m_Engine.LastCoordinate))
                {
                    button.BackColor = Color.White;
                    ChangeAvailableCoordinatesColor(button, Color.White);
                    changeOtherCoinsAvailability(button, enable);
                    m_Engine.ResetCoordinates();
                }
                else
                {
                    if (m_Engine.LastCoordinate == null)
                    {
                        m_Engine.LastCoordinate = m_Engine.SourceCoordinate;
                        button.BackColor        = Color.LightBlue;
                        ChangeAvailableCoordinatesColor(button, Color.Chocolate);
                        changeOtherCoinsAvailability(button, !enable);
                    }
                    else
                    {
                        m_Engine.TargetCoordinate = button.Coordinate;

                        BoardButton sourceButton = getButtonFromBoard(m_Engine.LastCoordinate);
                        ChangeAvailableCoordinatesColor(sourceButton, Color.White);
                        changeOtherCoinsAvailability(sourceButton, enable);
                        sourceButton.BackColor = Color.White;

                        if (!m_Engine.GameOver() && !(m_Engine.CurrentPlayer is Computer))
                        {
                            MakeCurrentPlayerCoinsDisabled();
                            m_Engine.TakeMoveFromPlayer();
                            m_Engine.SwitchTurnsIfNecessary();
                            m_Engine.ResetCoordinates();
                        }

                        if (!m_Engine.GameOver() && m_Engine.CurrentPlayer is Computer)
                        {
                            MakeCurrentPlayerCoinsDisabled();
                            m_Engine.TakeMoveFromPlayer();
                            m_Engine.SwitchTurnsIfNecessary();
                            m_Engine.ResetCoordinates();
                            m_Engine.GameOver();
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        // $G$ CSS-013 (-5) Bad input variable name (should be in the form of i_PascalCased)
        private void changeOtherCoinsAvailability(
            BoardButton button,
            bool isEnable)
        {
            foreach (Coin coin in m_Engine.CurrentPlayer.CoinsList)
            {
                Coordinate coordinate = coin.Coordinates;

                if (!coordinate.Equals(button.Coordinate))
                {
                    getButtonFromBoard(coordinate).Enabled = isEnable;
                }
            }
        }
Exemplo n.º 4
0
        private void m_Engine_Board_SetCoinOnButton(object sender, EventArgs e)
        {
            Coin        coin   = sender as Coin;
            int         row    = coin.Coordinates.Row;
            int         col    = coin.Coordinates.Column;
            BoardButton button = m_BoardButtons[row, col];

            switch (coin.CoinType)
            {
            case (eCoinType.O):
                button.Enabled = true;
                if (coin.IsKing)
                {
                    button.BackgroundImage       = Properties.Resources.U;
                    button.BackgroundImageLayout = ImageLayout.Stretch;
                }
                else
                {
                    button.BackgroundImage       = Properties.Resources.O;
                    button.BackgroundImageLayout = ImageLayout.Stretch;
                }
                break;

            case (eCoinType.X):
                button.Enabled = false;
                if (coin.IsKing)
                {
                    button.BackgroundImage       = Properties.Resources.K;
                    button.BackgroundImageLayout = ImageLayout.Stretch;
                }
                else
                {
                    button.BackgroundImage       = Properties.Resources.X;
                    button.BackgroundImageLayout = ImageLayout.Stretch;
                }
                break;

            default:
                break;
            }
        }
Exemplo n.º 5
0
        private void ChangeAvailableCoordinatesColor(BoardButton i_Button, Color i_Color)
        {
            Coin coin = m_Engine.Checkers.GetCoinFromBoard(i_Button.Coordinate);

            if (coin != null)
            {
                foreach (Coordinate coordinate in coin.AvailableCoordinates)
                {
                    BoardButton currentButton = getButtonFromBoard(coordinate);

                    if (i_Color == Color.White)
                    {
                        currentButton.Enabled = false;
                    }
                    else
                    {
                        currentButton.Enabled = true;
                    }

                    currentButton.BackColor = i_Color;
                }
            }
        }