/**
* Write a description of class ScoreBoard here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ScoreBoard extends Actor
{
public static final float FONT_SIZE = 48.0f;
public static final int WIDTH = 400;
public static final int HEIGHT = 300;
/**
* Create a score board with dummy result for testing.
*/
public ScoreBoard()
{
this(100);
}
/**
* Create a score board for the final result.
*/
public ScoreBoard(int score)
{
makeImage("Game Over", "Score: ", score);
}
/**
* Make the score board image.
*/
private void makeImage(String title, String prefix, int score)
{
GreenfootImage image = new GreenfootImage(WIDTH, HEIGHT);
image.setColor(Color.red);
image.fillRect(0, 0, WIDTH, HEIGHT);
image.setColor(new Color(255, 255, 255, 100));
image.fillRect(5, 5, WIDTH-10, HEIGHT-10);
Font font = image.getFont();
font = font.deriveFont(FONT_SIZE);
image.setFont(font);
image.setColor(Color.WHITE);
image.drawString(title, 60, 100);
image.drawString(prefix + score, 60, 200);
setImage(image);
}
}
at the end when image,sercolor the symbol variable red is not find / another problem
/**
* Write a description of class barrier here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Barrier extends Actor
{
public int hp =4;
private GreenfootImage img1;
private GreenfootImage img2;
private GreenfootImage img3;
private GreenfootImage img4;
public Barrier()
{
img1 = getImage();
img2 = new GreenfootImage("barrier-2.gif");
img3 = new GreenfootImage("barrier-3.gif");
img4 = new GreenfootImage("barrier-4.gif");
}
/**
* Act - do whatever the barrier wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
List bullets = getNeighbours(5, false, Ebullet.class); //new list with all Pbullets within 2 uinits adjacent to the enemy
if (!bullets.isEmpty()) { //is there is one (there will only be one, since only one bullet on screen at a time)
Actor b = (Actor) bullets.get(0); //gets the first object in the list
if (b instanceof Ebullet) { //just an extra check to make sure its a player bullet
getWorld().removeObject(b); //remobe the bullet
hp--;
if (hp <= 0) {
getWorld().removeObject(this);
} else {
switch (hp) {
case 3: setImage(img2); break;
case 2: setImage(img3); break;
case 1: setImage(img4); break;
}
}
}
} else {
List bullets2 = getNeighbours(3, false, Pbullet.class); //new list with all Pbullets within 2 uinits adjacent to the enemy
if (!bullets2.isEmpty()) { //is there is one (there will only be one, since only one bullet on screen at a time)
Actor b = (Actor) bullets2.get(0); //gets the first object in the list
if (b instanceof Pbullet) { //just an extra check to make sure its a player bullet
getWorld().removeObject(b); //remobe the bullet
((Space) getWorld()).ShootSet(1);
hp--;
if (hp <= 0) {
getWorld().removeObject(this);
} else {
switch (hp) {
case 3: setImage(img2); break;
case 2: setImage(img3); break;
case 1: setImage(img4); break;
}
}
}
}
}
}
}
list bullets is not working