Ejemplo n.º 1
0
        private bool tryUncoverPairFromMemory()
        {
            bool uncoveredPartnerFromMemory = false;

            for (int i = 0; i < MemoryBoard.GetLength(0) && !uncoveredPartnerFromMemory; i++)
            {
                for (int j = 0; j < MemoryBoard.GetLength(1) && !uncoveredPartnerFromMemory; j++)
                {
                    if (OriginalBoard[i, j].Covered)
                    {
                        uncoveredPartnerFromMemory = tryUncoverPartnerFromMemory(MemoryBoard[i, j]);

                        if (uncoveredPartnerFromMemory)
                        {
                            OriginalBoard[i, j].WaitingForPartner = true;
                            OriginalBoard[i, j].Covered           = false;
                            onMoveDone();
                            OriginalBoard[i, j].UpdateFoundPartner();
                        }
                    }
                }
            }

            return(uncoveredPartnerFromMemory);
        }
Ejemplo n.º 2
0
        private void enableDisableButtonsComputerTurn(bool i_EnableDisable)
        {
            MemoryGameButton button;

            foreach (Control c in Controls)
            {
                button = c as MemoryGameButton;

                if (button != null)
                {
                    if (i_EnableDisable == true)
                    {
                        if (MemoryBoard.IsOpen(button.Row, button.Col) == false)
                        {
                            button.Click += MemoryGameButton_Click;
                        }
                    }
                    else
                    {
                        if (MemoryBoard.IsOpen(button.Row, button.Col) == false)
                        {
                            button.Click -= MemoryGameButton_Click;
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
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;
                }
            }
        }
Ejemplo n.º 4
0
 private void computerChooseSameTiles()
 {
     MemoryBoard.MakeOpen(FirstChoiceButton.Row, FirstChoiceButton.Col, SecondChoiceButton.Row, SecondChoiceButton.Col);
     incScore();
     updateLabel();
     IsGameWon();
 }
Ejemplo n.º 5
0
        private void makeComputerTurn()
        {
            const bool k_EnableButtons = false;

            enableDisableButtonsComputerTurn(k_EnableButtons);

            if (ComputerTurnState == eComputerTurnState.FirstTileToChoose)
            {
                firstTileChoosenByComputer();
            }
            else if (ComputerTurnState == eComputerTurnState.SecondTileToChoose)
            {
                secondTileChoosenByComputer();
            }
            else if (ComputerTurnState == eComputerTurnState.EndTurn)
            {
                int firstTileValue  = MemoryBoard.GetKey(FirstChoiceButton.Row, FirstChoiceButton.Col);
                int secondTileValue = MemoryBoard.GetKey(SecondChoiceButton.Row, SecondChoiceButton.Col);

                if (firstTileValue == secondTileValue)
                {
                    computerChooseSameTiles();
                }
                else
                {
                    computerChooseDifferentTiles();
                }

                ComputerTurnState = eComputerTurnState.FirstTileToChoose;
            }
        }
Ejemplo n.º 6
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();
 }
Ejemplo n.º 7
0
 public void InitialMemory()
 {
     for (int i = 0; i < MemoryBoard.GetLength(0); i++)
     {
         for (int j = 0; j < MemoryBoard.GetLength(1); j++)
         {
             MemoryBoard[i, j] = new Cell();
         }
     }
 }
Ejemplo n.º 8
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;
        }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
0
 private void copyUncoveredCells()
 {
     for (int i = 0; i < MemoryBoard.GetLength(0); i++)
     {
         for (int j = 0; j < MemoryBoard.GetLength(1); j++)
         {
             if (!OriginalBoard[i, j].Covered)
             {
                 MemoryBoard[i, j].Content = OriginalBoard[i, j].Content;
             }
         }
     }
 }
Ejemplo n.º 11
0
        private void secondTileChoosenByComputer()
        {
            Point secondOpened = new Point();
            int   key;

            ComputerPlayer.ZeroAndUpdateRevealedTiles(MemoryBoard);
            secondOpened = ComputerPlayer.ChooseSecondTile(MemoryBoard);
            key          = MemoryBoard.GetKey(secondOpened.X, secondOpened.Y);
            TileButtonMatrix[secondOpened.X, secondOpened.Y].Image = GameManager.sr_ValueDictionary[key].Image;
            SecondChoiceButton           = TileButtonMatrix[secondOpened.X, secondOpened.Y];
            SecondChoiceButton.BackColor = Player2Name.BackColor;
            ComputerTurnState            = eComputerTurnState.EndTurn;
        }
Ejemplo n.º 12
0
        private void firstTileChoosenByComputer()
        {
            Point firstOpened = new Point();
            int   key;

            ComputerPlayer.ZeroAndUpdateRevealedTiles(MemoryBoard);
            firstOpened = ComputerPlayer.ChooseFirstTile(MemoryBoard);
            key         = MemoryBoard.GetKey(firstOpened.X, firstOpened.Y);
            TileButtonMatrix[firstOpened.X, firstOpened.Y].Image = GameManager.sr_ValueDictionary[key].Image;
            FirstChoiceButton           = TileButtonMatrix[firstOpened.X, firstOpened.Y];
            FirstChoiceButton.BackColor = Player2Name.BackColor;
            ComputerTurnState           = eComputerTurnState.SecondTileToChoose;
        }
Ejemplo n.º 13
0
        private void computerChooseDifferentTiles()
        {
            const bool k_EnableButtons = true;

            ComputerTimer.Stop();
            MemoryBoard.MakeRevealed(FirstChoiceButton.Row, FirstChoiceButton.Col, SecondChoiceButton.Row, SecondChoiceButton.Col);
            TileButtonMatrix[FirstChoiceButton.Row, FirstChoiceButton.Col].Image       = null;
            TileButtonMatrix[SecondChoiceButton.Row, SecondChoiceButton.Col].Image     = null;
            TileButtonMatrix[FirstChoiceButton.Row, FirstChoiceButton.Col].BackColor   = BackColor;
            TileButtonMatrix[SecondChoiceButton.Row, SecondChoiceButton.Col].BackColor = BackColor;
            Turn = !Turn;
            SetCurrentPlayerName();
            enableDisableButtonsComputerTurn(k_EnableButtons);
        }
Ejemplo n.º 14
0
        private void enableDisableButtonsPvPTurn(bool i_EnableDisable)
        {
            MemoryGameButton button;

            foreach (Control c in Controls)
            {
                button = c as MemoryGameButton;

                if (button != null)
                {
                    if (c != FirstChoiceButton && c != SecondChoiceButton && MemoryBoard.IsOpen(button.Row, button.Col) == false)
                    {
                        c.Enabled = i_EnableDisable;
                    }
                }
            }
        }
Ejemplo n.º 15
0
        private void IsGameWon()
        {
            MessageBoxButtons button     = MessageBoxButtons.YesNo;
            string            winnerName = string.Empty;
            string            loserName  = string.Empty;
            string            endGameMsg = string.Empty;

            if (MemoryBoard.IsGameWon())
            {
                ComputerTimer.Stop();

                if (ScorePlayer1 > ScorePlayer2)
                {
                    winnerName = Player1Name.Text.Substring(0, Player1NameLength);
                    loserName  = Player2Name.Text.Substring(0, Player2NameLength);
                    endGameMsg = string.Format("congratulations {0} you won the game with {1} pairs! {2}{3} with {4} pairs, Don't worry, maybe next time", winnerName, ScorePlayer1, Environment.NewLine, loserName, ScorePlayer2);
                }
                else if (ScorePlayer2 > ScorePlayer1)
                {
                    winnerName = Player2Name.Text.Substring(0, Player2NameLength);
                    loserName  = Player1Name.Text.Substring(0, Player1NameLength);
                    endGameMsg = string.Format("Congratulations!! {0} you won the game with {1} pairs! {2}{3} with {4} pairs, Don't worry, maybe next time", winnerName, ScorePlayer2, Environment.NewLine, loserName, ScorePlayer1);
                }
                else
                {
                    endGameMsg = string.Format("Its a tie!! {0}both of you got {1} pairs!", Environment.NewLine, ScorePlayer1);
                }

                endGameMsg = string.Format("{0}{1}Do you want to start another game?", endGameMsg, Environment.NewLine);

                DialogResult result = MessageBox.Show(endGameMsg, "Memory Game", button);

                if (result == DialogResult.Yes)
                {
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    DialogResult = DialogResult.No;
                }

                Close();
            }
        }
Ejemplo n.º 16
0
        private bool tryUncoverPartnerFromMemory(Cell i_Cell)
        {
            bool foundCellInMemory = false;

            for (int i = 0; i < MemoryBoard.GetLength(0) && !foundCellInMemory; i++)
            {
                for (int j = 0; j < MemoryBoard.GetLength(1) && !foundCellInMemory; j++)
                {
                    if (MemoryBoard[i, j].Content != " " && MemoryBoard[i, j].Content == i_Cell.Content &&
                        MemoryBoard[i, j] != i_Cell && OriginalBoard[i, j] != i_Cell && !OriginalBoard[i, j].FoundPartner)
                    {
                        foundCellInMemory = true;
                        OriginalBoard[i, j].WaitingForPartner = true;
                        OriginalBoard[i, j].Covered           = false;
                        onMoveDone();
                        OriginalBoard[i, j].UpdateFoundPartner();
                    }
                }
            }

            return(foundCellInMemory);
        }
Ejemplo n.º 17
0
    public void Awake()
    {
        if (string.IsNullOrEmpty(this.AppId))
        {
            Debug.LogError("You must enter your AppId from the Dashboard in the component: Scripts, MemoryGui, AppId before you can use this demo.");
            Debug.Break();
        }

        Application.runInBackground = true;
        CustomTypes.Register();

        this.GameClientInstance            = new MemoryGameClient();
        this.GameClientInstance.memoryGui  = this;
        this.GameClientInstance.AppId      = this.AppId;  // set in Inspector
        this.GameClientInstance.AppVersion = "1.0";


        board = this.GetComponentInChildren <MemoryBoard>();
        board.GameClientInstance = this.GameClientInstance;
        GameClientInstance.board = board;
        board.MemoryGui          = this;
        this.DisableButtons();
    }
Ejemplo n.º 18
0
    public void Awake()
    {
        if (string.IsNullOrEmpty(this.AppId))
        {
            Debug.LogError("You must enter your AppId from the Dashboard in the component: Scripts, MemoryGui, AppId before you can use this demo.");
            Debug.Break();
        }

        Application.runInBackground = true;
        CustomTypes.Register();

        this.GameClientInstance = new MemoryGameClient();

        this.GameClientInstance.memoryGui = this;
        this.GameClientInstance.AppId = this.AppId;       // set in Inspector
        this.GameClientInstance.AppVersion = "1.0";

        board = this.GetComponentInChildren<MemoryBoard>();
        board.GameClientInstance = this.GameClientInstance;
        GameClientInstance.board = board;
        board.MemoryGui = this;
        this.DisableButtons();
    }