From 332f06c97be44bf851a069e2f47cc9753a026b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=89=91=E9=98=B3?= <2998018776@qq.com> Date: Tue, 8 Jun 2021 08:52:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E5=BE=90=E5=89=91?= =?UTF-8?q?=E9=98=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\345\276\220\345\211\221\351\230\263/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/.keep" diff --git "a/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/.keep" "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From c321415fcb64eb332cc9ba9b2a4e5be38c7464ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=89=91=E9=98=B3?= <2998018776@qq.com> Date: Tue, 8 Jun 2021 08:53:00 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=BE=90=E5=89=91=E9=98=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GameSystem.cs" | 146 ++++++++++++++++++ .../Hero.cs" | 35 +++++ .../Person.cs" | 27 ++++ .../Program.cs" | 90 +++++++++++ .../User.cs" | 40 +++++ 5 files changed, 338 insertions(+) create mode 100644 "\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/GameSystem.cs" create mode 100644 "\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/Hero.cs" create mode 100644 "\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/Person.cs" create mode 100644 "\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/Program.cs" create mode 100644 "\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/User.cs" diff --git "a/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/GameSystem.cs" "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/GameSystem.cs" new file mode 100644 index 0000000..f0d55e0 --- /dev/null +++ "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/GameSystem.cs" @@ -0,0 +1,146 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + class GameSystem + { + + public bool Gaming(Hero hero, User user) + { + int sum = 0; + int hNum = 0; + int uNum = 0; + while (true) + { + string heroAction; + string userAction; + userAction = user.Action(); + Console.WriteLine(user.Name + ": 出拳: " + userAction); + heroAction = hero.Action(); + Console.WriteLine(hero.Name + ": 出拳: " + heroAction); + Console.WriteLine(IsWin(heroAction, userAction, user.Name, ref hNum, ref uNum)); + sum++; + while (true) + { + Console.WriteLine("是否开始下一轮?(1.继续/0.停止)"); + string chioce = Console.ReadLine(); + if (chioce == "1") + { + break; + } + else if (chioce == "0") + { + return EndGame(hero.Name, user.Name, sum, hNum, uNum); + } + else + { + Console.WriteLine("输入错误,请重新输入"); + continue; + } + } + } + } + + private bool EndGame(string heroName, string userName, int sum, int hNum, int uNum) + { + Console.WriteLine("==================================="); + Console.WriteLine("对战次数:" + sum); + + Console.WriteLine("姓名\t得分"); + Console.WriteLine(heroName + "\t" + hNum); + Console.WriteLine(userName + "\t" + uNum); + if (hNum > uNum) + { + Console.WriteLine($"{heroName}赢了,{userName}输了"); + } + else if (hNum < uNum) + { + Console.WriteLine($"{userName}赢了,{heroName}输了"); + } + else + { + Console.WriteLine("平局"); + } + while (true) + { + Console.WriteLine("要开始下一局吗?(y/n)"); + string chioce = Console.ReadLine(); + switch (chioce) + { + case "y": + return true; + case "n": + return false; + default: + Console.WriteLine("选择错误,请重新输入"); + continue; + } + } + } + + public string IsWin(string A, string B, string name, ref int hNum, ref int uNum) + { + string str; + if ((A == "剪刀" && B == "布") || (A == "石头" && B == "剪刀") || A == "布" && B == "石头") + { + hNum++; + str = "赢"; + } + else if (A == B) + { + + str = "平局"; + } + else + { + uNum++; + str = "输"; + } + if (str == "赢") + { + return $"笨蛋,{name}输了"; + + } + else if (str == "输") + { + return $"恭喜,{name}赢了"; + } + else + { + return "平局,再来"; + } + + /* else if (A == "石头" && B == "剪刀") + { + if () + { + hNum++; + return $"笨蛋,{name}输了"; + } + else if (B == "布") + { + uNum++; + return $"恭喜,{name}赢了"; + } + } + else if (A == "布" && B == "剪刀") + { + uNum++; + return $"恭喜,{name}赢了"; + } + else if (A == "布" && B == "石头") + { + hNum++; + return $"笨蛋,{name}输了"; + } + else*/ + + } + + + } +} diff --git "a/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/Hero.cs" "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/Hero.cs" new file mode 100644 index 0000000..97a3ca4 --- /dev/null +++ "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/Hero.cs" @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + class Hero : Person + { + public Hero() + { + } + + public Hero(string name) : base(name) + { + } + + public override string Action() + { + Random rd = new Random(); + int num = rd.Next(1, 4); + switch (num) + { + case 1: + return "剪刀"; + case 2: + return "石头"; + case 3: + return "布"; + } + return ""; + } + } +} diff --git "a/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/Person.cs" "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/Person.cs" new file mode 100644 index 0000000..7210fed --- /dev/null +++ "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/Person.cs" @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + class Person + { + public string Name { get; set; } + + public Person() + { + } + + public Person(string name) + { + Name = name; + } + + public virtual string Action() + { + return null; + } + } +} diff --git "a/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/Program.cs" "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/Program.cs" new file mode 100644 index 0000000..c096fa0 --- /dev/null +++ "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/Program.cs" @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("-------欢 迎 进 入 游 戏 世 界-------"); + while (true) + { + Console.WriteLine("*******************************"); + Console.WriteLine("**********猜拳,开始***********"); + Console.WriteLine("*******************************"); + Console.WriteLine("出拳规则:1.剪刀 2.石头 3.布"); + Hero hero = HeroCreate(); + User user = UserCreate(); + bool IsStart = Start(); + if (!IsStart) + { + Console.WriteLine("系统退出"); + return; + } + else + { + Console.WriteLine(hero.Name + " VS " + user.Name + " 对战"); + } + + GameSystem gm = new GameSystem(); + bool IsConutinue = gm.Gaming(hero, user); + if (!IsConutinue) + { + Console.WriteLine("系统退出"); + return; + } + } + } + + private static bool Start() + { + while (true) + { + Console.WriteLine("开始游戏吗?(y/n)"); + string chioce = Console.ReadLine(); + switch (chioce) + { + case "y": + return true; + case "n": + return false; + default: + Console.WriteLine("选择错误,请重新输入"); + continue; + } + } + } + public static Hero HeroCreate() + { + while (true) + { + Console.WriteLine("请选择对方角色<1.刘备 2.孙权 3.曹操>"); + Console.Write("请选择:"); + string chioce = Console.ReadLine(); + switch (chioce) + { + case "1": + return new Hero("刘备"); + case "2": + return new Hero("孙权"); + case "3": + return new Hero("曹操"); + default: + Console.WriteLine("选择错误,请重新输入"); + continue; + } + } + } + public static User UserCreate() + { + + Console.WriteLine("请输入您的姓名"); + string userName = Console.ReadLine(); + return new User(userName); + } + } +} diff --git "a/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/User.cs" "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/User.cs" new file mode 100644 index 0000000..b003d8d --- /dev/null +++ "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\345\211\221\351\230\263/User.cs" @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + class User : Person + { + public User() + { + } + + public User(string name) : base(name) + { + } + + public override string Action() + { + while (true) + { + Console.WriteLine("请出拳:1.剪刀 2.石头 3.布(输入相应数字)"); + string chioce = Console.ReadLine(); + switch (chioce) + { + case "1": + return "剪刀"; + case "2": + return "石头"; + case "3": + return "布"; + default: + Console.WriteLine("选择错误,请重新输入"); + continue; + } + } + } + } +} -- Gitee