Esempio n. 1
0
        private void playComputerMove(object i_Sender, EventArgs i_E)
        {
            string     computerMove = m_CurrentPlayer.ComputerPlayerMove(m_CurrentPlayer.PiecesThatMustCapture());
            int        left, top;
            PictureBox tileToMoveTo = new PictureBox();

            m_CurrentPosition = getPositionFromChars(computerMove[0], computerMove[1]);
            m_NewPlace        = getPositionFromChars(computerMove[3], computerMove[4]);
            convertBoardPositionToFormPosition(m_CurrentPosition, out top, out left);
            foreach (GamePieceUI piece in m_PlayerTwoPieces)
            {
                if ((piece.Left == left) && (piece.Top == top))
                {
                    GamePieceUIPieceTaken = piece;
                    break;
                }
            }

            convertBoardPositionToFormPosition(m_NewPlace, out top, out left);

            foreach (PictureBox piece in m_GameBoardGraphics)
            {
                if ((piece.Left == left) && (piece.Top == top))
                {
                    tileToMoveTo = piece;
                    break;
                }
            }

            playTurn(tileToMoveTo);
        }
Esempio n. 2
0
        private GamePieceUI initializePiecePictureBox(int i_Top, int i_Left, Image i_Img)
        {
            GamePieceUI picture = new GamePieceUI(i_Top, i_Left, i_Img);

            this.Controls.Add(picture);
            picture.BringToFront();
            picture.Click += new EventHandler(click_piece);

            return(picture);
        }
Esempio n. 3
0
        private void removePieceFromBoard(int i_Top, int i_Left, List <GamePieceUI> i_PieceToSearch)
        {
            GamePieceUI toRemove = null;

            foreach (GamePieceUI pic in i_PieceToSearch)
            {
                if ((pic.Top == i_Top) && (pic.Left == i_Left))
                {
                    toRemove = pic;
                    break;
                }
            }

            i_PieceToSearch.Remove(toRemove);
            this.Controls.Remove(toRemove);
        }
Esempio n. 4
0
        private void click_piece(object i_Sender, EventArgs i_E)
        {
            if (m_FirstTurnClick)
            {
                GamePieceUI   pieceChosen = i_Sender as GamePieceUI;
                BoardPosition position    = convertFormPositionToBoardPosition(pieceChosen);

                if (m_SamePieceCanCapture == true)
                {
                    if ((position.Column == m_PieceThatCaptured.Column) && (position.Row == m_PieceThatCaptured.Row))
                    {
                        GamePieceUIPieceTaken = pieceChosen.ChoosePiece(ref m_CurrentPosition, ref m_FirstTurnClick);
                        changeCursorAndPieceTaken(new Cursor(((Bitmap)pieceChosen.Image).GetHicon()), DamkaGraphics.transparentTile);
                    }
                    else
                    {
                        MessageBox.Show("Invalid selection.");
                    }
                }
                else
                {
                    if (m_CurrentPlayer == m_PlayerOne)
                    {
                        if (m_PlayerOnePieces.Contains(i_Sender as GamePieceUI))
                        {
                            GamePieceUIPieceTaken = pieceChosen.ChoosePiece(ref m_CurrentPosition, ref m_FirstTurnClick);
                            changeCursorAndPieceTaken(new Cursor(((Bitmap)pieceChosen.Image).GetHicon()), DamkaGraphics.transparentTile);
                        }
                        else
                        {
                            MessageBox.Show("Invalid selection.");
                        }
                    }
                    else
                    {
                        if (m_PlayerTwoPieces.Contains(i_Sender as GamePieceUI))
                        {
                            GamePieceUIPieceTaken = pieceChosen.ChoosePiece(ref m_CurrentPosition, ref m_FirstTurnClick);
                            changeCursorAndPieceTaken(new Cursor(((Bitmap)pieceChosen.Image).GetHicon()), DamkaGraphics.transparentTile);
                        }
                        else
                        {
                            MessageBox.Show("Invalid selection.");
                        }
                    }
                }
            }
            else
            {
                if (GamePieceUIPieceTaken == (i_Sender as GamePieceUI))
                {
                    GamePieceUIPieceTaken.BackColor = Color.White;
                    m_FirstTurnClick = true;
                    changeCursorAndPieceTaken(m_DefaultCursor, m_PieceTakenImage);
                }
                else
                {
                    MessageBox.Show("Invalid selection.");
                }
            }
        }