Genau deshalb möchte ich, dass dieser Code absolut geröstet wird. Keine Beschönigung, kein höfliches Feedback. Ich habe C# schon eine ganze Weile nicht mehr berührt, und da ich mich zu sehr auf KI verlassen habe, sind meine Grundlagen offensichtlich eingerostet. Diese Übung soll mich dazu zwingen, mich damit auseinanderzusetzen und mich tatsächlich als Programmierer zu verbessern.
Hier ist der Code.
Code: Select all
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");
}
}
}
}
}
Mobile version