diff --git "a/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/npc/IronNPC.cs" "b/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/npc/IronNPC.cs" new file mode 100644 index 0000000000000000000000000000000000000000..d9759b176197830c4e460c8782ccf13cdea1730f --- /dev/null +++ "b/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/npc/IronNPC.cs" @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + class IronNPC : NPC + { + private string hqq; + public string Hqq + { + get { return this.hqq; } + set { this.hqq = value; } + } + public IronNPC() { } + public IronNPC(string name, Npctype type, string hqq) : base(name, type) + { + this.hqq = hqq; + + } + + public override void Speak() + { + Console.WriteLine(); + } + public void xb(string task) + { + Console.WriteLine($"我是修补NPC,给你一个任务:{task}"); + + } + public void qh(string task) + { + Console.WriteLine($"我是强化NPC,给你一个任务:{task}"); + + } + public void dz(string task) + { + Console.WriteLine($"我是打造NPC,给你一个任务:{task}"); + + } + + + } + } + diff --git "a/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/npc/Npc.cs" "b/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/npc/Npc.cs" new file mode 100644 index 0000000000000000000000000000000000000000..8b513eb72a91c1f5e4e6a7af8d0cb8f760721e47 --- /dev/null +++ "b/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/npc/Npc.cs" @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + enum Npctype + { + Task,//任务类型 + Shop,//商贩类型 + Iron,//铁匠类型 + } + abstract class NPC + { + private string name; + private Npctype type; + + public string Name + { + get { return this.name; } + set { this.name = value; } + } + public Npctype Type + { + get { return this.type; } + set { this.type = value; } + } + public NPC(string name, Npctype type) + { + this.name = name; + this.type = type; + } + + public NPC() { } + public abstract void Speak(); + } +} diff --git "a/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/npc/Program.cs" "b/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/npc/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..f3c7037bf0a59c5bc85c91236bab69863c2379f6 --- /dev/null +++ "b/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/npc/Program.cs" @@ -0,0 +1,28 @@ +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) + { + IronNPC i = new IronNPC(); + i.Speak(); + i.xb("任务1"); + i.qh("任务2"); + i.dz("任务3"); + TaskNPC z = new TaskNPC(); + z.sx("任务4"); + z.dg("任务5"); + z.cj("任务6"); + ShopNPC s = new ShopNPC(); + s.wq("任务7"); + s.cl("任务8"); + s.sw("任务9"); + } + } +} diff --git "a/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/npc/ShopNPC.cs" "b/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/npc/ShopNPC.cs" new file mode 100644 index 0000000000000000000000000000000000000000..0441d172a37cfc791e6d78cdc74b5aa165329895 --- /dev/null +++ "b/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/npc/ShopNPC.cs" @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + class ShopNPC : NPC + { + private string item; + public string Item + { + get => item; + set => item = value; + } + public ShopNPC() { } + public ShopNPC(string name, Npctype type, string item) : base(name, type) + { + this.item = item; + + } + + public override void Speak() + { + Console.WriteLine("NPC:{0},我在贩卖{1}商品", this.Name, this.item); + } + public void wq(string task) + { + Console.WriteLine($"我是武器NPC,给你一个任务:{task}"); + + } + public void cl(string task) + { + Console.WriteLine($"我是材料NPC,给你一个任务:{task}"); + + } + public void sw(string task) + { + Console.WriteLine($"我是食物NPC,给你一个任务:{task}"); + + } + } + +} diff --git "a/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/npc/TaskNPC.cs" "b/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/npc/TaskNPC.cs" new file mode 100644 index 0000000000000000000000000000000000000000..72a46404724bdfbde748170eb9c366fe697d3057 --- /dev/null +++ "b/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/npc/TaskNPC.cs" @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + class TaskNPC : NPC + { + private string taskInfo; + + public TaskNPC() { } + public TaskNPC(string name, Npctype type, string taskInfo) : base(name, type) + { + this.taskInfo = taskInfo; + } + public override void Speak() + { + Console.WriteLine("哇,你来了,我正需要帮助,你可以帮助我吗?"); + Console.WriteLine("NPC:{0},任务:{1}", base.Name, this.taskInfo); + } + public void sx(string task) + { + Console.WriteLine($"我是送信NPC,给你一个任务:{task}"); + + } + public void dg(string task) + { + Console.WriteLine($"我是打怪NPC,给你一个任务:{task}"); + + } + public void cj(string task) + { + Console.WriteLine($"我是采集NPC,给你一个任务:{task}"); + } + } +} diff --git "a/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/\346\234\272\345\231\250\344\272\272/CookRobot.cs" "b/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/\346\234\272\345\231\250\344\272\272/CookRobot.cs" new file mode 100644 index 0000000000000000000000000000000000000000..cc91fb823483f5eb5bc7f582e7e2e1932b82a088 --- /dev/null +++ "b/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/\346\234\272\345\231\250\344\272\272/CookRobot.cs" @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace W1 +{ + enum Cook + { + 扬州炒饭, + 水煮肥牛, + 爆炒小龙虾 + } + class CookRobot : Robot + { + private Cook ck; + + public Cook Ck + { + get { return this.ck; } + set { this.ck = value; } + + } + public CookRobot(string name, Cook ck) : base(name) + { + this.ck = ck; + } + public override void Working() + { + Console.WriteLine("{0}正在做{1}", this.name, this.ck); + } + } +} diff --git "a/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/\346\234\272\345\231\250\344\272\272/DeliveryRobot.cs" "b/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/\346\234\272\345\231\250\344\272\272/DeliveryRobot.cs" new file mode 100644 index 0000000000000000000000000000000000000000..77131fba9aa0245151ac46c925387fed1621b939 --- /dev/null +++ "b/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/\346\234\272\345\231\250\344\272\272/DeliveryRobot.cs" @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace W1 +{ + class DeliveryRobot : Robot + { + private int hours; + + public int Hours + { + get { return this.hours; } + set { this.hours = value; } + } + + + public DeliveryRobot(string name, int hours) : base(name) + { + this.hours = hours; + } + public override void Working() + { + Console.WriteLine("{0}连续工作时长为{1}分钟", this.name, this.hours); + } + } +} diff --git "a/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/\346\234\272\345\231\250\344\272\272/Program.cs" "b/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/\346\234\272\345\231\250\344\272\272/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..21cbabb57cf47d709a893092826514b7ebf1672b --- /dev/null +++ "b/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/\346\234\272\345\231\250\344\272\272/Program.cs" @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace W1 +{ + class Program + { + static void Main(string[] args) + { + // 编写一个程序,以实现机器人的层次结构,此层次结构将至少包含抽象类机器人类Robot、炒菜机器人类CookRobot、传菜机器人类DeliveryRobot。 + //Robot类应包含机器人姓名name字段、机器人工作的方法Working(),该方法应该在子类中被实现,机器人工作的方式很多,所以Working()方法应该被定义为抽象方法。 + + //可以在CookRobot中添加一个代表菜的类型的字段,用枚举类型;在DeliveryRobot中添加一个代表连续工作时长的字段hours。 + //CookRobot和DeliveryRobot应实现具体的Working()方法。 + + //在主类中定义一个方法,形参数据类型是string,返回值数据类型是Robot,方法中实现如果传入的字符串是“炒菜”,那就返回CookRobot的实例(当然是要用Robot的引用指向的),如果传入的字符串是“传菜”,那就返回DeliveryRobot的实例。 + + //Main方法中:用户输入所选择的机器人的功能,根据用户的输入Robot执行对应的功能。 + Console.WriteLine("请输入炒菜 或 传菜"); + string c = Console.ReadLine(); + Tect(c); + + } + static void Tect(string c) + { + switch (c) + { + case "传菜": + Robot d = new DeliveryRobot("摸鱼人", 10); + d.Working(); + break; + case "炒菜": + Robot r = new CookRobot("摸鱼人", Cook.爆炒小龙虾); + r.Working(); + break; + default: + break; + + } + } + } +} diff --git "a/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/\346\234\272\345\231\250\344\272\272/Robot.cs" "b/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/\346\234\272\345\231\250\344\272\272/Robot.cs" new file mode 100644 index 0000000000000000000000000000000000000000..53f20ca9d159428e68cfeecb872a11ff5b51ea96 --- /dev/null +++ "b/\347\254\2541\346\254\241\344\275\234\344\270\232/5.20\344\275\234\344\270\232\343\200\201/\346\234\272\345\231\250\344\272\272/Robot.cs" @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace W1 +{ + abstract class Robot + { + protected string name; + + public string Nmae + { + get { return this.name; } + set { this.name = value; } + } + + public Robot(string name) + { + this.name = name; + } + public abstract void Working(); + } +}