コード例 #1
0
        public void makeMove(object sender, EventArgs e)
        {
            Move         currentMove = sender as Move;
            SquareButton toButton    = Squares[currentMove.ToSquare.Row, currentMove.ToSquare.Column];
            SquareButton fromButton  = Squares[currentMove.FromSquare.Row, currentMove.FromSquare.Column];
            Square       fromSquare  = currentMove.FromSquare;
            Square       toSquare    = currentMove.ToSquare;

            if (currentMove.MoveType == GameLogic.Move.eTypeOfMove.Jump)
            {
                int captureRow    = fromButton.Row > toButton.Row ? fromButton.Row - 1 : fromButton.Row + 1;
                int captureColumn = fromButton.Column > toButton.Column ? fromButton.Column - 1 : fromButton.Column + 1;
                Squares[captureRow, captureColumn].Text = " ";
            }

            if (fromSquare.Type == Square.eSquareType.X && toSquare.Row == 0)
            {
                toButton.Text = "K";
            }
            else
            {
                if ((fromSquare.Type == Square.eSquareType.O) && toSquare.Row == m_Size - 1)
                {
                    toButton.Text = "U";
                }
                else
                {
                    toButton.Text = fromButton.Text;
                }
            }

            fromButton.Text = Square.ToStringSqureType(Square.eSquareType.None);
        }
コード例 #2
0
        public void button_Click(Object sender, EventArgs e)
        {
            SquareButton button = (SquareButton)sender;
            int          row    = button.Row;
            int          col    = button.Column;

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

            if (CurrentMove.FromSquare == null)
            {
                button.BackColor       = Color.AliceBlue;
                CurrentMove.FromSquare = new Square(row, col);
            }
            else
            {
                if (CurrentMove.FromSquare.Row == row && CurrentMove.FromSquare.Column == col)
                {
                    button.BackColor       = Color.White;
                    CurrentMove.FromSquare = null;
                }
                else
                {
                    CurrentMove.ToSquare = new Square(row, col);
                }
            }

            if ((CurrentMove.FromSquare != null) && (CurrentMove.ToSquare != null))
            {
                m_Game.gameRound(CurrentMove);
                Squares[CurrentMove.FromSquare.Row, CurrentMove.FromSquare.Column].BackColor = Color.White;
                CurrentMove.FromSquare = null;
                CurrentMove.ToSquare   = null;
                CurrentMove            = null;
            }
        }
コード例 #3
0
        internal void InitBoard()
        {
            for (int i = 0; i < this.m_Size; i++)
            {
                for (int j = 0; j < this.m_Size; j++)
                {
                    if (i % 2 == 1)
                    {
                        if (j % 2 == 0)
                        {
                            m_Squares[i, j]           = new SquareButton(Square.eSquareType.None, i, j);
                            m_Squares[i, j].BackColor = Color.White;
                            int yLocation = i * 50 + 50;
                            int xLocation = j * 50 - 4;
                            m_Squares[i, j].Location = new Point(xLocation, yLocation);
                            m_Squares[i, j].Click   += new System.EventHandler(button_Click);
                            Controls.Add(m_Squares[i, j]);
                        }
                        else
                        {
                            m_Squares[i, j]           = new SquareButton(Square.eSquareType.None, i, j);
                            m_Squares[i, j].Enabled   = false;
                            m_Squares[i, j].BackColor = Color.Gray;
                            int yLocation = i * 50 + 50;
                            int xLocation = j * 50 - 4;
                            m_Squares[i, j].Location = new Point(xLocation, yLocation);
                            Controls.Add(m_Squares[i, j]);
                        }
                    }
                    else
                    {
                        if (j % 2 == 1)
                        {
                            m_Squares[i, j]           = new SquareButton(Square.eSquareType.None, i, j);
                            m_Squares[i, j].BackColor = Color.White;
                            int yLocation = i * 50 + 50;
                            int xLocation = j * 50 - 4;
                            m_Squares[i, j].Location = new Point(xLocation, yLocation);
                            m_Squares[i, j].Click   += new System.EventHandler(button_Click);
                            Controls.Add(m_Squares[i, j]);
                        }
                        else
                        {
                            m_Squares[i, j]           = new SquareButton(Square.eSquareType.None, i, j);
                            m_Squares[i, j].Enabled   = false;
                            m_Squares[i, j].BackColor = Color.Gray;
                            int yLocation = i * 50 + 50;
                            int xLocation = j * 50 - 4;
                            m_Squares[i, j].Location = new Point(xLocation, yLocation);
                            Controls.Add(m_Squares[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)
                        {
                            m_Squares[i, j].Type = Square.eSquareType.O;
                            m_Squares[i, j].Text = "O";
                        }
                    }
                    else
                    {
                        if (j % 2 == 1)
                        {
                            m_Squares[i, j].Type = Square.eSquareType.O;
                            m_Squares[i, j].Text = "O";
                        }
                    }
                }
            }

            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)
                        {
                            m_Squares[i, j].Type = Square.eSquareType.X;
                            m_Squares[i, j].Text = "X";
                        }
                    }
                    else
                    {
                        if (j % 2 == 1)
                        {
                            m_Squares[i, j].Type = Square.eSquareType.X;
                            m_Squares[i, j].Text = "X";
                        }
                    }
                }
            }
        }