zoukankan      html  css  js  c++  java
  • 剪刀 石头 布

    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
  • 相关阅读:
    UEditor 在 Layer 模态框中无法使用问题
    mysql FORMAT() 格式化后的数字运算出错
    dede 对 单个 字段 编辑
    SW线路中串联1K电阻的作用
    示波器 如何用示波器正确测量电源纹波
    Excel工作表忘记密码如何破解?
    excel小技巧
    CPU核心电压与VID电压
    电容有什么作用?为什么cpu电源引脚都并联一个电容?
    APU的Vsense引脚的作用
  • 原文地址:https://www.cnblogs.com/zhaoxianglong1987/p/7682197.html
Copyright © 2011-2022 走看看