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:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user