C#:控制台数绵羊小程序

2021-07-16 06:12

阅读:645

标签:div   lease   number   blog   lock   body   stat   put   you   

偶尔无聊,写了个数绵羊程序逗逗自己

简介:输入一个整数进行数绵羊

大致流程图:

技术分享图片

效果:

技术分享图片

技术分享图片

代码如下:

 1     class Program
 2     {
 3         static void Main(string[] args)
 4         {
 5             GetNumber();
 6             Console.ReadKey();
 7         }           
 8         public static void GetNumber()
 9         {
10             bool exit = false;
11             Console.WriteLine("Please input moutons number:");
12             string input = Console.ReadLine();
13             int n = -1;
14             while (true)
15             {
16                 if (int.TryParse(input, out n) && n > 0)
17                 {
18                     if(n>=5) break;
19                     if(n==1)
20                         Console.WriteLine($"Only {n} ,are you kidding me? I don‘t count...");  
21                     else
22                         Console.WriteLine($"I don‘t count...jajajajaja...");
23                 }
24                 else
25                     Console.WriteLine("Rules:moutons number should be greater than 0.");
26                 Console.WriteLine("Please input moutons number again or input ‘exit‘ go to sleep:");
27                 input = Console.ReadLine();
28                 if (input.Trim() == "exit")
29                 {
30                     exit = true;
31                     break;
32                 }
33             }
34             if (!exit)
35                 Clock(n);
36             else
37                 Msg();
38         }                
39         public static void Clock(int n)
40         {
41             int i = 1;
42             while(in)
43             {
44                 Console.WriteLine($"{i} 只 moutons..zzz");
45                 i++;
46                 Thread.Sleep(2000);
47             }
48             Console.WriteLine("Bonne nuit, les moutons comptent.");
49             Msg();
50         }
51         public static void Msg()
52         {
53             int now = DateTime.Now.Hour;
54             if (now 5)
55             {
56                 Console.WriteLine($"It‘s {now} o‘clock in the morning,you should go to bed.");
57             }
58             else if (now 12)
59             {
60                 Console.WriteLine("Good morning.");
61             }
62             else if (now 18)
63             {
64                 Console.WriteLine("Good afternoon.");
65             }
66             else if (now 22)
67             {
68                 Console.WriteLine("Good evening");
69             }
70             else
71             {
72                 Console.WriteLine($"It‘s {now} O ‘ time, you should go to bed.");
73             }
74         }
75     }

 

C#:控制台数绵羊小程序

标签:div   lease   number   blog   lock   body   stat   put   you   

原文地址:https://www.cnblogs.com/ecake/p/8214749.html


评论


亲,登录后才可以留言!