예제 #1
0
 /// <summary>
 /// Create a Character with the specified health, ammo, and weapon objects, plus the given name
 /// </summary>
 /// <param name="health">CharacterStatusElement for health</param>
 /// <param name="ammo">CharacterStatusElement for ammo</param>
 /// <param name="weapon">CharacterStatusElement for the current weapon</param>
 /// <param name="name">The character's name</param>
 /// <param name="collisionDetector">Collision detector with which this object should register.</param>
 public CharacterAbstract(CharacterHealth health, CharacterAmmo ammo, CharacterWeapon weapon, string name, CollisionDetectorInterface collisionDetector)
     : base()
 {
     health_ = health;
     ammo_ = ammo;
     weapon_ = weapon;
     name_ = name;
     collisionDetector_ = collisionDetector;
     if (collisionDetector_ != null)
     {
         collisionDetector_.register(this);
     }
     height_ = new Height(true, true);
     Inventory_ = new Inventory();
 }
        public void TestNotify()
        {
            CharacterHealth instance = new CharacterHealth();
            CharacterStatusObserverConcreteTester observer = new CharacterStatusObserverConcreteTester();

            instance.addObserver(observer);
            instance.update(50);

            Assert.AreEqual(50, observer.getValue());
            instance.update(60);

            Assert.AreEqual(60, observer.getValue());

            CharacterStatusObserverConcreteTester observer2 = new CharacterStatusObserverConcreteTester();
            CharacterStatusObserverConcreteTester observer3 = new CharacterStatusObserverConcreteTester();
            CharacterStatusObserverConcreteTester observer4 = new CharacterStatusObserverConcreteTester();

            instance.addObserver(observer2);
            instance.addObserver(observer3);
            instance.addObserver(observer4);

            instance.update(71);

            Assert.AreEqual(71, observer.getValue());
            Assert.AreEqual(71, observer2.getValue());
            Assert.AreEqual(71, observer3.getValue());
            Assert.AreEqual(71, observer4.getValue());

            instance.update(72);
            instance.update(73);

            Assert.AreEqual(73, observer.getValue());
            Assert.AreEqual(73, observer2.getValue());
            Assert.AreEqual(73, observer3.getValue());
            Assert.AreEqual(73, observer4.getValue());
        }
예제 #3
0
 public void setHealth(CharacterHealth health)
 {
     health_ = health;
 }
예제 #4
0
 /// <summary>
 /// Create a Character with the specified health, ammo, and weapon objects, plus the given name.
 /// Also, specify the AnimationSet, frameLengthModifier, velocity, position, direction,
 /// and depth of the character.
 /// </summary>
 /// <param name="pipeline">List of objects from which the object should be drawn.</param>
 /// <param name="health">CharacterStatusElement for health</param>
 /// <param name="ammo">CharacterStatusElement for ammo</param>
 /// <param name="weapon">CharacterStatusElement for the current weapon</param>
 /// <param name="name">The character's name</param>
 /// <param name="collisionDetector">Collision detector with which this object should register.</param>
 /// <param name="animations">AnimationSet containing all animations for this object</param>
 /// <param name="frameLengthModifier">Float representing the ratio of frames in an animation to movement along the screen</param>
 /// <param name="velocity">Vector of velocity, representing both direction of movement and magnitude</param>
 /// <param name="position">Position of object relative to the top left corner</param>
 /// <param name="direction">Vector representing the direction of the object</param>
 /// <param name="depth">Depth the object is to be drawn to</param>
 public CharacterAbstract(List<DrawableObjectAbstract> pipeline, CharacterHealth health, CharacterAmmo ammo, CharacterWeapon weapon, string name, CollisionDetectorInterface collisionDetector, AnimationSet animations, float frameLengthModifier, Vector2 velocity, Vector2 position, Vector2 direction, float depth)
     : base(pipeline, animations, frameLengthModifier, velocity, position, direction, depth)
 {
     health_ = health;
     ammo_ = ammo;
     weapon_ = weapon;
     name_ = name;
     collisionDetector_ = collisionDetector;
     if (collisionDetector_ != null)
     {
         collisionDetector_.register(this);
     }
     height_ = new Height(true, true);
     Inventory_ = new Inventory();
 }
 /// <summary>
 /// Create a PlayableCharacter with the specified health, ammo, and weapon objects, plus the given name.
 /// Also, specify the AnimationSet, frameLengthModifier, velocity, position, direction,
 /// and depth of the character.
 /// </summary>
 /// <param name="pipeline">Drawing pipeline in which to register the object</param>
 /// <param name="health">CharacterStatusElement for health</param>
 /// <param name="ammo">CharacterStatusElement for ammo</param>
 /// <param name="weapon">CharacterStatusElement for the current weapon</param>
 /// <param name="name">The character's name</param>
 /// <param name="detector">Collision detector with which the object should register.</param>
 /// <param name="animations">AnimationSet containing all animations for this object</param>
 /// <param name="frameLengthModifier">Float representing the ratio of frames in an animation to movement along the screen</param>
 /// <param name="velocity">Vector of velocity, representing both direction of movement and magnitude</param>
 /// <param name="position">Position of object relative to the top left corner</param>
 /// <param name="direction">Vector representing the direction of the object</param>
 /// <param name="depth">Depth the object is to be drawn to</param>
 public PlayableCharacterAbstract(List<DrawableObjectAbstract> pipeline, CharacterHealth health, CharacterAmmo ammo, CharacterWeapon weapon, string name, CollisionDetectorInterface detector, AnimationSet animations, float frameLengthModifier, Vector2 velocity, Vector2 position, Vector2 direction, float depth)
     : base(pipeline, health, ammo, weapon, name, detector, animations, frameLengthModifier, velocity, position, direction, depth)
 {
 }
 /// <summary>
 /// Create a PlayableCharacter with the specified health, ammo, and weapon objects, plus the given name
 /// </summary>
 /// <param name="health">CharacterStatusElement for health</param>
 /// <param name="ammo">CharacterStatusElement for ammo</param>
 /// <param name="weapon">CharacterStatusElement for the current weapon</param>
 /// <param name="name">The character's name</param>
 /// <param name="detector">Collision detector with which this object will register.</param>
 public PlayableCharacterAbstract(CharacterHealth health, CharacterAmmo ammo, CharacterWeapon weapon, string name, CollisionDetectorInterface detector)
     : base(health, ammo, weapon, name, detector)
 {
 }