Answer the question
In order to leave comments, you need to log in
How to make difficulty levels for game Guess the Number C# Windows Forms?
I made a game in C# Windows Forms, but I don't know how to implement difficulty levels. Let's say easy (0-10), medium (0-50) and hard (0-100). Please help.
Answer the question
In order to leave comments, you need to log in
Wrap the guessing logic in a separate method. Pass the min and max parameters to the method, which indicate the range (0-100 for example). Next, create a class with two numbers, also min and max, and create 3 such objects with the values \u200b\u200bdescribed by you at the beginning of the program start (Main). Add a code to choose the difficulty (for example, enter the difficulty from 1 to 3) and, in accordance with the choice, pass the data from the corresponding object with the difficulty parameters to the function for guessing the number
Look, in order to guess the number, you must first guess it.
You yourself understand how the difficulty levels differ - namely, the range of guessed values.
That is, if you think about it (I never would have thought that you need to think about it) - you need to generate numbers from different ranges, according to the level of complexity.
First you need to decide what difficulty levels you will have - the easiest way is to create a new enum:
enum Level
{
Easy,
Normal,
Hard,
}
class Range
{
public Range(int min, int max)
{
Min = min;
Max = max;
}
public int Min { get; }
public int Max { get; }
}
private static Range GetRange(Level level)
{
switch (level)
{
case Level.Easy: return new Range(0, 10);
case Level.Normal: return new Range(0, 50);
case Level.Hard: return new Range(0, 100);
}
}
private static readonly Random = new Random();
private static int GenerateNumber(Level level)
{
var range = GetRange(level);
return Random.Next(range.Min, range.Max);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question