Refactor Dogs Vs Cats challenge

This commit is contained in:
Thanos Paravantis 2016-07-01 17:04:06 +03:00
parent 8101fced7b
commit 6fdbda0ed0

View File

@ -39,19 +39,18 @@ public class ChallengeDogsVersusCats extends TeamChallenge
{
private int _catScore = 0;
private int _dogScore = 0;
private final int _scorePerPlayer = 50;
private int _scorePerPlayer = 50;
public ChallengeDogsVersusCats(BawkBawkBattles host)
{
super(
host,
ChallengeType.FirstComplete,
"Cats",
"Dogs",
"Cats",
"Dogs Vs Cats",
"If you are a dog, bark.",
"If you are a cat, meow.",
"Look up and punch to bark or meow.",
"First team to the end number wins!");
Settings.setUseMapHeight();
@ -124,23 +123,11 @@ public class ChallengeDogsVersusCats extends TeamChallenge
if (looped % 2 == 0)
{
getSecondTeam().add(player);
DisguiseWolf Ddog = new DisguiseWolf(player);
Host.getArcadeManager().GetDisguise().disguise(Ddog);
player.getInventory().setItem(Settings.getLockedSlot(), ItemStackFactory.Instance.CreateStack(Material.BONE, (byte) 0, 1, C.Reset + C.Bold + "Bark"));
UtilPlayer.message(player, F.main("Game", "You are a " + C.cGreen + "Dog" + C.mBody + ", bark!"));
addToDogTeam(player);
}
else
{
getFirstTeam().add(player);
DisguiseCat Dcat = new DisguiseCat(player);
Host.getArcadeManager().GetDisguise().disguise(Dcat);
player.getInventory().setItem(Settings.getLockedSlot(), ItemStackFactory.Instance.CreateStack(Material.STRING, (byte) 0, 1, C.Reset + C.Bold + "Meow"));
UtilPlayer.message(player, F.main("Game", "You are a " + C.cGreen + "Cat" + C.mBody + ", meow!"));
addToCatTeam(player);
}
looped++;
@ -163,25 +150,11 @@ public class ChallengeDogsVersusCats extends TeamChallenge
if (!isChallengeValid())
return;
int catScore = calculateScore(getFirstTeam());
int dogScore = calculateScore(getSecondTeam());
int maxDogScore = calculateScore(getFirstTeam());
int maxCatScore = calculateScore(getSecondTeam());
UtilTextMiddle.display("", C.cBlue + C.Bold + " Dogs: " + C.cGreen + _dogScore + "/" + dogScore + C.cGray + " - " + C.cRed + C.Bold + "Cats: " + C.cGreen + _catScore + "/" + catScore);
if (_catScore >= catScore)
{
for (Player player : getFirstTeam().getPlayers())
{
setCompleted(player);
}
}
else if (_dogScore >= dogScore)
{
for (Player player : getSecondTeam().getPlayers())
{
setCompleted(player);
}
}
displayScore(maxDogScore, maxCatScore);
checkScore(maxDogScore, maxCatScore);
}
@EventHandler
@ -193,21 +166,8 @@ public class ChallengeDogsVersusCats extends TeamChallenge
if (!isChallengeValid())
return;
for (Player player : getFirstTeam().getPlayers())
{
if (isPlayerValid(player))
{
UtilTextBottom.display(C.Bold + "Left-Click to Meow!", player);
}
}
for (Player player : getSecondTeam().getPlayers())
{
if (isPlayerValid(player))
{
UtilTextBottom.display(C.Bold + "Left-Click to Woof!", player);
}
}
showTipsForDogs();
showTipsForCats();
}
@EventHandler
@ -227,41 +187,114 @@ public class ChallengeDogsVersusCats extends TeamChallenge
if (item.getType() == Material.BONE || item.getType() == Material.STRING)
{
Location loc = player.getLocation();
if (getFirstTeam().isMember(player))
{
incrementCatScore();
player.playSound(event.getPlayer().getLocation(), Sound.CAT_MEOW, 1f, 1f);
incrementDogScore();
player.playSound(loc, Sound.WOLF_BARK, 1f, 1f);
}
else
{
incrementDogScore();
player.playSound(event.getPlayer().getLocation(), Sound.WOLF_BARK, 1f, 1f);
incrementCatScore();
player.playSound(loc, Sound.CAT_MEOW, 1f, 1f);
}
UtilParticle.PlayParticle(ParticleType.NOTE, event.getPlayer().getLocation().add(0.5, 1, 0.5), 0.5f, 0.5f, 0.5f, 0f, 2, ViewDist.MAX,
UtilServer.getPlayers());
UtilParticle.PlayParticle(ParticleType.NOTE, loc.add(0.5, 1, 0.5), 0.5F, 0.5F, 0.5F, 0F, 5, ViewDist.LONG, UtilServer.getPlayers());
}
}
}
private void addToDogTeam(Player player)
{
getFirstTeam().add(player);
DisguiseWolf dog = new DisguiseWolf(player);
Host.getArcadeManager().GetDisguise().disguise(dog);
player.getInventory().setItem(Settings.getLockedSlot(), ItemStackFactory.Instance.CreateStack(Material.BONE, (byte) 0, 1, C.Reset + C.Bold + "Bark"));
UtilPlayer.message(player, F.main("Game", "You are a " + C.cGreen + "Dog" + C.mBody + ", bark!"));
}
private void addToCatTeam(Player player)
{
getSecondTeam().add(player);
DisguiseCat Dcat = new DisguiseCat(player);
Host.getArcadeManager().GetDisguise().disguise(Dcat);
player.getInventory().setItem(Settings.getLockedSlot(), ItemStackFactory.Instance.CreateStack(Material.STRING, (byte) 0, 1, C.Reset + C.Bold + "Meow"));
UtilPlayer.message(player, F.main("Game", "You are a " + C.cGreen + "Cat" + C.mBody + ", meow!"));
}
private void displayScore(int maxDogScore, int maxCatScore)
{
UtilTextMiddle.display(null, C.cBlueB + "Dogs: " + C.cWhite + _dogScore + "/" + maxDogScore + C.cGray + " - " + C.cRedB + "Cats: " + C.cWhite + _catScore + "/" + maxCatScore);
}
private void checkScore(int maxDogScore, int maxCatScore)
{
if (_dogScore >= maxDogScore)
{
for (Player player : getFirstTeam().getPlayers())
{
setCompleted(player);
}
}
else if (_catScore >= maxCatScore)
{
for (Player player : getSecondTeam().getPlayers())
{
setCompleted(player);
}
}
}
private void showTipsForDogs()
{
for (Player player : getFirstTeam().getPlayers())
{
if (isPlayerValid(player))
{
UtilTextBottom.display(C.Bold + "Left-Click to Woof!", player);
}
}
}
private void showTipsForCats()
{
for (Player player : getSecondTeam().getPlayers())
{
if (isPlayerValid(player))
{
UtilTextBottom.display(C.Bold + "Left-Click to Meow!", player);
}
}
}
private void incrementDogScore()
{
int maxScore = calculateScore(getFirstTeam());
if (_dogScore < maxScore)
{
_dogScore++;
}
}
private void incrementCatScore()
{
int maxScore = calculateScore(getFirstTeam());
if (_catScore < maxScore)
_catScore++;
}
private void incrementDogScore()
{
int maxScore = calculateScore(getSecondTeam());
if (_dogScore < maxScore)
_dogScore++;
if (_catScore < maxScore)
{
_catScore++;
}
}
@SuppressWarnings("unused")
public int calculateScore(ChallengeTeam team)
private int calculateScore(ChallengeTeam team)
{
int amountOnTeam = 0;