Exemplo n.º 1
0
        /// <summary>
        /// finds out which goal cards in the Computer's hand would let the human win instantly
        /// </summary>
        /// <param name="player"></param>
        public void DontPlayCards(Player player)
        {
            for (int i = 0; i < HandList.Count; i++)
            {
                if (HandList[i] is GoalKeeperType)
                {
                    GoalKeeperType g = (GoalKeeperType)HandList[i];

                    for (int j = 0; j < player.KeeperList.Count; j++)
                    {
                        //if the human has played keepers that would meet the goal in the computer's hand
                        if (player.KeeperList[j].NameOfCard == g.Keeper1 || player.KeeperList[j].NameOfCard == g.Keeper2)
                        {
                            //look for the second keeper
                            for (int k = j + 1; k < player.KeeperList.Count; k++)
                            {
                                if (player.KeeperList[k].NameOfCard == g.Keeper1 || player.KeeperList[k].NameOfCard == g.Keeper2)
                                {
                                    //don't play that goal
                                    _numsNotToPlay.Add(i);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// if the player has a goal card and its requirements have been played, play the goal card
 /// </summary>
 /// <returns></returns>
 public bool FirstTest()
 {
     for (int i = 0; i < HandList.Count; i++)
     {
         if (HandList[i] is GoalKeeperType)
         {
             GoalKeeperType g = (GoalKeeperType)HandList[i];
             for (int j = 0; j < KeeperList.Count; j++)
             {
                 if (KeeperList[j].NameOfCard == g.Keeper1 || KeeperList[j].NameOfCard == g.Keeper2)
                 {
                     for (int k = j + 1; k < KeeperList.Count; k++)
                     {
                         if (KeeperList[k].NameOfCard == g.Keeper1 || KeeperList[k].NameOfCard == g.Keeper2)
                         {
                             Num = i;
                             return(true);
                         }
                     }
                 }
             }
         }
     }
     return(false);
 }
Exemplo n.º 3
0
        /// <summary>
        /// If the player has a keeper in hand that meets one of the requirements for a goal also in hand, play that keeper
        /// </summary>
        /// <param name="currentGoal"></param>
        /// <returns></returns>
        public bool ThirdTest()
        {
            for (int i = 0; i < HandList.Count; i++)
            {
                if (HandList[i] is GoalKeeperType)
                {
                    GoalKeeperType g = (GoalKeeperType)HandList[i];

                    for (int j = 0; j < HandList.Count; j++)
                    {
                        if (HandList[j] is Keeper)
                        {
                            Keeper k = (Keeper)HandList[j];

                            if (k.NameOfCard == g.Keeper1 || k.NameOfCard == g.Keeper2)
                            {
                                Num = j;
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
        /// <summary>
        /// the base method for Draws a goal card, sets current goal, removes from hand and checks for win
        /// </summary>
        /// <param name="b"></param>
        /// <param name="num"></param>
        /// <returns></returns>
        public Goal PlayGoalBase(Board b, int num)
        {
            Goal goalToAdd;

            //set goalToAdd to the selected goal
            goalToAdd = (Goal)_hand[num];
            if (goalToAdd is GoalKeeperType)
            {
                GoalKeeperType gK = (GoalKeeperType)goalToAdd;
                //create a new goal of correct type
                goalToAdd = new GoalKeeperType(gK.Bitmap, gK.Keeper1, gK.Keeper2);
            }
            else
            {
                GoalNumber gN = (GoalNumber)goalToAdd;
                //essesntially two types of GoalNUmber cards: Card requirement and Keeper requirement
                if (gN.Keeper == true)
                {
                    goalToAdd = new GoalNumber(gN.Bitmap, true, gN.Number);
                }
                else
                {
                    goalToAdd = new GoalNumber(gN.Bitmap, false, gN.Number);
                }
            }
            //draw the goalToAdd
            b.PaperTable.DrawImage(goalToAdd.Bitmap, _RESET_XPOS, goalToAdd.HEIGHT + goalToAdd.GAP);
            _hand.RemoveAt(num);
            return(goalToAdd);
        }
        public override bool CheckForWin(Goal goal, Player player)
        {
            bool firstKeeper  = false;
            bool secondKeeper = false;

            if (player.KeeperList.Count > 0)
            {
                foreach (Keeper k in player.KeeperList)
                {
                    //cast Goal to GoalKeeperType
                    GoalKeeperType g = (GoalKeeperType)goal;
                    //checks each keeper against the goal criteria
                    if (k.NameOfCard == g.Keeper1)
                    {
                        firstKeeper = true;
                    }
                    if (k.NameOfCard == g.Keeper2)
                    {
                        secondKeeper = true;
                    }
                }
            }
            //if goal met
            if (firstKeeper && secondKeeper)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// adds all the goals to the deck
        /// </summary>
        public void AddGoal()
        {
            //initialise array off image of each Goal
            Bitmap[] bArray = new Bitmap[]
            {
                Properties.Resources.Sleep___Music,
                Properties.Resources.Money___Love,
                Properties.Resources.Brain___Rocket,
                Properties.Resources.Party___Time,
                Properties.Resources.Milk___Cookies,
                Properties.Resources.Moon___Rocket,
                Properties.Resources.Cookies___Bread,
                Properties.Resources.Money___Television,
                Properties.Resources.Bread___Toaster,
                Properties.Resources._10_cards_in_hand,
                Properties.Resources._5_Keepers
            };

            //*add names of all the Goals from the embedded file so I don't have to add them individually
            Assembly assembly     = Assembly.GetExecutingAssembly();
            string   resourceName = "Fluxx.Resources.Goals.csv";

            Stream       stream = assembly.GetManifestResourceStream(resourceName);
            StreamReader reader = new StreamReader(stream);
            int          i      = 0;

            while (!reader.EndOfStream)
            {
                string   line     = reader.ReadLine();
                string[] csvArray = line.Split(',');
                string[] temp     = csvArray[0].Split('+');
                string   keeper1  = temp[0].Trim();
                string   keeper2  = temp[1].Trim();

                GoalKeeperType g = new GoalKeeperType(bArray[i], keeper1, keeper2);
                _cardList.Add(g);
                i++;
            }
            //only two types for this type of goal so just do it manually
            GoalNumber gNum = new GoalNumber(bArray[bArray.Length - 2], false, 10);

            _cardList.Add(gNum);
            GoalNumber gNum1 = new GoalNumber(bArray[bArray.Length - 1], true, 5);

            _cardList.Add(gNum1);
        }
Exemplo n.º 7
0
        /// <summary>
        /// if the player has a keeper in hand and that keeper is one of the requirements for the current goal, play that keeper
        /// </summary>
        /// <param name="currentGoal"></param>
        /// <returns></returns>
        public bool SecondTest(Goal currentGoal)
        {
            for (int i = 0; i < HandList.Count; i++)
            {
                if (HandList[i] is Keeper)
                {
                    Keeper k = (Keeper)HandList[i];
                    if (currentGoal is GoalKeeperType)
                    {
                        GoalKeeperType g = (GoalKeeperType)currentGoal;

                        if (k.NameOfCard == g.Keeper1 || k.NameOfCard == g.Keeper2)
                        {
                            Num = i;
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Play a random card that doesn't let the human instantly win OR override the goal when one of the keepers required is already in play
        /// </summary>
        /// <param name="currentGoal"></param>
        public void LastResort(Goal currentGoal)
        {
            Random rand           = new Random();
            int    num            = rand.Next(HandList.Count);
            bool   onGoal         = true;
            bool   foundValidCard = false;

            //checks to see we are able to play a card at random
            if (currentGoal is GoalKeeperType)
            {
                GoalKeeperType g = (GoalKeeperType)currentGoal;
                for (int i = 0; i < KeeperList.Count; i++)
                {
                    //if there is a played keeper that meets part of the current goal
                    if (KeeperList[i].NameOfCard == g.Keeper1 || KeeperList[i].NameOfCard == g.Keeper2)
                    {
                        for (int j = 0; j < HandList.Count; j++)
                        {
                            //if there is a goal card in the hand, we cannot select the first random number as it may be the goal card
                            //and thus override the current goal
                            if (HandList[j] is Goal)
                            {
                                AbleToPlayGoal = false;
                            }
                        }
                    }
                }
            }

            int goalCounter = 0;

            //counts number of goals in the hand as if there are only goal cards in the hand, the computer will have to override the current goal anyway
            foreach (Card c in HandList)
            {
                if (c is Goal)
                {
                    goalCounter++;
                }
            }
            //if there are no goal cards in the hand OR there are only goal cards in the hand
            if (AbleToPlayGoal || goalCounter == HandList.Count)
            {
                //we need to keep selecting a random card in the handlist until we get a valid card i.e not a goal card that will let the human win
                while (foundValidCard == false)
                {
                    num = rand.Next(HandList.Count);
                    Num = num;
                    //there are no bad cards to play so we can play any card we want
                    if (_numsNotToPlay.Count == 0)
                    {
                        foundValidCard = true;
                    }
                    //else there are bad cards and we dont want to play it
                    else
                    {
                        for (int i = 0; i < _numsNotToPlay.Count; i++)
                        {
                            if (_numsNotToPlay[i] == num)
                            {
                                //go through the while loop again with a different random number
                            }
                            else
                            {
                                foundValidCard = true;
                                break;
                            }
                        }
                    }
                }
            }
            //We don't want to play a goal card as it will override the current one
            else
            {
                //while the random number is selecting a goal card, keep trying with a different random number
                while (onGoal == true)
                {
                    Num = rand.Next(HandList.Count);
                    if (HandList[Num] is Goal)
                    {
                        //go around the loop again
                    }
                    else
                    {
                        onGoal = false;
                    }
                }
            }
        }