I'm coding for my end of the year project and I wasn't sure how to code this.
So my game has the player move around and when he picks up an item (removeTouching), I want a confirm dialog to pop up and ask a trivia question that can be answered with a yes/no/cancel option. The code below is what I have so far however it does not work, no confrim dialog pops up like it should. Any help would be appreciated, thank you
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import javax.swing.JOptionPane;
/**
* Player
* Yubin
* May 30
* this code includes all the things that the player willing be doing (?)
*/
public class Player extends Actor
{
public boolean appleBool; //declaring our booleans here, they are automatically set to "false"
public boolean teddyBool;
public boolean fishBool;
public boolean spiderBool;
public void act()
{
checkKeyPress(); //calling key control method
//world1 items
//we're checking to see what object is touched before removing it and
//only executing the check if that object isnt removed yet (using our created boolean)
if(isTouching(Apple.class) && !appleBool)
{
removeTouching(Apple.class); //apple disappears when player touches it
appleBool = true;
}
else if(isTouching(Teddy.class) && !teddyBool)
{
removeTouching(Teddy.class); //teddy disappears when player touches it
teddyBool = true;
}
else if(isTouching(Fish.class) && !fishBool)
{
removeTouching(Fish.class); //fish disappears when player touches it
fishBool = true;
}
else if(isTouching(Spider.class) && !spiderBool)
{
removeTouching(Spider.class); //spider disappears when player touches it
spiderBool = true;
}
if (appleBool) //now because we've assigned the boolean to true, this block will be called
{
JOptionPane.showMessage(null, "Are apples and oranges the same". YES_NO_OPTION);
appleBool = false;
}
else if(teddyBool)
{
JOptionPane.showMessage(null, "Cuddle me". YES_NO_OPTION);
teddyBool = false;
}
else if(fishBool)
{
JOptionPane.showMessage(null, "Something smells". YES_NO_OPTION);
fishBool = false;
}
if(spiderBool)
{
JOptionPane.showMessage(null, "Do you like spiders?". YES_NO_OPTION);
spiderBool = false;
}
if (isAtEdge())
{
turn(20);
}
//player bounces off the screen
}
//user controls
public void checkKeyPress()
{
if (Greenfoot.isKeyDown("left"))
{
move(-2);
}
if (Greenfoot.isKeyDown("right"))
{
move(2);
}
setRotation(90);
if (Greenfoot.isKeyDown("up"))
{
move(-2);
}
if (Greenfoot.isKeyDown("down"))
{
move(2);
}
setRotation(0);
}
}
