1. 程式人生 > >C#:控制臺數綿羊小程序

C#:控制臺數綿羊小程序

true clock .com == 輸入 ons info class ood

偶爾無聊,寫了個數綿羊程序逗逗自己

簡介:輸入一個整數進行數綿羊

大致流程圖:

技術分享圖片

效果:

技術分享圖片

技術分享圖片

代碼如下:

 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(i<=n) 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#:控制臺數綿羊小程序