using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WindowsFormsApp4; namespace ConsoleApp1 { abstract class Base { public string Name { get; set; } public int Number { get; set; } } class Player : Base { public int Fist(string name) { Name = name; switch (name) { case "剪刀": Number = 0; break; case "石头": Number = 1; break; case "布": Number = 2; break; } return Number; } } class Computer : Base { public int Fist() { var mapping = new string[] { "剪刀", "石头", "布" }; Number = new Random().Next(3); Name = mapping[Number]; return Number; } }//end Computer public enum Result { Win, Lose, Draw } class Judge { public static Result Confirm(Player playerObj, Computer computerObj) { var delta = playerObj.Number - computerObj.Number; switch (delta) { case 0: return Result.Draw; case -2: case 1: return Result.Win; default: return Result.Lose; } } } class Program { static void Main(string[] args) { while (true) { var playName = Console.ReadLine(); Content(playName); } } private static void Content(string playName) { var player = new Player(); var computer = new Computer(); var playerFist = player.Fist(playName); var computerFist = computer.Fist(); var result = Judge.Confirm(player, computer); Console.WriteLine("玩家:{0},计算机:{1},结果:{2}", player.Name, computer.Name, result); } //end Main }//end Program static class ObjectExt { public static void Write(this object obj) { Console.WriteLine(obj); } public static void Write<T>(this IEnumerable<T> obj) { foreach (var o in obj) { Console.WriteLine(o); } } } }//end namespace