Exemple #1
0
        private void initGameBoardButtons(GameBoard.eGameboardSizes i_GameBoardSize)
        {
            int     currentLocationTop, currentLocationLeft, leftLocationSaver;
            Vector2 location;

            GameBoardButtons = new ButtonWithLocation[(int)i_GameBoardSize, (int)i_GameBoardSize];
            getTopAndLeftInitButtonValue(out currentLocationTop, out currentLocationLeft, i_GameBoardSize);
            leftLocationSaver = currentLocationLeft;
            for (int i = 0; i < (int)i_GameBoardSize; i++)
            {
                for (int j = 0; j < (int)i_GameBoardSize; j++)
                {
                    location = new Vector2(j, i);
                    GameBoardButtons[i, j] = new ButtonWithLocation(i, j);
                    this.Controls.Add(GameBoardButtons[i, j]);
                    GameBoardButtons[i, j].AutoSize = true;
                    GameBoardButtons[i, j].Size     = new Size(35, 35);
                    GameBoardButtons[i, j].Location = new Point(currentLocationLeft, currentLocationTop);
                    currentLocationLeft            += 35;
                    if (((i % 2 == 0) && (j % 2 == 0)) || ((i % 2 == 1) && (j % 2 == 1)))
                    {
                        GameBoardButtons[i, j].Enabled   = false;
                        GameBoardButtons[i, j].BackColor = Color.Gray;
                    }
                    else
                    {
                        GameBoardButtons[i, j].BackColor = Color.BurlyWood;
                        GameBoardButtons[i, j].ForeColor = Color.BurlyWood;
                    }

                    if (i < ((int)i_GameBoardSize / 2) - 1 && GameBoardButtons[i, j].Enabled == true)
                    {
                        GameBoardButtons[i, j].BackgroundImage       = Image.FromFile(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + @"\white_man.png");
                        GameBoardButtons[i, j].BackgroundImageLayout = ImageLayout.Stretch;
                        GameBoardButtons[i, j].Text      = "O";
                        GameBoardButtons[i, j].TextAlign = ContentAlignment.MiddleCenter;
                        GameBoardButtons[i, j].Click    += new EventHandler(GameBoardButtons_FirstClick);
                    }
                    else if (i > ((int)i_GameBoardSize / 2) && GameBoardButtons[i, j].Enabled == true)
                    {
                        GameBoardButtons[i, j].BackgroundImage       = Image.FromFile(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + @"\black_man.png");
                        GameBoardButtons[i, j].BackgroundImageLayout = ImageLayout.Stretch;
                        GameBoardButtons[i, j].Text      = "X";
                        GameBoardButtons[i, j].TextAlign = ContentAlignment.MiddleCenter;
                        GameBoardButtons[i, j].Click    += new EventHandler(GameBoardButtons_FirstClick);
                    }
                    else
                    {
                        GameBoardButtons[i, j].Click += new EventHandler(GameBoardButtons_ClickOnEmptyCell);
                    }
                }

                currentLocationLeft = leftLocationSaver;
                currentLocationTop += 35;
            }
        }
Exemple #2
0
        private void GameBoardButtons_SecondClick(object sender, EventArgs e)
        {
            Button button = sender as Button;

            if (GameLogic.CurrentPlayerGroup.ToString() == button.Text)
            {
                button.BackColor  = Color.White;
                button.Click     += new EventHandler(GameBoardButtons_FirstClick);
                button.Click     -= new EventHandler(GameBoardButtons_SecondClick);
                m_IsButtonClicked = false;
                ClickedButton     = null;
            }
        }
Exemple #3
0
 private void initData()
 {
     m_IsMoveLegal       = false;
     m_HasAnotherEatMove = false;
     m_IsPcMove          = false;
     m_LastTurnGroup     = 'X';
     m_IsPlayerOneTurn   = true;
     m_IsButtonClicked   = false;
     if (ClickedButton != null)
     {
         ClickedButton.BackColor = Color.White;
         ClickedButton.Click    += new EventHandler(GameBoardButtons_FirstClick);
         ClickedButton.Click    -= new EventHandler(GameBoardButtons_SecondClick);
         ClickedButton           = null;
     }
 }
Exemple #4
0
        private void GameBoardButtons_FirstClick(object sender, EventArgs e)
        {
            ButtonWithLocation button = sender as ButtonWithLocation;

            if (GameLogic.CurrentPlayerGroup.ToString() == button.Text || (GameLogic.CurrentPlayerGroup.ToString() == "X" && button.Text == "K") || (GameLogic.CurrentPlayerGroup.ToString() == "O" && button.Text == "U"))
            {
                //// if blue color Button clicked set white color
                if (m_IsButtonClicked)
                {
                    ClickedButton.Click    += new EventHandler(GameBoardButtons_FirstClick);
                    ClickedButton.Click    -= new EventHandler(GameBoardButtons_SecondClick);
                    ClickedButton.BackColor = Color.White;
                }

                button.BackColor  = Color.CadetBlue;
                button.Click     -= new EventHandler(GameBoardButtons_FirstClick);
                button.Click     += new EventHandler(GameBoardButtons_SecondClick);
                m_IsButtonClicked = true;
                ClickedButton     = button;
            }
        }
Exemple #5
0
        private void pcGameBoardMove()
        {
            ButtonWithLocation pcNewButton = null, pcOldButton;
            string             winner = string.Empty, winMessage = string.Empty;
            char    whoWon;
            Vector2 pcMoveNewLocation = new Vector2(-1, -1), pcMoveStartLocation = new Vector2(-1, -1);

            pcMoveNewLocation = Logic.GameLogic.MakePcRandomMove(m_GameBoard, ref m_IsPcHasAvailableMoves, ref m_HasAnotherEatMove, out pcMoveStartLocation);

            if (!m_IsPcHasAvailableMoves)
            {
                if (!Logic.GameLogic.IsATie(m_GameBoard))
                {
                    whoWon     = GameLogic.WhoWin();
                    winner     = whoWon == 'X' ? PlayerOneName.Text : PlayerTwoName.Text;
                    winMessage = string.Format("{0} Won!{1}Another Round?", winner, Environment.NewLine);
                }
                else
                {
                    winMessage = string.Format("Tie!{0}Another Round?", Environment.NewLine);
                }

                isInterestedInAnotherGame(winMessage);
            }
            else
            {
                pcNewButton        = GameBoardButtons[pcMoveNewLocation.GetRow, pcMoveNewLocation.GetColumn];
                pcOldButton        = GameBoardButtons[pcMoveStartLocation.GetRow, pcMoveStartLocation.GetColumn];
                pcOldButton.Click -= new EventHandler(GameBoardButtons_FirstClick);
                pcOldButton.Click += new EventHandler(GameBoardButtons_ClickOnEmptyCell);
                pcNewButton.Click += new EventHandler(GameBoardButtons_FirstClick);
                m_Pieces.Add(m_GameBoard[pcNewButton.VectorLocation]);
                GameBoardButtons[pcMoveStartLocation.GetRow, pcMoveStartLocation.GetColumn].Text            = string.Empty;
                GameBoardButtons[pcMoveStartLocation.GetRow, pcMoveStartLocation.GetColumn].BackgroundImage = null;

                m_IsButtonClicked = false;
                Piece currentPiece = m_GameBoard[pcNewButton.VectorLocation];
                if (m_HasAnotherEatMove)
                {
                    while (GameLogic.ExeAllPcEatMovesAvailableToCurrentLocation(m_GameBoard, currentPiece))
                    {
                        pcNewButton.Click -= new EventHandler(GameBoardButtons_FirstClick);
                        pcNewButton.Click += new EventHandler(GameBoardButtons_ClickOnEmptyCell);
                        GameBoardButtons[pcMoveNewLocation.GetRow, pcMoveNewLocation.GetColumn].Text            = string.Empty;
                        GameBoardButtons[pcMoveNewLocation.GetRow, pcMoveNewLocation.GetColumn].BackgroundImage = null;
                    }

                    m_Pieces.Add(m_GameBoard[pcNewButton.VectorLocation]);
                    pcNewButton        = GameBoardButtons[currentPiece.GetLocation.GetRow, currentPiece.GetLocation.GetColumn];
                    pcNewButton.Click += new EventHandler(GameBoardButtons_FirstClick);
                    pcNewButton.Click += new EventHandler(GameBoardButtons_ClickOnEmptyCell);
                    m_IsPcMove         = !m_IsPcMove;
                }

                if (!m_HasAnotherEatMove)
                {
                    if (m_IsMoveLegal)
                    {
                        m_IsPcMove = !m_IsPcMove;
                    }
                }
            }
        }
Exemple #6
0
        private void GameBoardButtons_ClickOnEmptyCell(object sender, EventArgs e)
        {
            bool printMustEatError = false;

            pieces.Piece       currentPiece;
            ButtonWithLocation button = sender as ButtonWithLocation;
            string             winner = string.Empty, winMessage = string.Empty;
            char    whoWon;
            Vector2 pcMoveNewLocation = new Vector2(-1, -1), pcMoveStartLocation = new Vector2(-1, -1);

            if (ClickedButton != null)
            {
                currentPiece    = new pieces.Piece(ClickedButton.Text[0], ClickedButton.VectorLocation);
                m_IsMoveLegal   = Logic.GameLogic.CheckMove(currentPiece, button.VectorLocation, m_GameBoard, ref m_HasAnotherEatMove, ref printMustEatError, m_IsPcMove, ref pcMoveNewLocation);
                m_LastTurnGroup = Logic.GameLogic.CurrentPlayerGroup;

                if (m_HasAnotherEatMove || printMustEatError)
                {
                    printMustEatMessageBox();
                }
                else if (!m_IsMoveLegal)
                {
                    printIllegalMoveMessageBox();
                    ClickedButton.BackColor = Color.White;
                }

                if (m_IsMoveLegal)
                {
                    Logic.GameLogic.UpdateCurrentTurn(ref m_IsPlayerOneTurn);
                    m_Pieces.Add(m_GameBoard[button.VectorLocation]);
                    ClickedButton.Click          -= new EventHandler(GameBoardButtons_SecondClick);
                    ClickedButton.Click          += new EventHandler(GameBoardButtons_ClickOnEmptyCell);
                    ClickedButton.BackgroundImage = null;
                    ClickedButton.BackColor       = Color.BurlyWood;
                    ClickedButton.Text            = string.Empty;
                    ClickedButton     = null;
                    m_IsButtonClicked = false;
                }

                if (!m_IsPlayerOneTurn)
                {
                    m_IsPlayerOneTurn = !m_IsPlayerOneTurn;
                    if (!m_Is2PlayersMode)
                    {
                        m_IsPcMove = true;
                        pcGameBoardMove();
                        Logic.GameLogic.UpdateCurrentTurn(ref m_IsPlayerOneTurn);
                    }
                }

                if (Logic.GameLogic.IsGameOver(m_GameBoard))
                {
                    if (!Logic.GameLogic.IsATie(m_GameBoard))
                    {
                        whoWon     = GameLogic.WhoWin();
                        winner     = whoWon == 'X' ? PlayerOneName.Text : PlayerTwoName.Text;
                        winMessage = string.Format("{0} Won!{1}Another Round?", winner, Environment.NewLine);
                    }
                    else
                    {
                        winMessage = string.Format("Tie!{0}Another Round?", Environment.NewLine);
                    }

                    isInterestedInAnotherGame(winMessage);
                }
            }
        }