欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

练习 !!猜拳

发布时间:2025/5/22 编程问答 30 豆豆
生活随笔 收集整理的这篇文章主要介绍了 练习 !!猜拳 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

int renying = 0;
int dnying = 0;

for (int i = 1; i <= 3; i++)
{
Random r = new Random();//生成随机数
int diannao = r.Next(3);//生成0-3之间,不包括3的数

Console.Write("请出拳:剪刀-0 石头-1 布-2 :");
int ren = int.Parse(Console.ReadLine());//控制台录入字符串,转换为int类型

Console.WriteLine("电脑出拳:{0}", diannao);
if (diannao - ren == -1 || ren - diannao == -2)//所有人赢的情况
{
renying++;
Console.WriteLine("恭喜你,你赢了");
}
else if (diannao == ren)
{
Console.WriteLine("平局");
}
else
{
dnying++;
Console.WriteLine("输了");
}
}

if (renying >= 2)
{
Console.WriteLine("三局两胜人赢了");
}

if (dnying >= 2)
{
Console.WriteLine("三局两胜电脑赢了");
}

 

转载于:https://www.cnblogs.com/lz123/p/4932142.html

总结

以上是生活随笔为你收集整理的练习 !!猜拳的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。