c#小游戏源码免费简单
时间: 2023-07-19 12:37:05 浏览: 70
这里有一个简单的C#小游戏源码,可以供你参考:
```csharp
using System;
namespace GuessTheNumber
{
class Program
{
static void Main(string[] args)
{
Random random = new Random();
int secretNumber = random.Next(1, 101);
int tries = 0;
int guess = 0;
Console.WriteLine("Guess the secret number between 1 and 100!");
while (guess != secretNumber)
{
Console.Write("Enter your guess: ");
guess = int.Parse(Console.ReadLine());
tries++;
if (guess < secretNumber)
{
Console.WriteLine("Too low, try again!");
}
else if (guess > secretNumber)
{
Console.WriteLine("Too high, try again!");
}
else
{
Console.WriteLine("Congratulations, you guessed the secret number in " + tries + " tries!");
}
}
Console.ReadLine();
}
}
}
```
这个小游戏是猜数字游戏,玩家需要在1到100的范围内猜出一个随机生成的秘密数字。程序会提示玩家每次猜的数字是否太高或太低,并在玩家猜中秘密数字时显示猜测次数。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![sln](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)