Random r = new Random(); string x, y; while (true) { int a = r.Next(0, 3); int b = r.Next(0, 3);
switch (a) { case 0://剪刀 x = "剪刀"; break; case 1://石头 x = "石头"; break; case 2://布 x = "布"; break; default: x = "耍赖"; break; } switch (b) { case 0://剪刀 y = "剪刀"; break; case 1://石头 y = "石头"; break; case 2://布 y = "布"; break; default: y = "耍赖"; break; }
Console.WriteLine("x出的是" + x); Console.WriteLine("y出的是" + y); string jg = ""; if (a == b) { jg = "平局"; } else if ( a > b) { if (a==2&&b==0) { jg = "y胜利"; } else { jg = "x胜利"; } } else if (b > a) { if (b == 2 && a == 0) { jg = "x胜利"; } else { jg = "y胜利"; } }
Console.WriteLine(jg);
Console.ReadLine(); }