public void Initialise()
        {
            IHasSpeed hasSpeed  = GetComponent <IHasSpeed>();
            BaseSpeed baseSpeed = new BaseSpeed(8);

            hasSpeed.MyHasSpeedAlterer.AddAlteration(hasSpeed, baseSpeed);
        }
Exemple #2
0
 private void printSpeed(Toy toy)
 {
     if (toy is IHasSpeed)
     {
         IHasSpeed temp = (IHasSpeed)(toy);
         System.Console.WriteLine("Speed: " + temp.Speed);
     }
 }
 public void AddAlteration(IHasSpeed hasSpeed, ISpeedAlteration speedAlteration)
 {
     if (!MySpeedAlterationsDict.ContainsKey(hasSpeed))
     {
         MySpeedAlterationsDict[hasSpeed] = new List <ISpeedAlteration>();
     }
     MySpeedAlterationsDict[hasSpeed].Add(speedAlteration);
 }
        public void RemoveAlteration(IHasSpeed hasSpeed, ISpeedAlteration speedAlteration)
        {
            if (!MySpeedAlterationsDict.ContainsKey(hasSpeed))
            {
                Debug.LogError("Attempting to remove speed alteration from a HasSpeed that is not registered.");
            }

            MySpeedAlterationsDict[hasSpeed].Remove(speedAlteration);
        }
Exemple #5
0
 public void ChangeSpeed(double value)
 {
     if (toysList.Count > 1)
     {
         foreach (Toy toy in toysList)
         {
             if (toy is IHasSpeed)
             {
                 IHasSpeed temp = (IHasSpeed)(toy);
                 temp.Speed = value;
             }
         }
     }
 }
        public int GetTotalMoveSpeed(IHasSpeed hasSpeed)
        {
            if (!MySpeedAlterationsDict.ContainsKey(hasSpeed))
            {
                Debug.LogError("HasSpeed did not register in the dictionary.");
            }

            List <ISpeedAlteration> speedAlterations = MySpeedAlterationsDict[hasSpeed];

            speedAlterations.Sort(new SpeedAlterationSort());
            float speed = 0;

            foreach (ISpeedAlteration speedAlteration in speedAlterations)
            {
                speed = speedAlteration.Alter(speed);
            }
            return(Mathf.FloorToInt(speed));
        }
Exemple #7
0
 private void Awake()
 {
     HasSpeed = (IHasSpeed)_hasSpeedObject;
 }