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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 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 0000000000000000000000000000000000000000..f0d55e0ea129def5d9d950567f1ca3a7bfbe225e --- /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 0000000000000000000000000000000000000000..97a3ca4d022dbbcb1b21893bc731cab723ca9a8c --- /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 0000000000000000000000000000000000000000..7210fed863735476b159ea4356e91e21302bcbab --- /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 0000000000000000000000000000000000000000..c096fa04113d239bf697d0a5fc754e8b5e79a755 --- /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 0000000000000000000000000000000000000000..b003d8d38748cb77a70be111784eddbfd5c4e051 --- /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; + } + } + } + } +}