public void StartCommand()
        {
            Alien a;

            a.X     = 50;
            a.Y     = 50;
            a.Lives = 3;
            Console.WriteLine("without constructor a {0}", a.ToString());

            Alien x = new Alien(100, 100);

            Console.WriteLine("with constructor x {0}", x.ToString());

            Alien[] swarm    = new Alien[5];
            int     position = 0;

            foreach (var alien in swarm)
            {
                Console.WriteLine("swarm [{0}] {1}", position++, alien.ToString());
            }

            Console.WriteLine("--------------------------------------------");

            AlienClass[] swarmClass = new AlienClass[5];
            position = 0;
            foreach (var alien in swarmClass)
            {
                Console.WriteLine("swarm [{0}] {1} I am null, one problem with that?!", position++, alien?.ToString());
            }

            Console.ReadKey();
        }
Exemplo n.º 2
0
        // The	basis	of	C#	reference	types	is	the	C#	class.	A	class	is	declared	in	a	very similar
        // manner	to	a	structure,	but	the	way	that	classes	are	manipulated	in	a program	is	significantly	different.
        // The	use	of	the	new	keyword to	create	a	new	object	is	said	to	create	a	new	instance	of	a	class.
        public void CreateReference()
        {
            AlienClass x = new AlienClass(100, 100);

            Console.WriteLine("x	{0}", x);
            AlienClass[] swarm = new AlienClass[100];
            for (int i = 0; i < swarm.Length; i++)
            {
                swarm[i] = new AlienClass(0, 0);
            }

            Console.WriteLine("swarm	[0]	{0}", swarm[0]);
        }
 /**
  * Give alien secondary objectives of their human class
  *
  * Arguments
  * - AlienClass alienClass - The alien class
  * - GameObject secondaries - The container for the player's secondary objectives
  */
 void giveAlienSecondaryHumanObj(AlienClass alienClass, GameObject secondaries)
 {
     switch (alienClass.GetHumanClassType()) {
     case Classes.SCOUT: // Scout
         Debug.Log("Adding scout secondary");
         secondaries.AddComponent<ScoutSecondaryOne>();
         break;
     case Classes.ENGINEER: // Engineer
         Debug.Log("Adding engineer secondary");
         secondaries.AddComponent<EngineerSecondaryOne>();
         break;
     case Classes.MARINE: // Marine
         Debug.Log("Adding marine secondary");
         secondaries.AddComponent<MarineSecondaryOne>();
         break;
     case Classes.TECHNICIAN: // Technician
         Debug.Log("Adding Technician secondary");
         secondaries.AddComponent<TechnicianSecondaryOne>();
         break;
     }
 }
Exemplo n.º 4
0
        public static void TestAlienClass()
        {
            /* When the new keyword is used to create an instance of a class the following sequence is performed:
             * 1. The program code that implements the class is loaded into memory, if it is not already present.
             * 2. If this is the first time that the class has been referenced, any static members of the class
             *  are initialized and the static constructor is called.
             * 3. The constructor in the class is called. */

            AlienClass x = new AlienClass(100, 100);

            Console.WriteLine("x {0}", x);

            AlienClass[] swarm = new AlienClass[100];

            for (int i = 0; i < swarm.Length; i++)
            {
                swarm[i] = new AlienClass(0, 0);
            }

            Console.WriteLine("swarm [0] {0}", swarm[0]);
        }
 /**
  * Set the text of the class title for the alien
  *
  * Arguments
  * - AlienClass alienClass - The alien class
  */
 void setClassTitleForAlien(AlienClass alienClass)
 {
     ClassTitle.text = "Alien (";
     switch (alienClass.GetHumanClassType()) {
     case Classes.ENGINEER:
         ClassTitle.text += "Engineer)";
         break;
     case Classes.MARINE:
         ClassTitle.text += "Marine)";
         break;
     case Classes.SCOUT:
         ClassTitle.text += "Scout)";
         break;
     case Classes.TECHNICIAN:
         ClassTitle.text += "Technician)";
         break;
     default:
         throw new System.NotSupportedException("Invalid human class");
     }
 }