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

2019/10/29

How can I make a score counter ?

BestMannCZ BestMannCZ

2019/10/29

#
Hey, how can I make a score counter ? I wanna get 10 point after 1 Vcela died import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Louka here. * * @author (your name) * @version (a version number or a date) */ public class Louka extends World { public void pridejVcelu() { Vcela v = new Vcela(); int x = Greenfoot.getRandomNumber(this.getWidth()); int y = Greenfoot.getRandomNumber(this.getHeight()); this.addObject(v, x, y); } public Louka() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(1177, 768, 1); for(int i=0; i<10; i++) { this.pridejVcelu(); } } private int timer = 4000; public void act() { timer--; if (timer <= 0) { Greenfoot.stop(); // pause the execution of the program if 'timer' is less than or equal to 0 } } public void smazVcely() { int x = Greenfoot.getRandomNumber(this.getWidth()); int y = Greenfoot.getRandomNumber(this.getHeight()); removeObjects(getObjects(null)); for(int i=0; i<10; i++) { this.pridejVcelu(); } } }
BestMannCZ BestMannCZ

2019/10/29

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Vcela here. * * @author (your name) * @version (a version number or a date) */ public class Vcela extends Actor { /** * Act - do whatever the Vcela wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (Greenfoot.mouseClicked(this)) { ((Louka) getWorld()).smazVcely(); } } }
You need to login to post a reply.