1. 程式人生 > 其它 >3/22 剪刀石頭布

3/22 剪刀石頭布

namespace _07_三個人玩石頭剪刀布
{
class Program
{
static void Main(string[] args)
{
Random r = new Random();
string x="", y="", z="";
int computer1 = r.Next(1, 4);
int computer2 = r.Next(1, 4);
Console.WriteLine("1---剪刀 2---石頭 3---布");
int person = int.Parse(Console.ReadLine());
switch (person)
{

case 1: z = "剪刀";
break;
case 2: z = "石頭";
break;
case 3: z = "布";
break;
default:
Console.WriteLine("你耍賴皮不算");
break;
}
switch (computer1)
{
case 1: x = "剪刀";
break;
case 2: x = "石頭";
break;
case 3: x = "布";
break;
}
switch (computer2)
{
case 1: y = "剪刀";
break;
case 2: y = "石頭";
break;
case 3: y = "布";
break;
}
Console.WriteLine("電腦a出{0}",x);
Console.WriteLine("電腦b出{0}",y);
Console.WriteLine("玩家出{0}",z);
if ((computer1!=person&&computer1!=computer2&&person!=computer2)||(computer1==computer2&&computer1==person&&person==computer2))
{
Console.WriteLine("平局");
}
else if (person==1&&computer2!=2&&computer1!=2)
{
Console.WriteLine("玩家贏了");
}
else if (person == 2 && computer2 != 3 && computer1 != 3)
{
Console.WriteLine("玩家贏了");
}
else if (person == 3 && computer2 != 1 && computer1 != 1)
{
Console.WriteLine("玩家贏了");
}
else
{
Console.WriteLine("玩家輸了");
}
Console.ReadKey();
}
}
}