Sorry my typo/auto correction. Not book but bool. that I hope should make more sense now.
When you use bool as bit mask, monster 1 is 1, monster 2 is 2, monster 3 is 4, Monster 4 is 8.
That gives you an unique combination.
So if you select monster 3, it adds 4 to bit mask.
In if condition you can check by using && AND logic, if monster 3 is set by AND (&&) with value 4. Will return true or false.
But I you have only 3 monsters, just use for simplicity variables. bool usedMonster1, bool usedMonster2, bool usedMonster3. Then simply check with if loop.
Or you could use another int to store, and check for a previously selected monster race.
I edited your code and added another int called ‘previousNumber’ which should do the trick:
static int previousNumber = -1;
static void Main(string[] args)
{
MonsterSelection(1, 3);
Console.ReadKey();
}
static int MonsterSelection(int _min, int _max)
{
int number;
bool wasValid = false;
do
{
Console.WriteLine("Please specify the first Monster:\n");
Console.WriteLine("1 = Ork\n2 = Troll\n3 = Goblin\n");
wasValid = int.TryParse(Console.ReadLine(), out number);
if (wasValid && number != previousNumber)
{
if (number < _min || number > _max)
{
wasValid = false;
}
else
previousNumber = number;
}
} while (!wasValid);
return number;
}
Edit: I have to say, your code looks a bit weird to me. Is ‘Console’ some method you wrote?
And I also think that, if number is smaller than _min or bigger than _max, your method will get stuck in an endless do-while loop?
@Team2Studio
Console is an app/game developed in VS, but not a Unity game. This isn’t really a question that should be in the Unity forum as it’s not related to developing within Unity.
If OP meant developing a Windows or Mac game within Unity, then their code doesn’t look right as it looks like code I wrote back when developing a Windows program outside of Unity.
static void Main(string[] args)
{
// so we ask which two different races fight together...
bool usedMonster1;
bool usedMonster2;
bool usedMonster3;
MonsterSelection(1, 3);
Console.ReadKey();
}