jdkdoen05 wrote...
So we now did that but Player2 wins after just 1 second. The programm ends after just 2 seconds.import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Gegner here. * * @author (your name) * @version (a version number or a date) */ public class Spieler2 extends Mover { GreenfootImage gameName = new GreenfootImage ("Winner 2.png"); private int distanceCompleted; private int numberOfCheckPoints; public void act() { if (Greenfoot.isKeyDown("a")) { turn(-2); move(1); } if (Greenfoot.isKeyDown("d")) { turn(2); move(1); } if (Greenfoot.isKeyDown("s")) { move(); } if (Greenfoot.isKeyDown("w")) { backward(); } int numberOfCheckPoints = getWorld().getObjects(Checkpoint.class).size(); Checkpoint checkPoint = (Checkpoint)getOneIntersectingObject(Checkpoint.class); if (checkPoint != null && (distanceCompleted + 1)%numberOfCheckPoints == checkPoint.identificationNumber); { distanceCompleted++; if (distanceCompleted == 210*numberOfCheckPoints) { Greenfoot.setWorld(new Winner2()); } } { if(this.isTouching(Checkpoint.class)) this.numberOfCheckPoints = this.numberOfCheckPoints + 1; } { if(this.isTouching(Bariiere.class)) move(); } { if(this.isTouching(Oel.class)) turn(60); } } }
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) /** * Dies Klasse beschreibt eine Krabbe. * * @author (your name) * @version (a version number or a date) */ public class Spieler1 extends Mover { private int distanceCompleted; private int removeTouching; private int numberOfCheckPoints; public void act() { if (Greenfoot.isKeyDown("left")) { turn(-2); move(1); } if (Greenfoot.isKeyDown("right")) { turn(2); move(1); } if (Greenfoot.isKeyDown("down")) { move(); } if (Greenfoot.isKeyDown("up")) { backward(); } int numberOfCheckPoints = getWorld().getObjects(Checkpoint.class).size(); Checkpoint checkPoint = (Checkpoint)getOneIntersectingObject(Checkpoint.class); if (checkPoint != null && (distanceCompleted + 1)%numberOfCheckPoints == checkPoint.identificationNumber); { distanceCompleted++; if (distanceCompleted == 900*numberOfCheckPoints) { Greenfoot.setWorld (new Winner2()); } if(this.isTouching(Checkpoint.class)) { this.numberOfCheckPoints = this.numberOfCheckPoints + 1; } if(this.isTouching(Bariiere.class)) { move(); } if(this.isTouching(Spieler2.class)) { move(); } if(this.isTouching(Oel.class)) { turn(60); Greenfoot.delay(5); turn(60); Greenfoot.delay(5); turn(60); Greenfoot.delay(5); turn(60); Greenfoot.delay(5); turn(60); Greenfoot.delay(5); turn(60); removeTouching(Oel.class); removeTouching(Oelfleck.class); } } } }