Example #1
0
 public void AddComponent(iComponent c)
 {
     //prevent adding multiple of the same component
     if (!components.Contains(c))
     {
         components.Add(c);
     }
 }
Example #2
0
 public void EquipComponent(iComponent pw)
 {
     if (VerifyComponent(pw))
     {
         Optional = (iOptionalComponent)pw;
     }
     else
     {
         /// Do nothing
     }
 }
Example #3
0
 public void EquipComponent(iComponent pw)
 {
     if (VerifyComponent(pw))
     {
         Fixed = (iFixedComponent)pw;
     }
     else
     {
         /// Do nothing
     }
 }
Example #4
0
 public bool VerifyComponent(iComponent pw)
 {
     if (pw is iFixedComponent && pw.Size <= Size && pw.Name == Component)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #5
0
 public bool VerifyComponent(iComponent pw)
 {
     if (pw is iWeaponComponent && pw.Size <= Size)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #6
0
 public void EquipComponent(iComponent pw)
 {
     if (VerifyComponent(pw))
     {
         Weapon = (iWeaponComponent)pw;
     }
     else
     {
         /// Do nothing
     }
 }
Example #7
0
 public void EquipComponent(iComponent pw)
 {
     if (VerifyComponent(pw))
     {
         Utility = (iUtilityComponent)pw;
     }
     else
     {
         /// Do nothing
     }
 }
Example #8
0
 public bool VerifyComponent(iComponent pw)
 {
     if (Military)
     {
         if (pw is iOptionalComponent && pw.Size <= Size && pw.Military)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else if (pw is iOptionalComponent && pw.Size <= Size)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #9
0
 public void addComponent(iComponent c)
 {
     components.Add(c);
     componentCount++;
     c.start(this);
 }
Example #10
0
 public ConcreteDecoratorA(iComponent icomponent)
     : base(icomponent)
 {
 }
Example #11
0
 public Decorator(iComponent component)
 {
     this.component = component;
 }
Example #12
0
 public Decorator()
 {
     this.component = null;
 }
Example #13
0
        public static void testListDictLoopTimes(int listSize, int testsToAverage)
        {
            Console.WriteLine("Testing List Loop Times");

            List <testComponent> componentsList = new List <testComponent>();
            Dictionary <vector2, testComponent> componentsDict = new Dictionary <vector2, testComponent>();

            Console.WriteLine("Fill Test 0 - For Loop and List");

            var watch = System.Diagnostics.Stopwatch.StartNew();

            for (int i = 0; i < testsToAverage; i++)
            {
                watch.Stop();
                componentsList.Clear();
                watch.Start();
                for (int j = 0; j < listSize; j++)
                {
                    componentsList.Add(new testComponent(new vector2(j, j)));
                }
            }

            watch.Stop();
            double elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine("Fill: Test 0 - Took " + (elapsedMs / testsToAverage) + " ms");

            Console.WriteLine("Fill: Test 1 - For Loop and Dict");

            watch = System.Diagnostics.Stopwatch.StartNew();

            for (int i = 0; i < testsToAverage; i++)
            {
                watch.Stop();
                componentsDict.Clear();
                watch.Start();
                for (int j = 0; j < listSize; j++)
                {
                    vector2 pos = new vector2(j, j);
                    componentsDict.Add(pos, new testComponent(pos));
                }
            }

            watch.Stop();
            elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine("Fill: Test 1 - Took " + (elapsedMs / testsToAverage) + " ms");

            Console.WriteLine("Iteration: Test 2 - For Loop and List");

            watch = System.Diagnostics.Stopwatch.StartNew();

            for (int i = 0; i < testsToAverage; i++)
            {
                for (int j = 0; j < componentsList.Count; j++)
                {
                    componentsList[j].update(null);
                }
            }

            watch.Stop();
            elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine("Iteration: Test 2 - Took " + (elapsedMs / testsToAverage) + " ms");

            Console.WriteLine("Iteration: Test 3 - For Loop and Dict");

            watch = System.Diagnostics.Stopwatch.StartNew();

            for (int i = 0; i < testsToAverage; i++)
            {
                for (int j = 0; j < componentsDict.Count; j++)
                {
                    componentsDict[new vector2(j, j)].update(null);
                }
            }

            watch.Stop();
            elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine("Iteration: Test 3 - Took " + (elapsedMs / testsToAverage) + " ms");

            Console.WriteLine("Iteration: Test 4 - Foreach Loop and List");

            watch = System.Diagnostics.Stopwatch.StartNew();

            for (int i = 0; i < testsToAverage; i++)
            {
                foreach (iComponent v in componentsList)
                {
                    v.update(null);
                }
            }

            watch.Stop();
            elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine("Iteration: Test 4 - Took " + (elapsedMs / testsToAverage) + " ms");

            Console.WriteLine("Iteration: Test 5 - Foreach Loop and Dict");

            watch = System.Diagnostics.Stopwatch.StartNew();

            for (int i = 0; i < testsToAverage; i++)
            {
                foreach (KeyValuePair <vector2, testComponent> kvp in componentsDict)
                {
                    kvp.Value.update(null);
                }
            }

            watch.Stop();
            elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine("Iteration: Test 5 - Took " + (elapsedMs / testsToAverage) + " ms");

            Console.WriteLine("Find: Test 6 - List");

            watch = System.Diagnostics.Stopwatch.StartNew();

            for (int i = 0; i < testsToAverage; i++)
            {
                for (int j = 0; j < componentsList.Count; j++)
                {
                    iComponent working = componentsList.Single(s => (s.pos.x == j));
                    working.update(null);
                }
            }

            watch.Stop();
            elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine("Find: Test 6 - Took " + (elapsedMs / testsToAverage) + " ms");

            Console.WriteLine("Find: Test 7 - Dict");

            watch = System.Diagnostics.Stopwatch.StartNew();

            for (int i = 0; i < testsToAverage; i++)
            {
                for (int j = 0; j < componentsDict.Count; j++)
                {
                    testComponent working;

                    if (componentsDict.TryGetValue(new vector2(j, j), out working))
                    {
                        working.update(null);
                    }
                }
            }

            watch.Stop();
            elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine("Find: Test 7 - Took " + (elapsedMs / (testsToAverage) + " ms"));
            Console.ReadLine();
        }