Beispiel #1
0
        private bool FoundMatch(Color selectedColor)
        {
            if (GameState == 1)
            {
                Int32 matchValue = 0;

                foreach (Button bp in selectedButtonList)
                {
                    if (bp.BackColor == selectedColor)
                    {
                        matchValue++;

                        if (matchValue == 2)
                        {
                            ButtonRefresh(); // Clears selectedButtonList
                            return(true);
                        }
                    }
                }
                return(false);
            } // End Of GameState 1 Code

            else if (GameState == 2)
            {
                Int32 matchValue = 0;

                foreach (Button bp in selectedButtonList)
                {
                    if (bp.BackColor == selectedColor)
                    {
                        matchValue++;

                        if (matchValue == 3)
                        {
                            ButtonRefresh(); // Clears selectedButtonList
                            return(true);
                        }
                    }
                }
                return(false);
            } // End Of GameState 2 Code

            else if (GameState == 3)
            {
                Int32 matchValue = 0;

                foreach (Button bp in selectedButtonList)
                {
                    if (bp.BackColor == selectedColor)
                    {
                        matchValue++;

                        if (matchValue == 2)
                        {
                            CardFlipTimer.Start();
                            ButtonRefresh(); // Clears selectedButtonList
                            return(true);
                        }
                    }
                }
                return(false);
            } // End Of GameState 3 Code

            else
            {
                return(false); // Code will never reach this, but added for good practice anyways.
            }
        }
Beispiel #2
0
        private void ClickedPlayButtons(object sender, EventArgs e)
        {
            Int32 bIndex = bColors.IndexOf(((Button)sender).BackColor);

            if (GameState == 1 || GameState == 2)
            {
                if (bIndex % 2 == 0) //"Selected"
                {
                    ((Button)sender).BackColor = bColors[bIndex + 1];
                    selectedButtonList.Add(((Button)sender));
                    label2.Text = selectedButtonList.Count.ToString();
                }

                else //"Unselected"
                {
                    ((Button)sender).BackColor = bColors[bIndex - 1];
                    selectedButtonList.Remove(((Button)sender));
                    label2.Text = selectedButtonList.Count.ToString();
                }
            }

            else if (GameState == 3)
            {
                CardFlipTimer.Start();

                Int32 buttonIndex = allButtonList.BinarySearch(((Button)sender));
                Color buttonColor = allbuttColor[buttonIndex]; //Out of Range Error (See OnTimedEvent)
                ((Button)sender).BackColor = buttonColor;
            }

            //FoundMatch Method Call. Everytime a button is pressed, check to see if it's a match or not.

            if (GameState == 1)
            {
                if (selectedButtonList.Count() > 1)             // Only check if there is enough buttons pressed to check.
                {
                    if (FoundMatch(((Button)sender).BackColor)) // If ture
                    {
                        score += 5;
                    }

                    else // else it's false
                    {
                        score -= 7;
                    }
                }
            } // Game Logic for GameState 1

            else if (GameState == 2)
            {
                if (selectedButtonList.Count() > 2)             // Only check if there is enough buttons pressed to check.
                {
                    if (FoundMatch(((Button)sender).BackColor)) // If ture
                    {
                        score += 15;
                    }

                    else // else it's false
                    {
                        score -= 25;
                    }
                }
            } // Game Logic for GameState 2

            else if (GameState == 3)
            {
                if (selectedButtonList.Count() > 1)             // Only check if there is enough buttons pressed to check.
                {
                    if (FoundMatch(((Button)sender).BackColor)) // If ture
                    {
                        score += 25;
                    }

                    else // else it's false
                    {
                        score -= 30;
                    }
                }
            } // Game Logic for GameState 3

            if (timeLeft < 4)
            {
                timeLeft += 2;               // I call it desperation time. You're on the edge, how long can you hold on?
            }
        }