Ich habe einen Score Actor hinzugefügt, welcher den Score oben im Bildschirm anzeigt und jede Sekunde um eins erhöht.

This commit is contained in:
2026-09-15 19:57:22 +02:00
parent 024738ff62
commit d7645d43f0
5 changed files with 42 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class UI here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Score extends Actor
{
int timer;
/**
* Act - do whatever the UI wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
timer++;
draw_score();
}
public void draw_score(){
setImage(new GreenfootImage("Score:" + calculate_score(), 24, Color.WHITE, Color.BLACK));
}
public int calculate_score(){
return timer/60;
}
}