Именно поэтому я хочу, чтобы этот код был полностью поджарен. Никаких приукрашиваний, никаких вежливых отзывов. Я давно не прикасался к C#, и в сочетании со слишком большой зависимостью от искусственного интеллекта мои основы явно заржавели. Это упражнение предназначено для того, чтобы заставить меня противостоять этому и действительно стать лучше как программист.
Вот код.
Код: Выделить всё
using System;
namespace MyApp
{
internal class Program
{
static void Main(string[] args)
{
Generator generator = new Generator();
generator.numberGenerator();
}
}
class Generator()
{
public void numberGenerator()
{
Console.WriteLine("Give the difficulty of the game: +" +
"\n [1] Easy" +
"\n [2] Medium" +
"\n [3] Hard");
int userInputChoiceNumber = Convert.ToInt32(Console.ReadLine());
switch (userInputChoiceNumber)
{
case 1:
easyRound();
break;
case 2:
mediumRound();
break;
case 3:
hardRound();
break;
}
}
void easyRound()
{
while (true)
{
int attemptsEasy = 0; // om te kijken hoevaak iemamnd een beurt heeft gedaan
Console.WriteLine("Choose a number between 1-10");
int userInputChoiceEasy = Convert.ToInt32(Console.ReadLine());
Random easyRnd = new Random();
int numEasy = easyRnd.Next(1, 10);
if (userInputChoiceEasy == numEasy)
{
Console.WriteLine("You've guessed the right number!" + attemptsEasy);
break;
}
else if (userInputChoiceEasy != numEasy)
{
attemptsEasy++;
Console.WriteLine("Wrong! Try again");
}
else
{
Console.WriteLine("Number is out of boundary");
}
}
}
void mediumRound()
{
while (true)
{
int attemptsMedium = 0; // om te kijken hoevaak iemamnd een beurt heeft gedaan
Console.WriteLine("Choose a number between 1-35");
int userInputChoiceMedium = Convert.ToInt32(Console.ReadLine());
Random mediumRnd = new Random();
int numMedium = mediumRnd.Next(1, 35);
if (userInputChoiceMedium == numMedium)
{
Console.WriteLine("You've guessed the right number!" + attemptsMedium);
break;
}
else if (userInputChoiceMedium != numMedium)
{
attemptsMedium++;
Console.WriteLine("Wrong! Try again");
}
else
{
Console.WriteLine("Number is out of boundary");
}
}
}
void hardRound()
{
while (true)
{
int attempsHard = 0; // om te kijken hoevaak iemamnd een beurt heeft gedaan
Console.WriteLine("Choose a number between 1-60");
int userInputChoiceEasy = Convert.ToInt32(Console.ReadLine());
Random hardRnd = new Random();
int numHard = hardRnd.Next(1, 60);
if (userInputChoiceEasy == numHard)
{
Console.WriteLine("You've guessed the right number!" +
"\n Guessed attempts:" + attempsHard);
break;
}
else if (userInputChoiceEasy != numHard)
{
attempsHard++;
Console.WriteLine("Wrong! Try again");
}
else
{
Console.WriteLine("Number is out of boundary");
}
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... ing-please
Мобильная версия