I'm trying to make a game where when I press the play button two random numbers will generate and the user has to put in the correct number. If they get the answer correct the image (it's a box) turns green and the counter goes up one point. If they get the answer wrong the counter is cleared and the box is clear again but the numbers are still the same.
that's my world code and here's what i have for my play button
I when I click on alli nothing happens but the numbers are still randomly generated. I'm also a bit confused on the counter and how the image will know when the answer is wrong or right.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import javax.swing.JOptionPane; /** * Write a description of class bathWorld here. * * @author (your name) * @version (a version number or a date) */ public class bathWorld extends World { String num = ""+ Greenfoot.getRandomNumber(10); String num2 = ""+ Greenfoot.getRandomNumber(10); /** * Constructor for objects of class bathWorld. * */ public bathWorld() { //string num = ""+ Greenfoot.getRandomNumber(10); //showText(num,100,100); super(600, 400, 1); showText(num,100,100); showText(num2,200,200); prepare(); } /** * Prepare the world for the start of the program. That is: create the initial * objects and add them to the world. */ private void prepare() { alli alli = new alli(); addObject(alli, 276, 356); }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import javax.swing.JOptionPane; /** * Write a description of class alli here. * * @author (your name) * @version (a version number or a date) */ public class alli extends Actor { int num1 = Greenfoot.getRandomNumber(10); int num2 = Greenfoot.getRandomNumber(10); int sum = num1 + num2; /** * Act - do whatever the alli wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if(Greenfoot.mouseClicked(this)) { JOptionPane.showInputDialog("sum"); } } }