Esempio n. 1
0
        static void Main(string[] args)
        {
            // set how long to run the virtual world
            const int NUMBER_OF_MOVES = 5;

            // start with an empty list of generic inhabitants
            List<AbstractInhabitant> inhabitantList = new List<AbstractInhabitant>();

            // add a new graduate student to the list
            GraduateStudent denise = new GraduateStudent("Graduate Student Denise");
            inhabitantList.Add(denise);

            // add a new professor instance to the list
            Professor profCase = new Professor("Prof Case");
            inhabitantList.Add(profCase);

            // add a new cat instance to the list
            Cat bill = new Cat("Bill the Cat");
            inhabitantList.Add(bill);

            // add a programmer instance to the list
            Programmer josh = new Programmer("Josh");
            inhabitantList.Add(josh);

            // add a new type of character to the list

            //TODO: add your code here

            // startup each inhabitant on the list
            foreach (AbstractInhabitant inhabitant in inhabitantList)
            {
                inhabitant.Start();
            }

            //display a blank line just for readability
            Console.WriteLine();

            // run the virtual world
            for (int i = 0; i <= NUMBER_OF_MOVES; i++)
            {
                //display what move we're on
                Console.WriteLine(i);

                // have each inhabitant execute their updated state
                foreach (AbstractInhabitant inhabitant in inhabitantList)
                    inhabitant.Execute();

                //display a blank line just for readability
                Console.WriteLine();
            }

            // virtual world is winding down - have the inhabitants finish up
            foreach (AbstractInhabitant inhabitant in inhabitantList)
            {
                inhabitant.Finish();
            }

            // keep the command window open
            Console.Read();
        }
Esempio n. 2
0
 /// <summary>
 /// Activities when leaving this state.
 /// </summary>
 /// <param name="inhabitant"></param>
 public void OnExit(Cat inhabitant)
 {
     Console.WriteLine("{{Stretch}} Waking up.");
 }
Esempio n. 3
0
 /// <summary>
 /// Activities when first entering this state.
 /// </summary>
 /// <param name="inhabitant">inhabitant</param>
 public void OnEnter(Cat inhabitant)
 {
     Console.WriteLine("Iz tireds.");
 }
Esempio n. 4
0
 /// <summary>
 /// Activities when executing this state including
 /// what state to transition to at the end.
 /// </summary>
 /// <param name="inhabitant">inhabitant</param>
 public void Execute(Cat inhabitant)
 {
     inhabitant.Display("{{ZZZZZ}} sleeping....");
     inhabitant.ChangeState(new CatEatState());   // move to cat's eat state
 }
Esempio n. 5
0
 public void OnExit(Cat inhabitant)
 {
     Console.WriteLine("{{smilez}} That waz gud.");
 }
Esempio n. 6
0
 public void OnEnter(Cat inhabitant)
 {
     Console.WriteLine("I can haz cheezburger? Pleez?");
 }
Esempio n. 7
0
 /// <summary>
 /// Activities when executing this state including
 /// what state to transition to at the end.
 /// </summary>
 /// <param name="inhabitant">inhabitant</param>
 public void Execute(Cat inhabitant)
 {
     inhabitant.Display("...nom nom nom....");
     inhabitant.ChangeState(new CatSleepState());  // move to cat's sleep state
 }