GAM456-SpaceInvaders / SpaceInvaders / 4_GameObject / ObjectNode.cs
ObjectNode.cs
Raw
using System;
using System.Diagnostics;


namespace SpaceInvaders
{
    public class ObjectNode : DLink
    {
        //-------------------------------------------------------------------
        //  FIELDS
        //-------------------------------------------------------------------

        private GameObject pObject;


        //-------------------------------------------------------------------
        //  CONSTRUCTION
        //-------------------------------------------------------------------

        public ObjectNode() : base()
        {
            this.Clear();
        }


        //-------------------------------------------------------------------
        //  PUBLIC METHODS
        //-------------------------------------------------------------------

        public void SetObject(GameObject pObject)
        {
            Debug.Assert(pObject != null);
            this.pObject = pObject;
        }

        public GameObject GetObject()
        {
            return this.pObject;
        }

        public override bool Compare(Node pNode)
        {
            Debug.Assert(pNode != null);
            ObjectNode pObj2 = (ObjectNode)pNode;

            Debug.Assert(pObj2.pObject != null);
            Debug.Assert(this.pObject != null);

            if (this.pObject.name == pObj2.pObject.name)
            {
                return true;
            }

            return false;
        }

        public override object GetName()
        {
            Debug.Assert(this.pObject != null);
            return this.pObject.GetName();
        }

        public override void Reset()
        {
            this.Clear();
        }

        public override void PrintStats()
        {
            Debug.WriteLine("GameObjectNode: ({0})", this.GetHashCode());

            if (this.pObject != null)
            {
                Debug.WriteLine("GameObject.name: {0} ({1})", this.pObject.GetName(), this.pObject.GetHashCode());
            }
            else
            {
                Debug.WriteLine("GameObject.name: null");
            }

            base.PrintStats();
        }


        //-------------------------------------------------------------------
        //  PRIVATE METHODS
        //-------------------------------------------------------------------

        private void Clear()
        {
            this.pObject = null;
        }


    }
}