예제 #1
0
        private static void Main(string[] args)
        {
            Work work = new Work();
            work.Hour = 9;
            work.WriteProgram();

            work.Hour = 10;
            work.WriteProgram();

            work.Hour = 11;
            work.WriteProgram();

            work.Hour = 12;
            work.WriteProgram();

            work.Hour = 13;
            work.WriteProgram();

            work.Hour = 14;
            work.WriteProgram();

            work.Hour = 15;
            work.WriteProgram();

            work.Hour = 16;
            work.WriteProgram();

            work.Hour = 17;
            work.WriteProgram();

            //第一步开始
            work.TaskFinished = true;
            //第一步结束

            //第二步开始
            //w.TaskFinished = false;
            //第二步结束

            work.Hour = 18;
            work.WriteProgram();

            work.Hour = 19;
            work.WriteProgram();

            work.Hour = 20;
            work.WriteProgram();

            work.Hour = 21;
            work.WriteProgram();

            work.Hour = 22;
            work.WriteProgram();

            Console.ReadLine();
        }
 public override void WriteProgram(Work work)
 {
     if (work.Hour < 13)
     {
         Console.WriteLine("当前时间:{0}点 饿了,午饭;犯困,午休。", work.Hour);
     }
     else
     {
         work.SetState(new AfternoonState());
         work.WriteProgram();
     }
 }
 public override void WriteProgram(Work work)
 {
     if (work.Hour < 12)
     {
         Console.WriteLine("当前时间:{0}点 上午工作,精神百倍", work.Hour);
     }
     else
     {
         work.SetState(new NoonState());
         work.WriteProgram();
     }
 }
 public override void WriteProgram(Work work)
 {
     if (work.Hour < 17)
     {
         Console.WriteLine("当前时间:{0}点 下午状态还不错,继续努力。", work.Hour);
     }
     else
     {
         work.SetState(new EveningState());
         work.WriteProgram();
     }
 }
 public override void WriteProgram(Work work)
 {
     if (work.TaskFinished)
     {
         work.SetState(new RestState());
         work.WriteProgram();
     }
     else
     {
         if (work.Hour < 21)
         {
             Console.WriteLine("当前时间{0}点 加班哦,疲劳之极", work.Hour);
         }
         else
         {
             work.SetState(new SleepingState());
             work.WriteProgram();
         }
     }
 }
예제 #6
0
 public abstract void WriteProgram(Work work);
 public override void WriteProgram(Work work)
 {
     Console.WriteLine("当前时间:{0}点 不行了,睡着了", work.Hour);
 }
 public override void WriteProgram(Work work)
 {
     Console.WriteLine("当前时间{0}点 下班回家了", work.Hour);
 }
예제 #9
0
 public abstract void WriteProgram(Work work);