예제 #1
0
        private void MemoryGameButton_Click(object i_Sender, EventArgs i_E)
        {
            MemoryGameButton button = i_Sender as MemoryGameButton;
            int        key          = MemoryBoard.GetKey(button.Row, button.Col);
            PictureBox picture      = GameManager.sr_ValueDictionary[key];

            if (!MemoryBoard.IsOpenOrTurnOpen(button.Row, button.Col))
            {
                if (IsFirstTile)
                {
                    playerChooseFirstTile(button);
                }
                else
                {
                    button.Image       = picture.Image;
                    button.BackColor   = Turn ? Player2Name.BackColor : Player1Name.BackColor;
                    SecondChoiceButton = button;

                    if (MemoryBoard.SecondChoice(button.Row, button.Col))
                    {
                        playerChooseSameTiles(button);
                    }
                    else
                    {
                        playerChooseDifferentTiles(button);
                    }

                    IsFirstTile = !IsFirstTile;
                }
            }
        }
예제 #2
0
 private void playerChooseSameTiles(MemoryGameButton i_BoardTileButton)
 {
     MemoryBoard.MakeOpen(i_BoardTileButton.Row, i_BoardTileButton.Col, FirstChoiceButton.Row, FirstChoiceButton.Col);
     incScore();
     updateLabel();
     FirstChoiceButton.Click  -= MemoryGameButton_Click;
     SecondChoiceButton.Click -= MemoryGameButton_Click;
     IsGameWon();
 }
예제 #3
0
        private void playerChooseDifferentTiles(MemoryGameButton i_BoardTileButton)
        {
            bool disableButtons = false;

            enableDisableButtonsPvPTurn(disableButtons);
            PicTimer.Start();
            MemoryBoard.MakeTurnOpen(i_BoardTileButton.Row, i_BoardTileButton.Col);
            MemoryBoard.MakeRevealed(i_BoardTileButton.Row, i_BoardTileButton.Col, FirstChoiceButton.Row, FirstChoiceButton.Col);
            Turn = !Turn;
            SetCurrentPlayerName();
        }
예제 #4
0
        private void playerChooseFirstTile(MemoryGameButton i_BoardTileButton)
        {
            int        key     = MemoryBoard.GetKey(i_BoardTileButton.Row, i_BoardTileButton.Col);
            PictureBox picture = GameManager.sr_ValueDictionary[key];

            MemoryBoard.FirstChoice(i_BoardTileButton.Row, i_BoardTileButton.Col);
            i_BoardTileButton.Image     = picture.Image;
            IsFirstTile                 = !IsFirstTile;
            FirstChoiceButton           = i_BoardTileButton;
            i_BoardTileButton.BackColor = Turn ? Player2Name.BackColor : Player1Name.BackColor;
        }
예제 #5
0
        private void initializeTiles()
        {
            const int k_LeftSpacing = 20;
            const int k_TopSpacing  = 20;

            m_TileButtonMatrix = new MemoryGameButton[Rows, Cols];
            Button baseButton = TileButton;

            for (int i = 0; i < Rows; i++)
            {
                for (int j = 0; j < Cols; j++)
                {
                    TileButtonMatrix[i, j] = new MemoryGameButton(i, j);

                    if (i == 0)
                    {
                        TileButtonMatrix[i, j].Top = baseButton.Top;
                    }
                    else
                    {
                        TileButtonMatrix[i, j].Top = TileButtonMatrix[i - 1, j].Bottom + k_TopSpacing;
                    }

                    if (j == 0)
                    {
                        TileButtonMatrix[i, j].Left = baseButton.Left;
                    }
                    else
                    {
                        TileButtonMatrix[i, j].Left = TileButtonMatrix[i, j - 1].Right + k_LeftSpacing;
                    }

                    TileButtonMatrix[i, j].Enabled = true;
                    TileButtonMatrix[i, j].Visible = true;
                    TileButtonMatrix[i, j].Size    = baseButton.Size;
                    Controls.Add(TileButtonMatrix[i, j]);
                    TileButtonMatrix[i, j].Click += MemoryGameButton_Click;
                }
            }
        }