From 2901b3ae7ff2a8c941da6af7a6eb7f394275a39b Mon Sep 17 00:00:00 2001 From: futurestare <2528134883@qq.com> Date: Mon, 7 Jun 2021 22:43:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=83=A1=E6=B4=A5=E5=8D=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GameSystem.cs" | 118 ++++++++++++++++++ .../Hero.cs" | 60 +++++++++ .../Person.cs" | 27 ++++ .../Program.cs" | 75 +++++++++++ .../Users.cs" | 41 ++++++ 5 files changed, 321 insertions(+) create mode 100644 "\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\346\264\245\345\215\216/GameSystem.cs" create mode 100644 "\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\346\264\245\345\215\216/Hero.cs" create mode 100644 "\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\346\264\245\345\215\216/Person.cs" create mode 100644 "\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\346\264\245\345\215\216/Program.cs" create mode 100644 "\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\346\264\245\345\215\216/Users.cs" diff --git "a/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\346\264\245\345\215\216/GameSystem.cs" "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\346\264\245\345\215\216/GameSystem.cs" new file mode 100644 index 0000000..f4a821a --- /dev/null +++ "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\346\264\245\345\215\216/GameSystem.cs" @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo01 +{ + class GameSystem + { + public bool Gaming(Hero hero, Users users) + { + int sum = 0; + int hNum = 0; + int uNum = 0; + while (true) + { + string heroAction; + string userAction; + userAction = users.Action(); + Console.WriteLine(users.Name + ": 出拳: " + userAction); + heroAction = hero.Action(); + Console.WriteLine(hero.Name + ": 出拳: " + heroAction); + Console.WriteLine(IsWin(heroAction, userAction, users.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, users.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 "平局,再来"; + } + + } + } + } diff --git "a/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\346\264\245\345\215\216/Hero.cs" "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\346\264\245\345\215\216/Hero.cs" new file mode 100644 index 0000000..7cde214 --- /dev/null +++ "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\346\264\245\345\215\216/Hero.cs" @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo01 +{ + class Hero:Person + { + public Hero() + { + } + + public Hero(string name) : base(name) + { + + } + public void HeroCreate() + { + while (true) + { + Console.WriteLine("请选择对方角色<1.刘备 2.孙权 3.曹操>"); + Console.Write("请选择:"); + string chioce = Console.ReadLine(); + switch (chioce) + { + case "1": + this.Name = "刘备"; + return; + case "2": + this.Name = "孙权"; + return; + case "3": + this.Name = "曹操"; + return; + default: + Console.WriteLine("选择错误,请重新输入"); + continue; + } + } + } + + 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/\350\203\241\346\264\245\345\215\216/Person.cs" "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\346\264\245\345\215\216/Person.cs" new file mode 100644 index 0000000..d9ca448 --- /dev/null +++ "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\346\264\245\345\215\216/Person.cs" @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo01 +{ + 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/\350\203\241\346\264\245\345\215\216/Program.cs" "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\346\264\245\345\215\216/Program.cs" new file mode 100644 index 0000000..2290927 --- /dev/null +++ "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\346\264\245\345\215\216/Program.cs" @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo01 +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("-----------欢 迎 进 入 游 戏 世 界------------"); + while (true) + { + Console.WriteLine("****************************"); + Console.WriteLine("**********猜拳开始**********"); + Console.WriteLine("****************************"); + Console.WriteLine("出拳规则:1.剪刀 2.石头 3.布"); + Users users = UsersCreate(); + Hero hero = new Hero(); + hero.HeroCreate(); + + bool IsStart = Start(); + if (!IsStart) + { + Console.WriteLine("系统退出"); + return; + } + else + { + Console.WriteLine(users.Name + " VS " + hero.Name+ " 对战"); + } + GameSystem game = new GameSystem(); + bool IsConutinue = game.Gaming(hero, users); + if (!IsConutinue) + { + Console.WriteLine("系统退出"); + return; + } + } + + + + + } + + private static Users UsersCreate() + { + + Console.WriteLine("请输入您的姓名"); + string usersName = Console.ReadLine(); + return new Users(usersName); + } + + 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; + } + } + } + } +} \ No newline at end of file diff --git "a/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\346\264\245\345\215\216/Users.cs" "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\346\264\245\345\215\216/Users.cs" new file mode 100644 index 0000000..b6061ea --- /dev/null +++ "b/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\346\264\245\345\215\216/Users.cs" @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo01 +{ + class Users:Person + { + public Users() + { + + } + public Users(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