コード例 #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
 public void Execute(GraduateStudent inhabitant)
 {
     inhabitant.Display("{{read, study, read study}} doing research....");
     inhabitant.ChangeState(new GraduateStudentSleepState());
 }
コード例 #3
0
 public void OnExit(GraduateStudent inhabitant)
 {
     Console.WriteLine("{{arrgghhhh}} Nothing is working!");
 }
コード例 #4
0
 public void OnEnter(GraduateStudent inhabitant)
 {
     Console.WriteLine("Oh oh better get started.");
 }
コード例 #5
0
 public void Execute(GraduateStudent inhabitant)
 {
     inhabitant.Display("{{snoozing}}  ZZzzz ZZZzzz ");
     inhabitant.ChangeState(new GraduateStudentDoResearchState());
 }
コード例 #6
0
 public void OnExit(GraduateStudent inhabitant)
 {
     Console.WriteLine("{{zzz}} What! Morning already!");
 }
コード例 #7
0
 public void OnEnter(GraduateStudent inhabitant)
 {
     Console.WriteLine("{{Yawn}} I need some sleep.");
 }