This site requires JavaScript, please enable it in your browser!
Greenfoot back
ando600
ando600 wrote ...

2015/10/18

Skipping Through Worlds

ando600 ando600

2015/10/18

#
Hi. My code skips directly through the fight world, and goes directly to the lose world. I have put in ridiculous parameters which should never be met, and the code still skips through the world. Here is my StartWorld class: import greenfoot.*; /** * Write a description of class StartWorld here. * * @author (your name) * @version (a version number or a date) */ public class StartWorld extends World { /** * Constructor for objects of class StartWorld. * */ public StartWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 400, 1); } public void act() { if (getObjects(startScreen.class).isEmpty()) showStartScreen(); if(Greenfoot.isKeyDown("s")) { Greenfoot.setWorld(new Crossroads()); } } public void showStartScreen() { addObject(new startScreen(), getWidth() / 2, getHeight() / 2); } } Here is my Crossroads class: import greenfoot.*; import java.awt.Color; /** * Write a description of class Crossroads here. * * @author (your name) * @version (a version number or a date) */ public class Crossroads extends World { public BarOne barone = new BarOne("FighterOne", "Health Points", 100, 100); public BarTwo bartwo = new BarTwo("FighterTwo", "Health Points", 100, 100); private int FighterOneDeath, FighterTwoDeath; private int setWorldCounter = 0; private int worldCounter = 0; private boolean setWorldTrue = false; /** * Constructor for objects of class Crossroads. * */ public Crossroads() { super(1200, 400, 1); 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() { Road road = new Road(); addObject(road, 601, 394); road.setLocation(601, 394); FighterOne fighterone = new FighterOne(); addObject(fighterone, 258, 278); fighterone.setLocation(1085, 290); fighterone.setLocation(1181, 292); road.setLocation(867, 147); removeObject(road); removeObject(fighterone); Road road2 = new Road(); addObject(road2, 602, 394); road2.setLocation(601, 394); FighterOne fighterone2 = new FighterOne(); addObject(fighterone2, 200, 300); hitBoxOne hitboxone = new hitBoxOne(); addObject(hitboxone, 200, 300); FighterTwo fightertwo2 = new FighterTwo(); addObject(fightertwo2, 1000, 300); hitBoxTwo hitboxtwo = new hitBoxTwo(); addObject(hitboxtwo, 1000, 300); addObject(bartwo, 900, 60); addObject(barone, 300, 60); } public void act() { FighterOneDeath = barone.getValue(); FighterTwoDeath = bartwo.getValue(); setWorldTrue = false; worldCounter ++; worldCounter(); setWorld(); if (FighterOneDeath < 1) { setWorldTrue = true; if (getObjects(GameOver.class).isEmpty()) showGameOverTwo(); return; } if (FighterTwoDeath < 1) { setWorldTrue = true; if (getObjects(GameOver.class).isEmpty()) showGameOver(); return; } } private void showGameOver() { addObject(new GameOver(), getWidth() / 2, getHeight() / 2); } private void showGameOverTwo() { addObject(new GameOverTwo(), getWidth() / 2, getHeight() / 2); } private void worldCounter() { if(worldCounter > 10000) { if (setWorldTrue == true) { setWorldCounter++; } } } private void setWorld() { if(setWorldCounter >= 1000000000); { setWorldCounter = 0; setWorldTrue = false; Greenfoot.setWorld(new LoseWorld()); } } } Thank you in advance for any help.
danpost danpost

2015/10/18

#
Remove the semicolon at the end of your ridiculously huge conditional 'if'. It, in essence, is equivalent to an empty set of squiggly brackets, '{}' (ending the 'if' block entirely).
ando600 ando600

2015/10/18

#
Thanks. Didn't see that. Dumb mistake.
You need to login to post a reply.