{
static void Main(string[] args)
{
while (true)
{
int x, y;
string a, b; //首先先随机生成三个数,然后将0,1,2变成剪刀石头布,利用switch case达到,在比较的时候注意当x为0,y为2的时候,出x的获胜。即先判断这一句 x == 0 && y == 2 ,这句成立直接输出,因为后面的是||或者的意思;y获胜也一样,即先判断x == 2 && y == 0这一句,如果不成立再判断下一句。
Random r = new Random();
x = r.Next(0, 3);
y = r.Next(0, 3);
switch (x)
{
case 0:
a = "剪刀";
break;
case 1:
a = "石头";
break;
case 2:
a = "布";
break;
default:
a = "耍赖";
break;
}
switch (y)
{
case 0:
b= "剪刀";
break;
case 1:
b = "石头";
break;
case 2:
b= "布";
break;
default:
b = "耍赖";
break;
}
Console.WriteLine(a);
Console.WriteLine(b);
if (x == 0 && y == 2 || x > y)
{
Console.WriteLine(a+"获胜");
}
else if (x == y)
{
Console.WriteLine( "平局");
}
else if (x == 2 && y == 0 || x < y)
{
Console.WriteLine(b + "获胜");
}
else
{
Console.WriteLine("出现错误");
}
Console.ReadLine();
}
}
}
}