猜拳游戏C#版

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 猜拳游戏
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("以下是游戏规则:\n\n请输入1-3任意字符 1.代表剪刀;2.代表石头;3.代表布 ");
while (true)
{

Console.WriteLine("\n请选择数字:");
int num = int.Parse(Console.ReadLine());
switch (num)
{
case 1: Console.WriteLine("您出了剪刀!\n"); break;
case 2: Console.WriteLine("您出了石头!\n"); break;
case 3: Console.WriteLine("您出了布!\n"); break;
default: Console.WriteLine("您输入的数字不合法!\n"); break;
}

if ((num == 1) || (num == 2) || (num == 3))
{
Random a = new Random();
int num2 = a.Next(1, 4);

switch (num2)
{
case 1: Console.WriteLine("电脑出了剪刀!\n"); break;
case 2: Console.WriteLine("电脑出了石头!\n"); break;
case 3: Console.WriteLine("电脑出了布!\n"); break;
}
if (num == num2)
{
Console.WriteLine(" 平局!");
} if ((num == 1) && (num2 == 2))
{
Console.WriteLine("您输了!");
} if ((num == 2) && (num2 == 3))
{
Console.WriteLine("您输了!");
} if ((num == 3) && (num2 == 1))
{
Console.WriteLine("您输了!");
} if ((num == 2) && (num2 == 1))
{
Console.WriteLine("您赢了!");
} if ((num == 3) && (num2 == 2))
{
Console.WriteLine("您赢了!");
} if ((num == 1) && (num2 == 3))
{
Console.WriteLine("您赢了!");
}
}
}
}
}
}

相关文档
最新文档