标签:
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("三局两胜电脑赢了");
}
标签:
原文地址:http://www.cnblogs.com/lz123/p/4932142.html