예제 #1
0
        static void Main(string[] args)
        {
            //紧急项目
            Work emergencyProjects = new Work();
            emergencyProjects.Hour = 9;
            emergencyProjects.WriteProgram();
            emergencyProjects.Hour = 10;
            emergencyProjects.WriteProgram();
            emergencyProjects.Hour = 12;
            emergencyProjects.WriteProgram();
            emergencyProjects.Hour = 13;
            emergencyProjects.WriteProgram();
            emergencyProjects.Hour = 14;
            emergencyProjects.WriteProgram();
            emergencyProjects.Hour = 17;

            //emergencyProjects.WorkFinished = true;
            emergencyProjects.TaskFinished = false;

            emergencyProjects.WriteProgram();
            emergencyProjects.Hour = 19;
            emergencyProjects.WriteProgram();
            emergencyProjects.Hour = 22;
            emergencyProjects.WriteProgram();

            Console.Read();
        }
예제 #2
0
 public override void WriteProgram(Work w)
 {
     if (w.TaskFinished)
     {
         w.SetState(new RestState());
         w.WriteProgram();
     }
     else
     {
         if (w.Hour < 21)
         {
             Console.WriteLine("当前时间:{0}点 加班哦,疲累之极", w.Hour);
         }
         else
         {
             w.SetState(new SleepingState());
             w.WriteProgram();
         }
     }
 }
예제 #3
0
 public override void WriteProgram(Work w)
 {
     if (w.Hour < 17)
     {
         Console.WriteLine("当前时间:{0}点 下午状态还不错,继续努力", w.Hour);
     }
     else
     {
         w.SetState(new EveningState());
         w.WriteProgram();
     }
 }
예제 #4
0
 public override void WriteProgram(Work w)
 {
     if (w.Hour < 13)
     {
         Console.WriteLine("当前时间:{0}点 饿了,午饭;犯困,午休。", w.Hour);
     }
     else
     {
         w.SetState(new AfternoonState());
         w.WriteProgram();
     }
 }
예제 #5
0
 public override void WriteProgram(Work w)
 {
     if (w.Hour < 12)
     {
         Console.WriteLine("当前时间:{0}点 上午工作,精神百倍", w.Hour);
     }
     else
     {
         w.SetState(new NoonState());
         w.WriteProgram();
     }
 }
예제 #6
0
 public override void WriteProgram(Work w)
 {
     if (w.Hour < 12)
     {
         Console.WriteLine("当前时间:{0}点 上午工作,精神百倍", w.Hour);
     }
     else
     {
         w.SetState(new NoonState());
         w.WriteProgram();
     }
 }
예제 #7
0
 public override void WriteProgram(Work w)
 {
     if (w.Hour < 17)
     {
         Console.WriteLine("当前时间:{0}点 下午状态还不错,继续努力", w.Hour);
     }
     else
     {
         w.SetState(new EveningState());
         w.WriteProgram();
     }
 }
예제 #8
0
파일: Program.cs 프로젝트: niuniuliu/CSharp
 public override void WriteProgram(Work w)
 {
     if (w.Hour < 13)
     {
         Console.WriteLine("当前时间:{0}点 饿了,午饭;犯困,午休。", w.Hour);
     }
     else
     {
         w.SetState(new AfternoonState());
         w.WriteProgram();
     }
 }
 public override void WriteProgram(Work w)
 {
     if (w.Hour < 13)
     {
         Console.WriteLine("当前时间:{0}点 饿了,午饭;犯困,午休.", w.Hour);
     }
     else
     {
         w.SetState(new AfternoonState());
         w.WriteProgram();
     }
 }
예제 #10
0
 public override void WriteProgram(Work w)
 {
     if (w.TaskFinished)
     {
         w.SetState(new RestState());
         w.WriteProgram();
     }
     else
     {
         if (w.Hour < 21)
         {
             Console.WriteLine("当前时间:{0}点 加班哦,疲惫之极.", w.Hour);
         }
         else
         {
             w.SetState(new SleepingState());
             w.WriteProgram();
         }
     }
     Console.WriteLine("");
 }
예제 #11
0
        //static int Hour = 0; //钟点
        //static bool WorkFinished = false; //任务完成标记
        //public static void WriteProgram()
        //{
        //    if (Hour < 12)
        //    {
        //        Console.WriteLine("当前时间: {0}点 上午工作, 精神百倍", Hour);
        //    }
        //    else if (Hour < 13)
        //    {
        //        Console.WriteLine("当前时间: {0}点 饿了, 午饭;犯困, 午休", Hour);
        //    }
        //    else if (Hour < 17)
        //    {
        //        Console.WriteLine("当前时间: {0}点 下午状态还不错, 继续努力", Hour);
        //    }
        //    else
        //    {
        //        if (WorkFinished)
        //        {
        //            Console.WriteLine("当前时间: {0}点 下班回家了", Hour);
        //        }
        //        else
        //        {
        //            if (Hour < 21)
        //            {
        //                Console.WriteLine("当前时间: {0}点 加班哦, 疲累之极", Hour);
        //            }
        //            else
        //            {
        //                Console.WriteLine("当前时间: {0}点 不行了, 睡着了。", Hour);
        //            }
        //        }
        //    }
        //}
        //static void Main(string[] args)
        //{
        //    Hour = 9;
        //    WriteProgram();
        //    Hour = 10;
        //    WriteProgram();
        //    Hour = 11;
        //    WriteProgram();
        //    Hour = 12;
        //    WriteProgram();
        //    Hour = 13;
        //    WriteProgram();
        //    Hour = 14;
        //    WriteProgram();
        //    Hour = 17;
        //    WriteProgram();

        //    WorkFinished = true;
        //    //WorkFinished = false;

        //    WriteProgram();
        //    Hour = 19;
        //    WriteProgram();
        //    Hour = 22;
        //    WriteProgram();

        //    Console.Read();
        //}
        #endregion

        #region 使用面向对象实现,糟糕的长函数WriteProgram()
        static void Main(string[] args)
        {
            Work emergencyProjects = new Work();

            emergencyProjects.Hour = 9;
            emergencyProjects.WriteProgram();
            emergencyProjects.Hour = 10;
            emergencyProjects.WriteProgram();
            emergencyProjects.Hour = 12;
            emergencyProjects.WriteProgram();
            emergencyProjects.Hour = 13;
            emergencyProjects.WriteProgram();
            emergencyProjects.Hour = 14;
            emergencyProjects.WriteProgram();
            emergencyProjects.Hour = 17;
            emergencyProjects.WriteProgram();

            //emergencyProjects.TaskFinished = true;
            emergencyProjects.TaskFinished = false;

            emergencyProjects.WriteProgram();
            emergencyProjects.Hour = 19;
            emergencyProjects.WriteProgram();
            emergencyProjects.Hour = 20;
            emergencyProjects.WriteProgram();
            emergencyProjects.Hour = 21;
            emergencyProjects.WriteProgram();
            emergencyProjects.Hour = 22;
            emergencyProjects.WriteProgram();
            emergencyProjects.Hour = 23;
            emergencyProjects.WriteProgram();

            Console.Read();
        }