So for my school project, I have two players and I want the player with the highest score to win. In my current code I have it so that if a player collects more 10 "WaterBlobs" they win, but I would like to change it so that the player with the highest score wins. My code for player 2 is the exact same besides the addObject and showText. If this is possible to do please let me know with an example on how to code it.
Thanks :)
public class Player_1 extends Actor
{
private int score;
collectWaterBlob();
public void act()
{
detectPluto();
}
public void detectPluto()
{
if (score > 9 && isTouching(Pluto.class))
{
World world = getWorld();
world.addObject(new Player_1_Wins(), world.getWidth()/2, world.getHeight()/2);
Greenfoot.playSound("Victory.mp3");
Greenfoot.stop();
}
}
public void collectWaterBlob()
{
if (isTouching(WaterBlob.class))
{
removeTouching(WaterBlob.class);
Greenfoot.playSound("drip.mp3");
increaseScore();
World world = getWorld();
world.addObject(new WaterBlob(), Greenfoot.getRandomNumber(1690), Greenfoot.getRandomNumber(900));
}
public void increaseScore()
{
score++;
showStatus();
}
public void showStatus()
{
getWorld().showText("Player 1 Score : "+score, 93,865);
}
}
