So i have a race car game and i want it to end, when a car drove 3 times the circuit. How do I do it? Has someone a code for it?
How can the game endlike this.
if(isTouching(CheckPoint.class) && distanceCompleted + 1)%numberOfCheckPoints == identificationNumber) { distanceCompleted++; if (distanceCompleted == 3*numberOfCheckPoints) gameOver(); }
int numberOfCheckPoints = getWorld().getObjects(CheckPoint.class).size();
import greenfoot.*; public class CheckPoint extends Actor { int identificationNumber; public CheckPoint(int id) { identificationNumber = id; if (id != 0) getImage().clear(); } }
addObject(new CheckPoint(0), 200, 100);
CheckPoint checkPoint = (CheckPoint)getOneIntersectingObject(CheckPoint.class); if (checkPoint != null && (distanceCompleted+1)%numberOfCheckPoints == checkPoint.identificationNumber) { ...//etc (continued as above).
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) /** * Dies Klasse beschreibt eine Krabbe. * Krabben leben am Strand. Sie lieben Sandwürmer ... * * @author Michael Kolling * @author Gunnar Johannesmeyer (Übersetzung und kleinere Anpassung) * @version 1.0 */ public class Spieler1 extends Object { private int distanceCompleted; private int identificationNumber; public Spieler1() { distanceCompleted=0; identificationNumber=1000; } public void act() { int numberOfCheckPoints = getWorld().getObjects(Checkpoint.class).size(); if(isTouching(Checkpoint.class) && (distanceCompleted + 1)%numberOfCheckPoints == identificationNumber); { distanceCompleted++; if (distanceCompleted == 18*numberOfCheckPoints) { setImage("spieler1win.png"); setLocation(500, 400); setRotation(0); Greenfoot.stop(); Greenfoot.stop(); } if (Greenfoot.isKeyDown("left")) { turn(-2); } if (Greenfoot.isKeyDown("right")) { turn(2); } if (Greenfoot.isKeyDown("up")) { move(); } if(Greenfoot.isKeyDown("down")) { backward(); } } } }
import greenfoot.*; public class Spieler1 extends Actor // note below code { private int distanceCompleted; public void act() { if (Greenfoot.isKeyDown("left")) turn(-2); if (Greenfoot.isKeyDown("right"))turn(2); if (Greenfoot.isKeyDown("up")) move(); if (Greenfoot.isKeyDown("down")) 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 == 18*numberOfCheckPoints) { setImage("spieler1win.png"); setLocation(500, 400); setRotation(0); Greenfoot.stop(); } } } }