diff --git "a/\351\203\255\347\220\252\346\236\253/\344\270\215\344\274\232\345\201\232/Computer.cs" "b/\351\203\255\347\220\252\346\236\253/\344\270\215\344\274\232\345\201\232/Computer.cs" new file mode 100644 index 0000000000000000000000000000000000000000..9d38b1305e01663d62b85df48f1462f5930dbb1a --- /dev/null +++ "b/\351\203\255\347\220\252\346\236\253/\344\270\215\344\274\232\345\201\232/Computer.cs" @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + class Computer + { + private string name; + + public Computer(string name) + { + this.name = name; + } + + public string Name { get => name; set => name = value; } + + + public int Check() + { + Random ran = new Random(); + int num = ran.Next(1, 4); + switch (num) + { + case 1: + Console.WriteLine("{0}出了一个剪刀", name); + break; + case 2: + Console.WriteLine("{0}出了一个石头", name); + break; + case 3: + Console.WriteLine("{0}出了一个布", name); + break; + } + return num; + } + } +} diff --git "a/\351\203\255\347\220\252\346\236\253/\344\270\215\344\274\232\345\201\232/Player.cs" "b/\351\203\255\347\220\252\346\236\253/\344\270\215\344\274\232\345\201\232/Player.cs" new file mode 100644 index 0000000000000000000000000000000000000000..82fc5a0cd27036a2ef3936d42d12eb061d01f4ef --- /dev/null +++ "b/\351\203\255\347\220\252\346\236\253/\344\270\215\344\274\232\345\201\232/Player.cs" @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + class Player + { + private string name; + + public Player(string name) + { + this.name = name; + } + + public string Name { get => name; set => name = value; } + public int Really() + { + + Console.WriteLine("请出拳:1.剪刀,2.石头,3.布(输入相应的数字)"); + int num1 = int.Parse(Console.ReadLine()); + switch (num1) + { + case 1: + Console.WriteLine("{0}出了一个剪刀", name); + break; + case 2: + Console.WriteLine("{0}出了一个石头", name); + break; + case 3: + Console.WriteLine("{0}出了一个布", name); + break; + } + return num1; + } + } +} diff --git "a/\351\203\255\347\220\252\346\236\253/\344\270\215\344\274\232\345\201\232/Program.cs" "b/\351\203\255\347\220\252\346\236\253/\344\270\215\344\274\232\345\201\232/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..3ddcb54e0041a66aa91ecddb936de0aed2b6785c --- /dev/null +++ "b/\351\203\255\347\220\252\346\236\253/\344\270\215\344\274\232\345\201\232/Program.cs" @@ -0,0 +1,95 @@ +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("-------------欢迎进入游戏世界-------------"); + Console.WriteLine("------------------------------------------"); + Console.WriteLine("-------------欢迎进入游戏世界-------------"); + Console.WriteLine("------------------------------------------"); + Console.WriteLine("出拳规则:1.剪刀,2.石头,3.布"); + Console.WriteLine("请选择敌方角色:1.刘备,2.孙权,3.曹操"); + int num = int.Parse(Console.ReadLine()); + string str = Convert.ToString(num); + switch (num) + { + case 1: + str = "刘备"; + break; + case 2: + str = "孙权"; + break; + case 3: + str = "曹操"; + break; + } + Computer computer = new Computer(str); + Console.WriteLine("请输入您的名字"); + string name = Console.ReadLine(); + Player player = new Player(name); + Referee referee = new Referee(name,str); + + switch (num) + { + case 1: + Console.WriteLine(name + " " + "VS" + " " + "刘备" + " " + "对战"); + Test(referee, computer, player); + break; + case 2: + Console.WriteLine(name + " " + "VS" + " " + "孙权" + " " + "对战"); + Test(referee, computer, player); + break; + case 3: + Console.WriteLine(name + " " + "VS" + " " + "曹操" + " " + "对战"); + Test(referee, computer, player); + break; + } + Player player1 = new Player(name); + player1.Really(); + Computer computer1 = new Computer(str); + computer1.Check(); + } + public static void Test(Referee referee, Computer computer, Player player) + { + Console.WriteLine("游戏开始吗?"); + string str = Console.ReadLine(); + switch (str) + { + case "y": + Test1(referee, computer, player); + break; + case "n": + Console.WriteLine("欢迎下次光临"); + break; + } + } + public static void Test1(Referee referee, Computer computer, Player player) + { + while (true) + { + int n1 = player.Really(); + int n2 = computer.Check(); + referee.Result(n1, n2); + Console.WriteLine("是否进入下一轮(y/n)"); + string str = Console.ReadLine(); + switch (str) + { + case "y": + Test1(referee, computer, player); + break; + case "n": + referee.Finally(); + break; + } + } + } + } + +} diff --git "a/\351\203\255\347\220\252\346\236\253/\344\270\215\344\274\232\345\201\232/Referee.cs" "b/\351\203\255\347\220\252\346\236\253/\344\270\215\344\274\232\345\201\232/Referee.cs" new file mode 100644 index 0000000000000000000000000000000000000000..c6403b4b7ce3aa0366073bbba7ff8316dbbc5e0e --- /dev/null +++ "b/\351\203\255\347\220\252\346\236\253/\344\270\215\344\274\232\345\201\232/Referee.cs" @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + class Referee + { + private string name; + private string name1; + + + + int sum = 0; + int sum1 = 0; + int sum2 = 0; + + public string Name { get => name; set => name = value; } + public string Name1 { get => name1; set => name1 = value; } + + public Referee(string name, string name1) + { + this.Name = name; + this.Name1 = name1; + } + + public void Result(int n1, int n2) + { + if (n1 - n2 == -2 || n1 - n2 == 1) + { + Console.WriteLine("恭喜,{0}赢了", name); + sum++; + sum1++; + } + else if (n1 == n2) + { + Console.WriteLine("和局,真衰,嘿嘿,走着瞧"); + sum++; + } + else + { + Console.WriteLine("笨蛋,{0}输了", name); + sum++; + sum2++; + } + } + public void Finally() + { + Console.WriteLine("================================"); + Console.WriteLine("{0} VS {1}",name,name1); + Console.WriteLine("对战次数", sum); + Console.WriteLine("姓名{0},得分{1}", name, sum1); + Console.WriteLine("姓名{0},得分{1}", name1, sum2); + if (sum1 > sum2) + { + Console.WriteLine("{0}赢,{1}笨蛋", name, name1); + } + else if (sum1 == sum2) + { + Console.WriteLine("和局,真衰,嘿嘿,走着瞧"); + } + else + { + Console.WriteLine("{0}赢,{1}笨蛋", name1, name); + } + } + } +} diff --git "a/\351\203\255\347\220\252\346\236\253/\345\210\253\347\234\213\344\272\206/PersonClass.cs" "b/\351\203\255\347\220\252\346\236\253/\345\210\253\347\234\213\344\272\206/PersonClass.cs" new file mode 100644 index 0000000000000000000000000000000000000000..9a4bcdafcee1803ea8ac0ec4c5ec67e85855901d --- /dev/null +++ "b/\351\203\255\347\220\252\346\236\253/\345\210\253\347\234\213\344\272\206/PersonClass.cs" @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + class PersonClass + { + public string name; + public string num; + public string address; + + public PersonClass(string name,string num,string address) + { + this.name = name; + this.num = num; + this.address = address; + } + } +} diff --git "a/\351\203\255\347\220\252\346\236\253/\345\210\253\347\234\213\344\272\206/Program.cs" "b/\351\203\255\347\220\252\346\236\253/\345\210\253\347\234\213\344\272\206/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..5cbcf1ed10438e74564e2fc6d4cb9b7d1fb47301 --- /dev/null +++ "b/\351\203\255\347\220\252\346\236\253/\345\210\253\347\234\213\344\272\206/Program.cs" @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + public struct PersonStruct + { + public string name; + public string num; + public string address; + + public PersonStruct(string name, string num, string address) + { + this.name = name; + this.num = num; + this.address = address; + } + } + class Program + { + // 定义一个结构体,名为PersonStruct,有三个成员变量:姓名、电话、地址, + //在主方法中,创建一个PersonStruct结构体对象p1,为p1的成员变量赋值。 + //再声明一个PersonStruct结构体变量p2,把p1赋值给p2,改变p2的姓名,打印p1的内容。 + //定义一个类,名为PersonClass,有三个成员变量:姓名、电话、地址, + //在主方法中,创建一个PersonClass对象p3,为p3的成员变量赋值。 + //再声明一个PersonClass变量p4,把p3赋值给p4,改变p4的姓名,打印p3的内容。 + //观察打印结果,并在在注释中,说下你对此的认识(它们为什么会这样?) + static void Main(string[] args) + { + PersonStruct p1 = new PersonStruct(); + p1.name = "吴一"; + p1.num = "12345678999"; + p1.address = "莆田"; + + PersonStruct p2 ; + p2.name = "吴二"; + p2 = p1; + Console.WriteLine("姓名:{0},电话号码:{1},家庭住址:{2}",p1.name,p1.num,p1.address); + + PersonClass p3 = new PersonClass("吴三","98765432111","莆田"); + PersonClass p4; + p4 = p3; + p4.name = "吴四"; + Console.WriteLine("姓名:{0},电话号码:{1},家庭住址:{2}", p3.name, p3.num, p3.address); + + + } + } +}