Hi again guys! Changed the code slightly so in its current state it will work and reduce the counter, however it is the square above the basecamp (which is at 6,3). So, I increase the required value by one, however now it doesnt work, and when you inspect locationytwo it is still at 2, even tho intY (location) is equal to three. Please help.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class robottrackslarge here. * * @author (your name) * @version (a version number or a date) */ public class robot extends Actor //need to score passengers, add second level { private int choice; public void addedToWorld(World w) { world worldWorld = (world) w; Counter3 counter3 = worldWorld.getCounter3(); choice = counter3.getCount(); } private Counter2 theCounter2; private Counter theCounter; public int maximumcarrying=0; //maximum the robot can carry private int score=0; private int scorelevelone=150;//this sets the score private int scoreleveltwo=150; private boolean win=false; private int targetscore; //may need to remove this private int level=1; private int passengersleft=4; //number of passengers the robot needs to drop off private int passengerscarrying=0; //number of passengers the robot is carrying public int locationX; public int locationY; public boolean tester; public boolean testertwo=false; public int locationxtwo; public int locationytwo; /** * Act - do whatever the robot wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { maximumcarryingsetter();// Add your action code here. } //maybe try using a boolean to see whether the game has been won public void maximumcarryingsetter(){ //this will decide whether to keep the counter at 150 or lower it to 130 if (choice==1){ maximumcarrying=1; wintester(); } if (choice==2){ maximumcarrying=2; wintester(); } if (choice==3){ maximumcarrying=3; wintester(); } if (choice==4){ maximumcarrying=1; wintester(); } if (choice==5){ maximumcarrying=2; wintester(); } if (choice==6){ maximumcarrying=3; wintester(); } if (choice==7){ maximumcarrying=1; wintester(); } if (choice==8){ maximumcarrying=2; wintester(); } if (choice==9){ maximumcarrying=3; wintester(); } } public void setcounter(){ //this will decide whether to keep the counter at 150 or lower it to 130 if (level==2){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-20); scoretester(); } else{ scoretester(); } } public void wintester(){ //this will test if the game is won if(win==false){ scoretester(); } else{ win=false; setcounter(); //set the counter to 130 then begin level two } } public void scoretester(){ //this part checks to see that the game hasnt been won yet and links to wintester() world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); if (passengersleft==0&&counter.getCount()>0){ win=true; } else if(counter.getCount()<1&& passengersleft>0){ //display failure code and send to main menu. } else if(counter.getCount()>0&& passengersleft>0){ canmove(); } } public void canmove(){ int locationy =getY(); int testedlocationy; testedlocationy=locationy+1; if(testedlocationy>9){ movementnotdown(); } else{ movement(); } } public void movement() { if(Greenfoot.isKeyDown("right")) { move(1); Greenfoot.delay(10); floortesterIce(); } else if(Greenfoot.isKeyDown("left")) { move(-1); Greenfoot.delay(10); floortesterIce(); } else if(Greenfoot.isKeyDown("up")) { setLocation(getX(),getY()-1); Greenfoot.delay(10); floortesterIce(); } else if(Greenfoot.isKeyDown("down")) { setLocation(getX(),getY()+1); Greenfoot.delay(10); floortesterIce(); } } public void movementnotdown() { if(Greenfoot.isKeyDown("right")) { move(1); Greenfoot.delay(10); floortesterIce(); } else if(Greenfoot.isKeyDown("left")) { move(-1); Greenfoot.delay(10); floortesterIce(); } else if(Greenfoot.isKeyDown("up")) { setLocation(getX(),getY()-1); Greenfoot.delay(10); floortesterIce(); } } public void floortesterIce() { Actor Ice; Ice=getOneObjectAtOffset(0,0,Ice.class); if(Ice != null) { //this needs to go scoringmovementice(); } else{ floortestergrass(); } } public void floortestergrass() { Actor grass; grass=getOneObjectAtOffset(0,0,grass.class); if(grass != null) { scoringmovementgrass(); } else{ floortesterrock(); } } public void floortesterrock() { Actor rock; rock=getOneObjectAtOffset(0,0,rock.class); if(rock != null) { scoringmovementrock(); } else{ canmove(); } } public void scoringmovementgrass(){ if (choice==1){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-3); passengerpickuptester(); } if (choice==2){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-4); passengerpickuptester(); } if (choice==3){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-5); passengerpickuptester(); } if (choice==4){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-3); passengerpickuptester(); } if (choice==5){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-4); passengerpickuptester(); } if (choice==6){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-5); passengerpickuptester(); } if (choice==7){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-1); passengerpickuptester(); } if (choice==8){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-2); passengerpickuptester(); } if (choice==9){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-3); passengerpickuptester(); } } public void scoringmovementrock(){ if (choice==1){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-3); passengerpickuptester(); } if (choice==2){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-4); passengerpickuptester(); } if (choice==3){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-5); passengerpickuptester(); } if (choice==4){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-3); passengerpickuptester(); } if (choice==5){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-4); passengerpickuptester(); } if (choice==6){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-5); passengerpickuptester(); } if (choice==7){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-2); passengerpickuptester(); } if (choice==8){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-3); passengerpickuptester(); } if (choice==9){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-4); passengerpickuptester(); } } public void scoringmovementice(){ if (choice==1){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-1); passengerpickuptester(); } if (choice==2){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-2); passengerpickuptester(); } if (choice==3){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-3); passengerpickuptester(); } if (choice==4){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-3); passengerpickuptester(); } if (choice==5){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-4); passengerpickuptester(); } if (choice==6){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-5); passengerpickuptester(); } if (choice==7){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-3); passengerpickuptester(); } if (choice==8){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-4); passengerpickuptester(); } if (choice==9){ world worldWorld = (world) getWorld(); Counter counter = worldWorld.getCounter(); counter.bumpCount(-5); passengerpickuptester(); } } public void passengerpickuptester(){ Actor person; //tests to see if there is a person on the same square person=getOneObjectAtOffset(0,0,person.class); if(person != null) { //there is a person on that square testifcanpickuppassenger(); } else{ //there is not a person in that square atbasecamp(); } } public void testifcanpickuppassenger() { Actor person; person=getOneObjectAtOffset(0,0,person.class); if(passengerscarrying<maximumcarrying){ World world; world=getWorld(); world.removeObject(person); passengerscarrying=passengerscarrying+1; scoringpassengers(); //score for the passenger you just picked up } else{ atbasecamp(); } } public void scoringpassengers(){ world worldWorld = (world) getWorld(); Counter2 counter2 = worldWorld.getCounter2(); counter2.bumpCount2(1); atbasecamp(); } public void atbasecamp(){ testertwo=true; locationytwo =getY(); locationxtwo =getX(); Actor Basecamp; Basecamp=getOneObjectAtOffset(0,0,Basecamp.class); if(locationxtwo==6&&locationytwo==2) { //works if you set the y to two but one above the needed square. //there is a basecamp on that square tester=true; System.out.println("hello"); if(passengerscarrying>0){ world worldWorld = (world) getWorld(); Counter2 counter2 = worldWorld.getCounter2(); counter2.bumpCount2(-1); //need to sort this passengersleft=passengersleft-1; passengerscarrying=passengerscarrying-1; //basecampunload(); } else{ wintester(); } } else{ //there is not a person in that square wintester(); } } //Basecamp != null //public void basecampunload(){ this is all old i just dont want to lose it yet :-( //if(passengerscarrying>0){ // world worldWorld = (world) getWorld(); // Counter2 counter2 = worldWorld.getCounter2(); // counter2.bumpCount2(-1); //need to sort this // passengersleft=passengersleft-1; // passengerscarrying=passengerscarrying-1; // basecampunload(); // } // else{ // wintester(); // } //} }