Posted this before but no one commented. Really need help. Been trying for two weeks to get this working but no success. So please help!!
So I am trying to get bet() to run until a bet is selected, and then no longer run. However, it won't work. Even if the value changes to 1, 2, 3, or 4, bet doesn't run. If i try to run bet() outside of an if statement, it works but adds infinite amount of horses until Greenfoot.stop;
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) public class RaceWorld extends World { /** * Constructor for objects of class RaceWorld. * */ public RaceWorld() { // Create a new world with 1200x600 cells with a cell size of 1x1 pixels. super(1200, 600, 1); addObject( new BetWindow(), 570, 440); addObject( new HorseBet(), 1125, 490); addObject( new Money(), 1110, 35); } public void act() { int value = ((HorseBet) getObjects(HorseBet.class).get(0)).getValue(); bet(); if ( value == 0) { bet(); } else { //nothing } } public void bet() { int value = ((HorseBet) getObjects(HorseBet.class).get(0)).getValue(); if ( value == 1) { removeObjects(getObjects(BetWindow.class)); addObject( new Horse1(), 50, 80); addObject( new Horse2(), 50, 152); addObject( new Horse3(), 50, 222); addObject( new Horse4(), 50, 296); } else if ( value == 2) { removeObjects(getObjects(BetWindow.class)); addObject( new Horse1(), 50, 80); addObject( new Horse2(), 50, 152); addObject( new Horse3(), 50, 222); addObject( new Horse4(), 50, 296); } else if ( value == 3) { removeObjects(getObjects(BetWindow.class)); addObject( new Horse1(), 50, 80); addObject( new Horse2(), 50, 152); addObject( new Horse3(), 50, 222); addObject( new Horse4(), 50, 296); } else if ( value == 4) { removeObjects(getObjects(BetWindow.class)); addObject( new Horse1(), 50, 80); addObject( new Horse2(), 50, 152); addObject( new Horse3(), 50, 222); addObject( new Horse4(), 50, 296); } else { //nothing } } public void started() { //code } }