using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 猜拳游戏
{
class Program
{
static void Main(string[] args)
{
//完成一个简单的儿时游戏-剪子包袱锤。提示玩家出拳,玩家出拳后,电脑自动出拳,根据双方 的出拳,来判定输赢
Console.WriteLine("欢迎进入猜拳游戏!");
while (true)
{
//获取玩家数:
Console.WriteLine("请玩家出拳(0剪子,1包袱,2锤头)");
int a = int.Parse(Console.ReadLine());
//获取电脑随机数:
int b = getRand();
if (a == 0 && b == 0)
{
Console.WriteLine("玩家剪刀,电脑剪刀,平局");
}
else if (a == 0 && b == 1)
{
Console.WriteLine("玩家剪刀,电脑包袱,玩家胜");
break;
}
else if (a == 0 && b == 2)
{
Console.WriteLine("玩家剪刀,电脑锤头,电脑胜");
}
else if (a == 1 && b == 1)
{
Console.WriteLine("玩家包袱,电脑包袱,平局");
}
else if (a == 1 && b == 2)
{
Console.WriteLine("玩家包袱,电脑锤头,玩家胜");
break;
}
else if (a == 1 && b == 0)
{
Console.WriteLine("玩家包袱,电脑剪刀,电脑胜");
}
else if (a == 2 && b == 0)
{
Console.WriteLine("玩家锤头,电脑剪刀,玩家胜");
break;
}
else if (a == 2 && b == 1)
{
Console.WriteLine("玩家锤头,电脑包袱,电脑胜");
}
else if (a == 2 && b == 2)
{
Console.WriteLine("玩家锤头,电脑锤头,平局");
}
}
}
private static int getRand()
{
Random r = new Random();
int d = r.Next(2);
return d;
}
}
}
c#猜拳游戏
于 2022-06-29 13:24:22 首次发布