Ejemplo n.º 1
0
        public void AssignMealsToEatOutUsingFlags()
        {
            // single pipe, "|", in C# is a logic operator, not conditional.
            // used at binary level to OR each position of the binary values.
            // with an OR, the result is true when at least one condition is true;
            // otherwise the result is false.

            /*
             * EXAMPLE:
             *
             * MealsToEatOut  = Meals.Breakfast | Meals.Snack | Meals.Dinner;
             *
             * Breakfast    0	0	0	0	0	0	1
             |	|	|	|	|	|	|
             | Snack    0	0	0	0	1	0	0
             |	|	|	|	|	|	|
             | Dinner	0	0	0	1	0	0	0
             |  ________________________________________
             |  Result	0	0	0	1	1	0	1
             |
             | Use the logical AND operator "&" to see if the result has a flag set.
             |
             | if((MealsToEatOut & Meals.Breakfast) == Meals.Breakfast)
             |  {
             |      // has Breakfast
             |  }
             |  else
             |  {
             |      // DOES NOT have Breakfast
             |  }
             |
             |  MealsToEatOut	0	0	0	1	1	0	1
             |                      &	&	&	&	&	&	&
             |      Breakfast	0	0	0	0	0	0	1
             |    ________________________________________
             |        Result	0	0	0	0	0	0	1   --> has breakfast
             |
             */

            //
            // Array Initializers
            //
            var exepectedMealsToEatOut = new[] { Meals.Breakfast, Meals.Lunch, Meals.LateNight };
            // another way... exepectedMealsToEatOut[] = {Meals.Breakfast, Meals.Lunch, Meals.LateNight};
            var actualMealsToEatOut = new Meals[3];                  // creates an array for three elements

            EatingOut.SetMealsToEatOut(exepectedMealsToEatOut);      // using params here!

            var meals = Enum.GetValues(typeof(Meals)).Cast <Enum>(); // cast to Enum in order to do the Where...below

            var index = 0;

            foreach (var appointment in meals.Where(EatingOut.MealsToEatOut.HasFlag))
            {
                actualMealsToEatOut[index] = (Meals)appointment;
                index++;
            }

            Assert.IsTrue(actualMealsToEatOut.SequenceEqual(exepectedMealsToEatOut)); // https://www.dotnetperls.com/sequenceequal
        }
Ejemplo n.º 2
0
        private Card RandomCard(Vector2 position, bool front, int playerID)
        {
            Card c = null;

            if (Globals.r.Next(4) == 0)
            {
                int cardsCount = 31;
                int rn         = Globals.r.Next(cardsCount);
                switch (rn)
                {
                case 0:
                    c = new Actor(position, front, playerID);
                    break;

                case 1:
                    c = new Artist(position, front, playerID);
                    break;

                case 2:
                    c = new Astrophysicist(position, front, playerID);
                    break;

                case 3:
                    c = new Babysitter(position, front, playerID);
                    break;

                case 4:
                    c = new BabysitterU(position, front, playerID);
                    break;

                case 5:
                    c = new BusDriver(position, front, playerID);
                    break;

                case 6:
                    c = new Conman(position, front, playerID);
                    break;

                case 7:
                    c = new DeliveryPerson(position, front, playerID);
                    break;

                case 8:
                    c = new DrugDealer(position, front, playerID);
                    break;

                case 9:
                    c = new FastFoodEmployee(position, front, playerID);
                    break;

                case 10:
                    c = new Hacker(position, front, playerID);
                    break;

                case 11:
                    c = new Hitman(position, front, playerID);
                    break;

                case 12:
                    c = new HumanTrafficker(position, front, playerID);
                    break;

                case 13:
                    c = new IndieGameDev(position, front, playerID);
                    break;

                case 14:
                    c = new Influencer(position, front, playerID);
                    break;

                case 15:
                    c = new InstaModel(position, front, playerID);
                    break;

                case 16:
                    c = new InternDev(position, front, playerID);
                    break;

                case 17:
                    c = new JuniorDev(position, front, playerID);
                    break;

                case 18:
                    c = new Musician(position, front, playerID);
                    break;

                case 19:
                    c = new OnlyFans(position, front, playerID);
                    break;

                case 20:
                    c = new Referee(position, front, playerID);
                    break;

                case 21:
                    c = new RiceFarmer(position, front, playerID);
                    break;

                case 22:
                    c = new Santa(position, front, playerID);
                    break;

                case 23:
                    c = new Shelfstacker(position, front, playerID);
                    break;

                case 24:
                    c = new Shoplifter(position, front, playerID);
                    break;

                case 25:
                    c = new Sporter(position, front, playerID);
                    break;

                case 27:
                    c = new Streamer(position, front, playerID);
                    break;

                case 28:
                    c = new SugarDaddy(position, front, playerID);
                    break;

                case 29:
                    c = new TaxiDriver(position, front, playerID);
                    break;

                case 30:
                    c = new Writer(position, front, playerID);
                    break;

                case 26:
                    c = new YogaInstructor(position, front, playerID);
                    break;
                }
            }
            else
            {
                int cardsCount = 12;
                int rn         = Globals.r.Next(cardsCount);
                switch (rn)
                {
                case 0:
                    c = new Alcohol(position, front, playerID);
                    break;

                case 1:
                    c = new Drugs(position, front, playerID);
                    break;

                case 2:
                    c = new EatingOut(position, front, playerID);
                    break;

                case 3:
                    c = new FastFood(position, front, playerID);
                    break;

                case 4:
                    c = new Gambling(position, front, playerID);
                    break;

                case 5:
                    c = new Gaming(position, front, playerID);
                    break;

                case 6:
                    c = new Joint(position, front, playerID);
                    break;

                case 7:
                    c = new PomXML(position, front, playerID);
                    break;

                case 8:
                    c = new Shopping(position, front, playerID);
                    break;

                case 9:
                    c = new Smoking(position, front, playerID);
                    break;

                case 10:
                    c = new SocialMedia(position, front, playerID);
                    break;

                case 11:
                    c = new Streaming(position, front, playerID);
                    break;
                }
            }

            return(c);
        }