static void Main(string[] args)
        {
            Dictionary <PoolTypeEnum, HashSet <int> > tickets = new Dictionary <PoolTypeEnum, HashSet <int> >()
            {
                { PoolTypeEnum.RECREATION, new HashSet <int>() },
                { PoolTypeEnum.COMPETITION, new HashSet <int>() },
                { PoolTypeEnum.THERMAL, new HashSet <int>() },
                { PoolTypeEnum.KIDS, new HashSet <int>() }
            };

            for (int i = 1; i < 100; i++)
            {
                foreach (KeyValuePair <PoolTypeEnum, HashSet <int> > type in tickets)
                {
                    if (GetRandomBoolean())
                    {
                        type.Value.Add(i);
                    }
                }
            }

            Console.WriteLine("Number of visitors by a pool type:");
            foreach (KeyValuePair <PoolTypeEnum, HashSet <int> > type in tickets)
            {
                Console.WriteLine($" - {type.Key.ToString().ToLower()}: {type.Value.Count}");
                Console.ReadLine();
            }

            PoolTypeEnum maxVisitors = tickets
                                       .OrderByDescending(t => t.Value.Count)
                                       .Select(t => t.Key)
                                       .FirstOrDefault();

            Console.WriteLine($"Pool '{maxVisitors.ToString().ToLower()}' was the most popular.");
            Console.ReadLine();

            HashSet <int> any = new HashSet <int>(tickets[PoolTypeEnum.RECREATION]);

            any.UnionWith(tickets[PoolTypeEnum.COMPETITION]);
            any.UnionWith(tickets[PoolTypeEnum.THERMAL]);
            any.UnionWith(tickets[PoolTypeEnum.KIDS]);
            Console.WriteLine($"{any.Count} people visited at least one pool.");
            Console.ReadLine();

            HashSet <int> all = new HashSet <int>(tickets[PoolTypeEnum.RECREATION]);

            all.IntersectWith(tickets[PoolTypeEnum.COMPETITION]);
            all.IntersectWith(tickets[PoolTypeEnum.THERMAL]);
            all.IntersectWith(tickets[PoolTypeEnum.KIDS]);
            Console.WriteLine($"{all.Count} people visited all pools.");
            Console.ReadLine();

            Console.WriteLine("RECREATION: " + string.Join(" ", tickets[PoolTypeEnum.RECREATION]));
            Console.WriteLine("COMPETITION: " + string.Join(" ", tickets[PoolTypeEnum.COMPETITION]));
            Console.WriteLine("THERMAL: " + string.Join(" ", tickets[PoolTypeEnum.THERMAL]));
            Console.WriteLine("KIDS: " + string.Join(" ", tickets[PoolTypeEnum.KIDS]));
        }
Esempio n. 2
0
 public void Add(PoolTypeEnum type, IPoolable poolabelObject)
 {
     if (!AvailableObjects.ContainsKey(type))
     {
         AvailableObjects.Add(type, new List <IPoolable>());
     }
     poolabelObject.Deactivate();
     AvailableObjects[type].Add(poolabelObject);
 }
Esempio n. 3
0
    public IPoolable Fetch(PoolTypeEnum type, Func <PoolTypeEnum, IPoolable> instantiateCallback)
    {
        var firstAvailable = AvailableObjects[type].FirstOrDefault(po => po.IsAvailable());

        if (firstAvailable == null && instantiateCallback != null)
        {
            var instance = instantiateCallback(type);
            Add(type, instance);
            firstAvailable = instance;
        }
        return(firstAvailable);
    }
Esempio n. 4
0
    private IPoolable SpawnPoolableTapButton(PoolTypeEnum typeToSpawn)
    {
        GameObject prefab = typeToSpawn == PoolTypeEnum.ContinueButton ? continueButtonPrefab : gameOverButtonPrefab;

        return(Instantiate(prefab, Vector2.zero, Quaternion.identity, buttonsParent).GetComponent <IPoolable>());
    }
Esempio n. 5
0
 public List <IPoolable> GetAllActive(PoolTypeEnum type)
 {
     return(AvailableObjects[type].Where(po => !po.IsAvailable()).ToList());
 }