Page 1 of 1

(C#) A Useful Health Class

Posted: Sun Jun 10, 2007 10:07 pm
by flipnode
Comments on this .NET class that I've created? Good design or Bad? Am I missing anything?

Helpful comments requested, please.

Code: Select all

using System;

namespace BloodRage
{
    namespace Core
    {
        class BRHealth
        {
            protected int _Health = 0;
            protected int _Death = 0;
            protected int _FullHealth = 0;
            protected bool _Alive = false;

            public bool IsAlive
            {
                get { return (this._Alive); }
            }

            public int Health
            {
                get { return (this._Health); }
                set { UpdateHealth(value); }
            }

            // constructor
            public BRHealth(int health, int death, int fullHealth)
            {
                this.Init(health, death, fullHealth);
            }

            // Deconstructor
            ~BRHealth()
            {
            }

            private bool Init(int health, int death, int fullHealth)
            {
                //if(health < death || fullHealth < death)
                //{
                //    throw
                //}
                this._Health = health;
                this._Death = death;
                this._FullHealth = fullHealth;

                // IsAlive?
                return(this.CheckHealth());
            }
                        
            private void UpdateHealth(int health)
            {
                this._Health = health;
                this.CheckHealth();
            }

            protected bool CheckHealth()
            {
                // false : oh crap he is dead!
                // true  : yup heart is still beating!
                return(this._Alive = (this._Health == this._Death ? false : true));                
            }
        }
    }
}

Posted: Mon Jun 11, 2007 3:18 am
by Dorth
Well, technically your Health could go under Death and since you check

protected bool CheckHealth()
{
// false : oh crap he is dead!
// true : yup heart is still beating!
return(this._Alive = (this._Health == this._Death ? false : true));
}

with == you might miss it... better check like you do above, with <=

Posted: Mon Jun 11, 2007 11:18 am
by lester
you've certainly missed the public void TurnUndead() function

Posted: Wed Jun 13, 2007 12:47 pm
by flipnode
You are correct. I missed that <= logic. I think that thought popped into my head, but I forgot to code it.

Hmm you might be right about the TurnUndead() function.
I'll add that to the class.

Anything else?

Posted: Thu Jun 14, 2007 4:59 pm
by lester
lol I was just kidding about TurnUndead. Maybe I should be more cautious in sentences :-/