标签:
int count1 = 0, count2 = 0;//设定赢的次数,输的次数
for (; ; )
{
//1、提示用户出拳
Console.Write("请出拳(石头0,剪子1,布2):");
int yh = int.Parse(Console.ReadLine());
//2、电脑随机生成
Random r = new Random();
int dn = r.Next(0, 3);
//3、判断输赢
// 用户赢:0-1=-1 1-2=-1 2-0=2
//用户输了:0-2=-2 1-0=1 2-1=1
//平局 0
int jg = yh-dn;
if (yh < 0 || yh > 2)
{
Console.WriteLine("输入有误!");
}
else
{
if (jg == -1 || jg == 2)
{
Console.WriteLine("您赢了!");
count1++;
if (count1 == 2)
{
Console.WriteLine("您最终赢了!"); break;//赢两次结果,跳出循环
}
}
else if (jg == -2 || jg == 1)
{
Console.WriteLine("您输了!");
count2++;
if (count2 == 2)
{
Console.WriteLine("您最终输了!"); break;
}
}
else if (jg == 0)
{
Console.WriteLine("平局!");
}
}
}
Console.ReadLine();
标签:
原文地址:http://www.cnblogs.com/fengsantianya/p/5456534.html