0
点赞
收藏
分享

微信扫一扫

一个石头剪刀布的例子

颜娘娘的碎碎念 2022-04-04 阅读 125
c#

      static void Main(string[] args)
        {
            string[] str = { "石头", "布", "剪刀" };
            while (true)
            {
                Console.WriteLine("******************游戏开始******************");
                Console.Write("请出拳(1:石头,2:布,3:剪刀):");
                int roleData = 0;
                try
                {
                    roleData = Convert.ToInt32(Console.ReadLine());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("输入错误!");
                }
                Random dom = new Random();
                int machineData = dom.Next(1,4);
                if (roleData == machineData)
                {
                    Console.WriteLine("平局");
                }
                else if (roleData == 1 && machineData == 2)
                {
                    Console.WriteLine("你输了");
                }
                else if (roleData == 2 && machineData == 3)
                {
                    Console.WriteLine("你输了");
                }
                else if (roleData == 3 && machineData == 1)
                {
                    Console.WriteLine("你输了");
                }
                else 
                {
                    Console.WriteLine("你赢了");
                }
                Console.WriteLine(string.Format("结果:角色:{0}||人机:{1}",str[roleData-1],str[machineData-1]));
                Console.ReadLine();
            }
        }

举报

相关推荐

0 条评论