Example #1
0
        /// <summary>
        /// Creates a new SinglePlayer game
        /// </summary>
        /// <param name="adjustButtonStatus">Enable/Disable turning over a card</param>
        /// <param name="updateImageSource">Changes the source of an image</param>
        public SinglePlayer(AdjustButtonStatus adjustButtonStatus, UpdateImageSource updateImageSource)
        {
            Cards.Shuffle <Card>();

            Reset(updateImageSource);

            EnableUndiscoveredButtons(adjustButtonStatus);
        }
Example #2
0
 /// <summary>
 /// Enables turning over every card still in play
 /// </summary>
 /// <param name="adjustButtonStatus">Enable/Disable turning over a card</param>
 public virtual void EnableUndiscoveredButtons(AdjustButtonStatus adjustButtonStatus)
 {
     for (int i = 0; i < Cards.Count; i++)
     {
         if (Cards[i].Discover_Player1 == false)
         {
             adjustButtonStatus(i, true);
         }
     }
 }
Example #3
0
 /// <summary>
 /// Enables turning over every card still in play
 /// </summary>
 /// <param name="adjustButtonStatus">Enable/Disable turning over a card</param>
 public override void EnableUndiscoveredButtons(AdjustButtonStatus adjustButtonStatus)
 {
     for (int i = 0; i < Cards.Count; i++)
     {
         if (!(Cards[i].Discover_Player1 || Cards[i].Discover_Player2))
         {
             adjustButtonStatus(i, true);
         }
     }
 }
Example #4
0
 /// <summary>
 /// Turns over the specified card
 /// </summary>
 /// <param name="i">Specified Card</param>
 /// <param name="adjustButtonStatus">Enable/Disable turning over a card</param>
 /// <param name="updateImageSource">Changes the source of an image</param>
 /// <param name="displayVictoryMessage">Dictates what function to call to display victory message</param>
 /// <returns></returns>
 public override bool PlayButton(int i, AdjustButtonStatus adjustButtonStatus,
                                 UpdateImageSource updateImageSource,
                                 DisplayVictoryMessage displayVictoryMessage)
 {
     Counter++;
     if (Counter == 3)
     {
         Counter = 1;
         Reset(updateImageSource);
     }
     updateImageSource(i, Cards[i].Image_Path);
     CurrentCard = Cards[i].Name;
     adjustButtonStatus(i, false);
     if (Counter == 2)
     {
         if (CurrentCard == PreviousCard)
         {
             foreach (var item in Cards)
             {
                 if (CurrentCard == item.Name)
                 {
                     if (Player == 1)
                     {
                         item.Discover_Player1 = true;
                         PlayerOneScore++;
                     }
                     else
                     {
                         item.Discover_Player2 = true;
                         PlayerTwoScore++;
                     }
                     Reset(updateImageSource);
                 }
             }
             if (Victory(displayVictoryMessage))
             {
                 return(true);
             }
         }
         Player = (Player == 1) ? 2 : 1;
         EnableUndiscoveredButtons(adjustButtonStatus);
     }
     PreviousCard = CurrentCard;
     return(false);
 }
Example #5
0
        /// <summary>
        /// Turns over the specified card
        /// </summary>
        /// <param name="i">Specified Card</param>
        /// <param name="adjustButtonStatus">Enable/Disable turning over a card</param>
        /// <param name="updateImageSource">Changes the source of an image</param>
        /// <param name="displayVictoryMessage">Dictates what function to call to display victory message</param>
        /// <returns></returns>
        public virtual bool PlayButton(int i, AdjustButtonStatus adjustButtonStatus,
                                       UpdateImageSource updateImageSource,
                                       DisplayVictoryMessage displayVictoryMessage)
        {
            Counter++;
            if (Counter == 3)
            {
                Counter = 1;
                Reset(updateImageSource);
            }

            updateImageSource(i, Cards[i].Image_Path);
            CurrentCard = Cards[i].Name;
            adjustButtonStatus(i, false);

            if (Counter == 2)
            {
                if (CurrentCard == PreviousCard)
                {
                    foreach (var card in Cards)
                    {
                        if (CurrentCard == card.Name)
                        {
                            card.Discover_Player1 = true;
                            Reset(updateImageSource);
                        }
                    }
                    if (Victory(displayVictoryMessage))
                    {
                        return(true);
                    }
                }

                MoveCounter++;
                EnableUndiscoveredButtons(adjustButtonStatus);
            }
            PreviousCard = CurrentCard;
            return(false);
        }
Example #6
0
        public override bool PlayButton(int i,
                                        AdjustButtonStatus adjustButtonStatus,
                                        UpdateImageSource updateImageSource,
                                        DisplayVictoryMessage displayVictoryMessage)
        {
            AddToAiMemory(i);
            Counter++;
            updateImageSource(i, Cards[i].Image_Path);
            CurrentCard = Cards[i].Name;
            adjustButtonStatus(i, false);
            if (Counter == 2)
            {
                if (CurrentCard == PreviousCard)
                {
                    foreach (var item in Cards)
                    {
                        if (CurrentCard == item.Name)
                        {
                            item.Discover_Player1 = true;
                            PlayerOneScore++;
                            Reset(updateImageSource);
                        }
                    }
                    RemoveFromAiMemory(); // this goes into the if and takes on NAME param and it should work as well
                    if (Victory(displayVictoryMessage))
                    {
                        return(true);
                    }
                }
                // AI turn begins
                #region AiTurn
                Counter = 0;
                Player  = 2;

                WriteMessageEvent("Press OK to begin ai's turn");

                Reset(updateImageSource);
                if (AiMemory.Count > 0)
                {
                    if (!CheckAiMemoryForPair(updateImageSource, displayVictoryMessage))
                    {
                        int tmp = AiPlayButton(AiPlaysRandomButton(), true, updateImageSource, displayVictoryMessage);
                        if (!CheckAiMemoryForMatch(tmp, updateImageSource, displayVictoryMessage))
                        {
                            AiPlayButton(AiPlaysRandomButton(), true, updateImageSource, displayVictoryMessage);
                        }
                    }
                }
                else
                {
                    AiPlayButton(AiPlaysRandomButton(), true, updateImageSource, displayVictoryMessage);
                    AiPlayButton(AiPlaysRandomButton(), true, updateImageSource, displayVictoryMessage);
                }

                #endregion
                Counter = 0;
                Player  = 1;
                EnableUndiscoveredButtons(adjustButtonStatus);

                if (Victory(displayVictoryMessage))
                {
                    return(true);
                }

                WriteMessageEvent("Press OK to begin player's turn");
                Reset(updateImageSource);
            }
            PreviousCard = CurrentCard;
            return(false);
        }
Example #7
0
 /// <summary>
 /// Creates a new game vs an AI controlled player
 /// </summary>
 /// <param name="adjustButtonStatus">Enable/Disable turning over a card</param>
 /// <param name="updateImageSource">Changes the source of an image</param>
 public AiPlayer(AdjustButtonStatus adjustButtonStatus, UpdateImageSource updateImageSource) : base(adjustButtonStatus, updateImageSource)
 {
 }