Example #1
0
        public void MakeMove(object sender, EventArgs e)
        {
            Move        currentMove   = sender as Move;
            PieceButton targetButton  = Pieces[currentMove.TargetPiece.Row, currentMove.TargetPiece.Column];
            PieceButton currentButton = Pieces[currentMove.CurrentPiece.Row, currentMove.CurrentPiece.Column];
            Piece       CurrentPiece  = currentMove.CurrentPiece;
            Piece       TargetPiece   = currentMove.TargetPiece;

            if (currentMove.MoveType == CheckerLogic.Move.eMoveType.Jump)
            {
                int captureRow    = currentButton.Row > targetButton.Row ? currentButton.Row - 1 : currentButton.Row + 1;
                int captureColumn = currentButton.Column > targetButton.Column ? currentButton.Column - 1 : currentButton.Column + 1;
                Pieces[captureRow, captureColumn].BackgroundImage = null;
            }

            if (CurrentPiece.Type == Piece.eSoliderType.X && TargetPiece.Row == 0)
            {
                targetButton.BackgroundImage = Image.FromFile("..\\..\\Resources\\blackking.png");
            }
            else
            {
                if ((CurrentPiece.Type == Piece.eSoliderType.O) && TargetPiece.Row == m_Size - 1)
                {
                    targetButton.BackgroundImage = Image.FromFile("..\\..\\Resources\\greyking.png");
                }
                else
                {
                    targetButton.BackgroundImage = currentButton.BackgroundImage;
                }
            }

            currentButton.BackgroundImage = null;
        }
Example #2
0
        public void button_Click(Object sender, EventArgs e)
        {
            PieceButton button = (PieceButton)sender;
            int         row    = button.Row;
            int         col    = button.Column;

            if (CurrentMove == null)
            {
                CurrentMove = new Move();
            }

            if (CurrentMove.CurrentPiece == null)
            {
                button.BackColor         = ColorTranslator.FromHtml("#5c7fa1");
                CurrentMove.CurrentPiece = new Piece(row, col);
            }
            else
            {
                if (CurrentMove.CurrentPiece.Row == row && CurrentMove.CurrentPiece.Column == col)
                {
                    button.BackColor         = Color.White;
                    CurrentMove.CurrentPiece = null;
                }
                else
                {
                    CurrentMove.TargetPiece = new Piece(row, col);
                }
            }

            if ((CurrentMove.CurrentPiece != null) && (CurrentMove.TargetPiece != null))
            {
                m_Game.GameRound(CurrentMove);
                Pieces[CurrentMove.CurrentPiece.Row, CurrentMove.CurrentPiece.Column].BackColor = Color.White;
                CurrentMove.CurrentPiece = null;
                CurrentMove.TargetPiece  = null;
                CurrentMove = null;
            }
        }
        internal void InitTable()
        {
            for (int i = 0; i < this.m_Size; i++)
            {
                for (int j = 0; j < this.m_Size; j++)
                {
                    m_Pieces[i, j] = new PieceButton(Piece.eSoliderType.Empty, i, j);
                    int yLocation = i * 50 + 50;
                    int xLocation = j * 50 - 4;
                    m_Pieces[i, j].Location = new Point(xLocation, yLocation);

                    if (i % 2 == 1)
                    {
                        if (j % 2 == 0)
                        {
                            TableEmptyPiece(i, j);
                        }
                        else
                        {
                            TableUnaccessiblePiece(i, j);
                        }
                    }
                    else
                    {
                        if (j % 2 == 1)
                        {
                            TableEmptyPiece(i, j);
                        }
                        else
                        {
                            TableUnaccessiblePiece(i, j);
                        }
                    }
                }
            }

            for (int i = 0; i < this.m_Size / 2 - 1; i++)
            {
                for (int j = 0; j < this.m_Size; j++)
                {
                    if (i % 2 == 1)
                    {
                        if (j % 2 == 0)
                        {
                            TableGreyPiece(i, j);
                        }
                    }
                    else
                    {
                        if (j % 2 == 1)
                        {
                            TableGreyPiece(i, j);
                        }
                    }
                }
            }

            for (int i = this.m_Size - 1; i > this.m_Size / 2; i--)
            {
                for (int j = 0; j < this.m_Size; j++)
                {
                    if (i % 2 == 1)
                    {
                        if (j % 2 == 0)
                        {
                            TableBlackPiece(i, j);
                        }
                    }
                    else
                    {
                        if (j % 2 == 1)
                        {
                            TableBlackPiece(i, j);
                        }
                    }
                }
            }
        }