Improve challenge selection system
- Game will no longer end unexpectedly, when all challenges are played. - Challenges are now marked correctly as played.
This commit is contained in:
parent
5e9f16424c
commit
973666a42f
@ -352,33 +352,25 @@ public class BawkBawkBattles extends TeamGame implements IThrown
|
|||||||
{
|
{
|
||||||
int limit = _list.size();
|
int limit = _list.size();
|
||||||
int attemps = 0;
|
int attemps = 0;
|
||||||
boolean available = true;
|
|
||||||
|
|
||||||
Challenge instance = _list.select();
|
Challenge instance = _list.random();
|
||||||
|
|
||||||
while (!isSuitable(instance))
|
while (!isSuitable(instance))
|
||||||
{
|
{
|
||||||
if (attemps < limit)
|
if (attemps < limit)
|
||||||
{
|
{
|
||||||
instance = _list.select();
|
instance = _list.random();
|
||||||
attemps++;
|
attemps++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
available = false;
|
_list.resetPlayed();
|
||||||
break;
|
attemps = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (available)
|
System.out.println("Found matching challenge: " + instance.getName());
|
||||||
{
|
return instance;
|
||||||
System.out.println("Found matching challenge: " + instance.getName());
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSuitable(Challenge instance)
|
private boolean isSuitable(Challenge instance)
|
||||||
@ -889,6 +881,8 @@ public class BawkBawkBattles extends TeamGame implements IThrown
|
|||||||
_settings.markMessagesAsSending(false);
|
_settings.markMessagesAsSending(false);
|
||||||
_settings.markMessagesAsSent(false);
|
_settings.markMessagesAsSent(false);
|
||||||
|
|
||||||
|
_list.addPlayed(_challenge);
|
||||||
|
|
||||||
Damage = false;
|
Damage = false;
|
||||||
_challenge = null;
|
_challenge = null;
|
||||||
EndCheck();
|
EndCheck();
|
||||||
|
@ -11,13 +11,12 @@ public class ChallengeList
|
|||||||
private List<Challenge> _played = new ArrayList<>();
|
private List<Challenge> _played = new ArrayList<>();
|
||||||
private Challenge _restricted;
|
private Challenge _restricted;
|
||||||
|
|
||||||
public Challenge select()
|
public Challenge random()
|
||||||
{
|
{
|
||||||
if (_restricted == null)
|
if (_restricted == null)
|
||||||
{
|
{
|
||||||
if (_played.size() == _challenges.size())
|
if (_played.size() == _challenges.size())
|
||||||
{
|
{
|
||||||
System.out.println("All challenges played, resetting and selecting new one.");
|
|
||||||
_played.clear();
|
_played.clear();
|
||||||
return UtilMath.randomElement(_challenges);
|
return UtilMath.randomElement(_challenges);
|
||||||
}
|
}
|
||||||
@ -25,21 +24,16 @@ public class ChallengeList
|
|||||||
{
|
{
|
||||||
Challenge challenge = UtilMath.randomElement(_challenges);
|
Challenge challenge = UtilMath.randomElement(_challenges);
|
||||||
|
|
||||||
System.out.println("Attempt: " + challenge.getName());
|
|
||||||
|
|
||||||
while (_played.contains(challenge))
|
while (_played.contains(challenge))
|
||||||
{
|
{
|
||||||
System.out.println("Attempt (Loop): " + challenge.getName());
|
|
||||||
challenge = UtilMath.randomElement(_challenges);
|
challenge = UtilMath.randomElement(_challenges);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Selected: " + challenge.getName());
|
|
||||||
return challenge;
|
return challenge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.out.println("Restricted: " + _restricted.getName());
|
|
||||||
return _restricted;
|
return _restricted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,11 +46,21 @@ public class ChallengeList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addPlayed(Challenge challenge)
|
||||||
|
{
|
||||||
|
_played.add(challenge);
|
||||||
|
}
|
||||||
|
|
||||||
public void restrict(Challenge challenge)
|
public void restrict(Challenge challenge)
|
||||||
{
|
{
|
||||||
_restricted = challenge;
|
_restricted = challenge;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resetPlayed()
|
||||||
|
{
|
||||||
|
_played.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public void unrestrict()
|
public void unrestrict()
|
||||||
{
|
{
|
||||||
_restricted = null;
|
_restricted = null;
|
||||||
@ -66,4 +70,9 @@ public class ChallengeList
|
|||||||
{
|
{
|
||||||
return _challenges.size();
|
return _challenges.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int played()
|
||||||
|
{
|
||||||
|
return _played.size();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user