"깊이"가 다른 게임개발자 허민영

유저에서 게임까지, 철학에서 코딩까지, 본질을 보는 게임개발

내일배움캠프

[Unity 7기] 숫자 맞추기 게임

허민영 2024. 12. 30. 15:02
int guess = 0;
Random random = new Random();
int randomNumber = random.Next(1, 101);
bool isCorrect = false;

guess = Convert.ToInt32(Console.ReadLine());

while (isCorrect == false)
{
    if (guess == randomNumber)
    {
        Console.WriteLine("Enter your guess (1-100):"+guess);
        Console.WriteLine("Congratulations! You guessed the number.");
        isCorrect = true;
    }
    else if (guess > randomNumber)
    {
        Console.WriteLine("Enter your guess (1-100):" + guess);
        Console.WriteLine("Too high! Try again.");
        guess = Convert.ToInt32(Console.ReadLine());
    }
    else
    {
        Console.WriteLine("Too low! Try again.");
        guess = Convert.ToInt32(Console.ReadLine());
    }
}