-
Notifications
You must be signed in to change notification settings - Fork 1
/
DisplayListScore.java
53 lines (46 loc) · 1.42 KB
/
DisplayListScore.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class DisplayListScore here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class DisplayListScore extends Actor
{
private ListPlayers listPlayers = new ListPlayers();
private final int gap = 20;
private int xLocation;
private int yLocation;
private int spawnY;
private boolean valid;
DisplayListScore(int xLocation, int yLocation)
{
this.xLocation = xLocation;
this.yLocation = yLocation;
this.spawnY = yLocation + gap;
this.valid = true;
}
public void act()
{
if(valid)
{
World myWorld = getWorld();
myWorld.showText("Current Highscore", xLocation, yLocation);
if(listPlayers.getPlayers().size() > 5){
displayList(5, myWorld);
} else {
displayList(listPlayers.getPlayers().size(), myWorld);
}
valid = false;
}
}
public void displayList(int length, World myWorld)
{
for(int i = 0; i < length; i++)
{
spawnY += gap;
myWorld.showText(listPlayers.getPlayerName(i), xLocation - 50, spawnY);
myWorld.showText(String.valueOf(listPlayers.getPlayerScore(i)), xLocation + 70, spawnY);
}
}
}