public override void WriteCode(Work w)
 {
     if (w.Hour < 12)
     {
         Console.WriteLine("当前时间{0}点,工作状态良好", w.Hour);
     }
     else
     {
         w.State = new NoonState();
         w.WriteCode();
     }
 }
Пример #2
0
 public override void WriteCode(Work w)
 {
     if (w.Hour < 13)
     {
         Console.WriteLine("当前时间{0}点,饿了,吃饭午睡", w.Hour);
     }
     else
     {
         w.State = new AfternoonState();
         w.WriteCode();
     }
 }
 public override void WriteCode(Work w)
 {
     if (w.Hour < 17)
     {
         Console.WriteLine("当前时间{0}点,下午状态还不错,继续努力", w.Hour);
     }
     else
     {
         w.State = new EveningState();
         w.WriteCode();
     }
 }
 public override void WriteCode(Work w)
 {
     if (w.TaskFinished)
     {
         w.State = new RestState();
         w.WriteCode();
     }
     else
     {
         Console.WriteLine("当前时间{0}点,加班了,好累啊", w.Hour);
     }
 }
Пример #5
0
        static void Main(string[] args)
        {
            Work w = new Work();

            w.SetState();

            w.Hour = 10;
            w.WriteCode();

            w.Hour = 12;
            w.WriteCode();

            w.Hour = 15;
            w.WriteCode();

            w.Hour = 18;
            w.WriteCode();

            w.TaskFinished = true;
            w.WriteCode();

            Console.ReadKey();
        }