コード例 #1
0
ファイル: SimSchool.cs プロジェクト: ksucase/SimSchool
        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();
        }
コード例 #2
0
ファイル: CatSleepState.cs プロジェクト: ksucase/SimSchool
 /// <summary>
 /// Activities when leaving this state.
 /// </summary>
 /// <param name="inhabitant"></param>
 public void OnExit(Cat inhabitant)
 {
     Console.WriteLine("{{Stretch}} Waking up.");
 }
コード例 #3
0
ファイル: CatSleepState.cs プロジェクト: ksucase/SimSchool
 /// <summary>
 /// Activities when first entering this state.
 /// </summary>
 /// <param name="inhabitant">inhabitant</param>
 public void OnEnter(Cat inhabitant)
 {
     Console.WriteLine("Iz tireds.");
 }
コード例 #4
0
ファイル: CatSleepState.cs プロジェクト: ksucase/SimSchool
 /// <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
 }
コード例 #5
0
ファイル: CatEatState.cs プロジェクト: ksucase/SimSchool
 public void OnExit(Cat inhabitant)
 {
     Console.WriteLine("{{smilez}} That waz gud.");
 }
コード例 #6
0
ファイル: CatEatState.cs プロジェクト: ksucase/SimSchool
 public void OnEnter(Cat inhabitant)
 {
     Console.WriteLine("I can haz cheezburger? Pleez?");
 }
コード例 #7
0
ファイル: CatEatState.cs プロジェクト: ksucase/SimSchool
 /// <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
 }