private void PrimaryAttributeTest(PrimaryAttribute attr) { GameTime.time = 0; // Set some values attr.Value = attr.MinValue; Assert.AreEqual(attr.Value, attr.MinValue); attr.Value = float.MaxValue; Assert.AreEqual(attr.Value, attr.MaxValue); attr.Value = float.MinValue; Assert.AreEqual(attr.Value, attr.MinValue); // Add a modifier attr.AddModifier(new TimeBasedModifier("StrengthBuff", 10, 10)); Assert.AreEqual(attr.MinValue + 10, attr.Value); attr.BaseValue += 1; Assert.AreEqual(attr.MinValue + 11, attr.Value); attr.BaseValue -= 1; // Advance in time for (int i = 0; i < 10; i++) { GameTime.time = i; Assert.AreEqual(attr.MinValue + 10, attr.Value); } // Until the modifier's life cycle is over GameTime.time += 1; Assert.AreEqual(attr.MinValue, attr.Value); // Add some more modifiers and advance time GameTime.time = 0; attr.AddModifier(new TimeBasedModifier("StrengthBuff", 10, 10)); attr.AddModifier(new TimeBasedModifier("AnotherStrengthBuff", 20, 5)); Assert.AreEqual(attr.MinValue + 30, attr.Value); GameTime.time = 5; Assert.AreEqual(attr.MinValue + 10, attr.Value); Assert.AreEqual(1, attr.Modifiers.Count); Assert.IsTrue(attr.IsModified); GameTime.time = 10; Assert.AreEqual(attr.MinValue, attr.Value); Assert.AreEqual(0, attr.Modifiers.Count); Assert.IsFalse(attr.IsModified); attr.Value = attr.MaxValue; attr.Reset(); Assert.AreEqual(attr.MinValue, attr.Value); }
private void VolumeTest(VolumeAttribute volumeAttr) { GameTime.time = 0; // Check the default values Body.Value = 0; Assert.AreEqual(0, volumeAttr.MinValue); Assert.AreEqual(20, volumeAttr.MaxValue); Assert.AreEqual(20, volumeAttr.Value); Body.Value = 10; Assert.AreEqual(23, volumeAttr.MaxValue); Assert.AreEqual(20, volumeAttr.Value); volumeAttr.Value = 23; Body.Value = 0; Assert.AreEqual(0, volumeAttr.MinValue); Assert.AreEqual(20, volumeAttr.MaxValue); Assert.AreEqual(20, volumeAttr.Value); Body.Value = 10; // Set the value volumeAttr.Value = 10; Assert.AreEqual(10, volumeAttr.Value); volumeAttr.Value -= 10; Assert.AreEqual(0, volumeAttr.Value); // Dropping below the minimum volumeAttr.Value = float.MinValue; Assert.AreEqual(0, volumeAttr.Value); // Exceeding the maximum volumeAttr.Value = float.MaxValue; Assert.AreEqual(23, volumeAttr.Value); // Change corresponding attributes Experience.Value = 100; Assert.AreEqual(28, volumeAttr.MaxValue); // Apply modifier and advance in time Body.AddModifier(new TimeBasedModifier("StrengthBuff", 11, 10)); Assert.AreEqual(32, volumeAttr.MaxValue); GameTime.time = 11f; Assert.AreEqual(28, volumeAttr.MaxValue); // Reset volumeAttr.Value = 0; volumeAttr.Reset(); Assert.AreEqual(28, volumeAttr.Value); }
public void AttributeSignalTest() { _modifierAdded = 0; _modifierRemoved = 0; Body.OnModifierAdded += new ModifierAddedHandler(ModifierAdded); Body.OnModifierRemoved += new ModifierRemovedHandler(ModifierRemoved); // Change the value and test the received signal Body.OnValueChanged += new ValueChangedHandler(ValueChangedDemo); Body.Value = 100; Assert.AreEqual(1, _valueChangedEventTriggered); // Adding a modifier triggers the signal var modifier = new TimeBasedModifier("StrengthBuff", 10, 10); Body.AddModifier(modifier); Assert.AreEqual(1, _modifierAdded); Assert.AreEqual(2, _valueChangedEventTriggered); // Removing a modifier triggers the signal Body.RemoveModifier(modifier); Assert.AreEqual(3, _valueChangedEventTriggered); Assert.AreEqual(1, _modifierRemoved); // Secondary Attributes work the same Level.OnValueChanged += new ValueChangedHandler(ValueChangedDemo); Experience.Value = 100; Assert.AreEqual(4, _valueChangedEventTriggered); // Adding a modifier triggers the signal Experience.AddModifier(modifier); Assert.AreEqual(5, _valueChangedEventTriggered); // Removing a modifier triggers the signal Experience.RemoveModifier(modifier); Assert.AreEqual(6, _valueChangedEventTriggered); // Maximum and minimum signals are emitted too. Body.OnMaxReached += new MaxReachedHandler(MaxReachedDemo); Body.Value = 999; Assert.AreEqual(1, _maxReachedEventTriggered); Body.OnMinReached += new MinReachedHandler(MinReachedDemo); Body.Value = -100; Assert.AreEqual(1, _minReachedEventTriggered); // VolumeAttribute Test Life.OnValueChanged += new ValueChangedHandler(ValueChangedDemo); Life.Value = 10; Assert.AreEqual(9, _valueChangedEventTriggered); Life.OnMaxReached += new MaxReachedHandler(MaxReachedDemo); Life.Value = 999; Assert.AreEqual(2, _maxReachedEventTriggered); Life.OnMinReached += new MinReachedHandler(MinReachedDemo); Life.Value = -100; Assert.AreEqual(2, _minReachedEventTriggered); Body.BaseValue = 200; Assert.AreEqual(14, _valueChangedEventTriggered); }