diff --git "a/\351\237\246\344\270\275\346\261\237/JudgeMan.cs" "b/\351\237\246\344\270\275\346\261\237/JudgeMan.cs" new file mode 100644 index 0000000000000000000000000000000000000000..568d724c1961b16eaabdfd382942453ae627a3fd --- /dev/null +++ "b/\351\237\246\344\270\275\346\261\237/JudgeMan.cs" @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ConsoleApp8 +{ + class JudgeMan:Role + { + + } +} diff --git "a/\351\237\246\344\270\275\346\261\237/NPCMan.cs" "b/\351\237\246\344\270\275\346\261\237/NPCMan.cs" new file mode 100644 index 0000000000000000000000000000000000000000..67ce63499db8840f102fdbe628b164036d832f45 --- /dev/null +++ "b/\351\237\246\344\270\275\346\261\237/NPCMan.cs" @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ConsoleApp8 +{ + class NPCMan:Role + { + Random ran = new Random(); + public override int ShowFist() + { + return ran .Next (1,4); + } + } +} diff --git "a/\351\237\246\344\270\275\346\261\237/Player.cs" "b/\351\237\246\344\270\275\346\261\237/Player.cs" new file mode 100644 index 0000000000000000000000000000000000000000..56e351c605c50d1cf4228b87a54fe512c06a9725 --- /dev/null +++ "b/\351\237\246\344\270\275\346\261\237/Player.cs" @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ConsoleApp8 +{ + class Player:Role + { + public override int ShowFist() + { + int num = int.Parse(Console .ReadLine ()); + return num; + } + } +} diff --git "a/\351\237\246\344\270\275\346\261\237/Program.cs" "b/\351\237\246\344\270\275\346\261\237/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..93a269ff00fd7385fb73e6e48d40768201c4ed9f --- /dev/null +++ "b/\351\237\246\344\270\275\346\261\237/Program.cs" @@ -0,0 +1,173 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static System.Net.Mime.MediaTypeNames; + +namespace ConsoleApp3 +{ + public enum NPCRole + { + 刘备 = 1, + 孙权 , + 曹操 + } + public enum Fist + { + 石头 = 1, + 剪刀 , + 布 + } + class Program + { + static JudgeMan jm = new JudgeMan(); + static Player p = new Player(); + static NPCMan npc = new NPCMan(); + static int count = 0; + static int pCount = 0; + static int nCount = 0; + + static void Main(string[] args) + { + PlayFistGame(); + } + + private static void PlayFistGame() + { + Welcome(); + Prepare(); + Battle(); + ShowResult(); + } + + Console.WriteLine("....................................................................."); + private static void Welcome() + { + Console.WriteLine("====================......欢 迎 进 入 游 戏的 世 界...........====================\r\n"); + Console.WriteLine("************************************"); + Console.WriteLine("*************猜拳,开始啦啦啦!!!*************"); + Console.WriteLine("************************************\r\n"); + } + + private static void Prepare() + { + while (true) + { + Console.WriteLine("出拳规则:{0}", ListFist()); ; + Console.WriteLine("请选择对方角色:{0}", ListNPC()); + int num = int.Parse(Console.ReadLine()); + npc.Name = ((NPCRole)num).ToString(); + + Console.WriteLine("请输入您的姓名:"); + p.Name = Console.ReadLine(); + + Console.WriteLine("{0} VS {1} 对战", p.Name, npc.Name); + Console.WriteLine("开始游戏吗?(y/n)"); + string key = Console.ReadLine(); + if (key == "y") + { + break; + } + } + } + Console.WriteLine("....................................................................."); + + private static void Battle() + { + while (true) + { + Console.WriteLine("\n\r请出拳:{0}", ListFist()); + int pf = p.ShowFist(); + int nf = npc.ShowFist(); + Console.WriteLine("\r\n{0} 出: {1}", p.Name, (Fist)pf); + Console.WriteLine("{0} 出: {1}", npc.Name, (Fist)nf); + int result = IsWin(pf, nf); + + Console.WriteLine(); + Console.WriteLine(result == 0 ? "不可思议鸭,平局啦!!!" : result == 1 ? $"恭喜恭喜恭喜!!!{p.Name}赢了!" : $"太不好意思了!{p.Name}输了!"); + + count++; + if (result == 1) + { + pCount++; + } + else if (result == -1) + { + nCount++; + } + + Console.WriteLine("是否开始下一轮的猜拳活动呢?(y/n)"); + string key = Console.ReadLine(); + if (key != "y") + { + break; + } + } + } + + static void ShowResult() + { + Console.WriteLine("===================================================="); + Console.WriteLine("{0} VS {1}", p.Name, npc.Name); + Console.WriteLine("对战次数:{0}", count); + Console.WriteLine("姓名\t得分"); + Console.WriteLine("{0}\t{1}", p.Name, pCount); + Console.WriteLine("{0}\t{1}", npc.Name, nCount); + Console.WriteLine("平局\t{0}", count-nCount-pCount); + Console.WriteLine("总结果:" + (pCount > nCount ? p.Name : npc.Name) + "吼吼!!!赢了鸭鸭鸭!"); + Console.WriteLine("是否开始下一局的游戏呢?(y/n)"); + string key = Console.ReadLine(); + if (key == "y") + { + count = 0; + pCount = 0; + nCount = 0; + PlayFistGame(); + } + else + { + Console.WriteLine("系统要退出了!!!"); + } + } + Console.WriteLine("....................................................................."); + + + private static int IsWin(int pf, int nf) + { + if (pf == nf) + { + return 0; + } + else if (pf == 1 && nf == 2 || pf == 2 && nf == 3 || pf == 3 && nf == 1) + { + return 1; + } + else + { + return -1; + } + } + + static string ListFist() + { + string fistStr = ""; + foreach (Fist f in Enum.GetValues(typeof(Fist))) + { + fistStr += (int)f + "、" + f + ";"; + } + return fistStr; + } + Console.WriteLine("....................................................................."); + static string ListNPC() + { + string roleStr = ""; + foreach (NPCRole n in Enum.GetValues(typeof(NPCRole))) + { + roleStr += (int)n + "、" + n + ";"; + } + return roleStr; + } + + } +} diff --git "a/\351\237\246\344\270\275\346\261\237/Role.cs" "b/\351\237\246\344\270\275\346\261\237/Role.cs" new file mode 100644 index 0000000000000000000000000000000000000000..ec224e2697a0c77e16b9cc770fd4d1cebf38acf9 --- /dev/null +++ "b/\351\237\246\344\270\275\346\261\237/Role.cs" @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ConsoleApp8 +{ + class Role + { + public string Name { get; set; } + public virtual int ShowFist() + { + + return 0; + } + } +}