سلامتی موز
using System;
namespace GuessTheNumber
{
class Program
{
static void Main(string[] args)
{
// Generate a random number between 1 and 100
Random random = new Random();
int secretNumber = random.Next(1, 101);
// Initialize the number of guesses
int guesses = 10;
// Greet the user and explain the game
Console.WriteLine("سلام، من بینگ هستم. من یک عدد بین 1 تا 100 در نظر گرفتهام. میتوانید حدس بزنید که چه عددی است؟");
Console.WriteLine("شما فقط 10 بار میتوانید حدس بزنید. من به شما میگویم که عدد شما بزرگتر یا کوچکتر از عدد من است.");
Console.WriteLine("آیا آمادهاید؟ بسیار خب، بیایید شروع کنیم!");
// Start the game loop
while (guesses > 0)
{
// Prompt the user to enter a guess
Console.Write("حدس شما چیست؟ ");
string input = Console.ReadLine();
// Try to parse the input as an integer
int guess;
bool isValid = int.TryParse(input, out guess);
// If the input is not a valid integer, show an error message and continue the loop
if (!isValid)
{
Console.WriteLine("لطفا یک عدد صحیح بین 1 تا 100 وارد کنید.");
continue;
}
// If the input is out of range, show an error message and continue the loop
if (guess < 1 || guess > 100)
{
Console.WriteLine("لطفا یک عدد بین 1 تا 100 وارد کنید.");
continue;
}
// If the guess is correct, congratulate the user and end the game
if (guess == secretNumber)
{
Console.WriteLine("درست است! شما عدد من را حدس زدید. تبریک میگویم!");
break;
}
// If the guess is wrong, show a hint and decrement the number of guesses
if (guess < secretNumber)
{
Console.WriteLine("نه، عدد من بزرگتر است.");
}
else
{
Console.WriteLine("نه، عدد من کوچکتر است.");
}
guesses--;
Console.WriteLine("شما {0} بار دیگر میتوانید حدس بزنید.", guesses);
}
// If the user ran out of guesses, reveal the secret number and end the game
if (guesses == 0)
{
Console.WriteLine("متاسفم، شما نتوانستید عدد من را حدس بزنید. عدد من {0} بود.", secretNumber);
}
// Thank the user for playing and say goodbye
Console.W
riteLine("از اینکه با من بازی کردید ممنونم. خداحافظ!");
}
}
}
- ۰۲/۰۹/۱۳