0

This may be something fairly trivial, but I've decided to jump feet first into this and don't quite understand how to handle this.

   private void OnBattleUpdate(object sender, ElapsedEventArgs e)
    {
        if (monster.IsAlive)
        {
            ActionResult result = monster.GetAttackResult();
            messages.Add(result.LookMessage);
            state.Character.CauseDamage(result.HealthChange);
            if (state.Character.Health <= 0)
            {
                messages.Add("You are dead.");
            }

            int playerDamage = state.Character.GetDamage().HealthChange;
            messages.Add(String.Format("You swing your sword at {0} and cause {1} damage", monster.Name, playerDamage));
            monster.CauseDamage(playerDamage);
            messages.Add(String.Format("Health : {0}/{1}", state.Character.Health, state.Character.MaxHealth));
        }
        else
        {
            messages.Add(String.Format("{0} is dead.", monster.Name));
            state.Character.Gold += monster.Gold;
            mapManager.RemoveMonster(monster, mapManager.MapName);
            battleTimer.Stop();
        }
    }

The code to handle "IsAlive"

    private bool _isAlive;
    public bool IsAlive
    {
        get { return _isAlive; }
        set
        {
            if (Health > 0)
            {
                _isAlive = true;
            }
            else
            {
                _isAlive = false;
            }
        }
    }

Am I just approaching this the wrong way? Any tips that you all can provide would be extremely helpful :)

Kael
  • 1
  • 1
  • 2
    [What is NullReference and how do I fix it](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Andy Korneyev Apr 14 '15 at 16:30
  • Okay, I managed to find a solution in making the _isAlive variable public. I'm not 100% sure why that occurred, or even why it ended up fixing itself. But either way, its been taken care of. Thanks all! – Kael Apr 14 '15 at 21:47

0 Answers0