I'm having some trouble with my game. The plan is to decide if certain pictures of people and their ID cards are matched, or not. The game has an 'allow' and a 'deny' button to use for this decision. The problem I ran into was rather strange; The game has to decide if the decission the user made was correct or not. The user has 3 'lives'/'hearts' which go down by 1 each time the user makes a mistake. But instead of deciding if the shown picture and ID card were a match, the game seems to decide if the next two are a match or not. And that kinda messes up the entire "life-system" ... Here's the code that generates the combinations and the code that decides if it's right or wrong;
Anyone who thinks he/she has the answer, thanks in advance!
if(Greenfoot.mouseClicked(this))
{
getWorld().removeObjects(getWorld().getObjects(Dirk.class));
getWorld().removeObjects(getWorld().getObjects(Fleur.class));
getWorld().removeObjects(getWorld().getObjects(Coen.class));
getWorld().removeObjects(getWorld().getObjects(Remco.class));
int RandomNum = Greenfoot.getRandomNumber(4);
int RandomNum2 = Greenfoot.getRandomNumber(50);
if (RandomNum == 0){
getWorld().addObject (new Dirk(),120,140);
} else if (RandomNum == 1) {
getWorld().addObject (new Fleur(),120,140);
} else if (RandomNum == 2) {
getWorld().addObject (new Coen(),120,140);
} else if (RandomNum == 3) {
getWorld().addObject (new Remco(),120,140);
}
..
if (RandomNum == 0){
if (RandomNum2 <= 30){
getWorld().addObject (new IdcardDirk(),120,620);
} else if (RandomNum2 >= 30) {
getWorld().addObject (new IdcardFleur(),120,620);
} else if (RandomNum2 >= 37) {
getWorld().addObject (new IdcardCoen(),120,620);
} else if (RandomNum2 >= 44) {
getWorld().addObject (new IdcardRemco(),120,620);
}
} else if (RandomNum == 1){
if (RandomNum2 >= 30){
getWorld().addObject (new IdcardDirk(),120,620);
} else if (RandomNum2 <= 30) {
getWorld().addObject (new IdcardFleur(),120,620);
} else if (RandomNum2 >= 37) {
getWorld().addObject (new IdcardCoen(),120,620);
} else if (RandomNum2 >= 44) {
getWorld().addObject (new IdcardRemco(),120,620);
}
} else if (RandomNum == 2){
if (RandomNum2 >= 44){
getWorld().addObject (new IdcardDirk(),120,620);
} else if (RandomNum2 >= 37) {
getWorld().addObject (new IdcardFleur(),120,620);
} else if (RandomNum2 <= 30) {
getWorld().addObject (new IdcardCoen(),120,620);
} else if (RandomNum2 >= 30) {
getWorld().addObject (new IdcardRemco(),120,620);
}
} else if (RandomNum == 3){
if (RandomNum2 >= 37){
getWorld().addObject (new IdcardDirk(),120,620);
} else if (RandomNum2 >= 44) {
getWorld().addObject (new IdcardFleur(),120,620);
} else if (RandomNum2 >= 30) {
getWorld().addObject (new IdcardCoen(),120,620);
} else if (RandomNum2 <= 30) {
getWorld().addObject (new IdcardRemco(),120,620);
}
...
...
...
if(isGeraakt1())
{
removeHealth();
}
if(isGeraakt2())
{
removeHealth();
}
if(isGeraakt3())
{
removeHealth();
}
if(isGeraakt4())
{
removeHealth();
}
public boolean isGeraakt1()
{
boolean raak = false;
int RandomNum = Greenfoot.getRandomNumber(4);
int RandomNum2 = Greenfoot.getRandomNumber(50);
if ( RandomNum == 0 && RandomNum2 <= 30 && Greenfoot.mouseClicked(this))
{
raak = true;
}
return raak;
}
public boolean isGeraakt2()
{
boolean raak = false;
int RandomNum = Greenfoot.getRandomNumber(4);
int RandomNum2 = Greenfoot.getRandomNumber(50);
if ( RandomNum == 1 && RandomNum2 <= 30 && Greenfoot.mouseClicked(this))
{
raak = true;
}
return raak;
}
public boolean isGeraakt3()
{
boolean raak = false;
int RandomNum = Greenfoot.getRandomNumber(4);
int RandomNum2 = Greenfoot.getRandomNumber(50);
if ( RandomNum == 2 && RandomNum2 <= 30 && Greenfoot.mouseClicked(this))
{
raak = true;
}
return raak;
}
public boolean isGeraakt4()
{
boolean raak = false;
int RandomNum = Greenfoot.getRandomNumber(4);
int RandomNum2 = Greenfoot.getRandomNumber(50);
if ( RandomNum == 3 && RandomNum2 <= 30 && Greenfoot.mouseClicked(this))
{
raak = true;
}
return raak;
}
public void removeHealth()
{
Controlecentrum subWorld = (Controlecentrum) getWorld();
Heart HeartObject = (Heart) subWorld.getObjects(Heart.class).get(0);
HeartObject.adjustValue(-1);
if (HeartObject.getValue() == 0) removeLive();
}
public void removeLive()
{
int lives = getWorld().getObjects(Heart.class).size();
getWorld().removeObject((Actor)getWorld().getObjects(Heart.class).get(lives-1));
if (lives != 1)
{
//
}
else
{
Greenfoot.setWorld(new GameOverScreen());
}
