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

2012/4/22

compiling problems with game over screen

danbhome danbhome

2012/4/22

#
this is the game over calss code import Greenfoot.*; import java.awt.Color; public class GameOver extends Actor { String msgTxt = "GAME OVER"; public GameOver() { updateImage(); } public GameOver(String txt) { msgTxt = txt; updateImage(); } private void updateImage() { GreenfootImage image = new GreenfootImage(getWorld().getWidth(), getWorld().getHeight()); // or whatever size you want the object image.setColor(Color.cyan); // color of your choice image.fill(); GreenfootImage txtImg = new GreenfootImage(msgTxt, 36, Color.black, new Color(0, 0, 0, 0)); // colors and font size of your choice image.drawImage(txtImg, (image.getWidth() - txtImg.getWidth()) / 2, (image.getHeight() - txtImg.getHeight) / 2); // whatever else you might want to do for the image setImage(image); } } /** * Write a description of class gameover here. * * @author (your name) * @version (a version number or a date) */ public class gameover extends Actor { /** * Act - do whatever the gameover wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { // Add your action code here. } } and this is the world code /** * Write a description of class world1 here. * a green swirly world * @author (your name) * @version (a version number or a date) */ public class world1 extends World { private counter thecounter; /** * Constructor for objects of class world1. * */ public world1() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 400, 1); thecounter = new counter(); addObject(thecounter, 40, 340); prepare(); //addbattery(); } /** * Prepare the world for the start of the program. That is: create the initial * objects and add them to the world. */ private void prepare() { frownyface frownyface = new frownyface(); addObject(frownyface, 559, 150); you you = new you(); addObject(you, 250, 34); you.setRotation(360); battery battery = new battery(); addObject(battery, 310, 43); Zapper zapper = new Zapper(); addObject(zapper, 300, 28); battery.setLocation(300, 361); } //public void addbattery() //{ // if (getObjects(battery.class).size() == 0)addObject(battery, 20, 390); // } /** * * * * */ public counter getcounter() { return thecounter; } public act; void() { if (getObjects(you.class).isEmpty()) addObject(new GameOver(), getWidth() / 2, getHeight() / 2); Greenfoot.stop(); return; } } }
danbhome danbhome

2012/4/22

#
compiling problem says that in world after act it says <identifier> expected. also for game over it says class gameover is in public, should be declared in a file named gameover.java
nccb nccb

2012/4/23

#
On Windows, file names are not case sensitive. So if you try to create "FILE.txt" and "file.txt", those will be the same file. When you make a GameOver class and a gameover class, Greenfoot will try to store them in "GameOver.java" and "gameover.java". In Windows, I'm not sure what this will do, but it can't end well. Make sure your classes differ by something other than case. If your GameOver classes and gameover class are in the same file (hard to tell), you'll need to split them up (and still rename one of them).
danbhome danbhome

2012/4/26

#
this all in one Gameover class
Duta Duta

2012/4/26

#
After replying to your post on a different thread (about this issue, I assume you just clicked on the wrong thread), I see that you have done what I thought. Like I said, change import Greenfoot.*; to import greenfoot.*;
danpost danpost

2012/4/26

#
The compiler points to 'public act; void()', which it does not understand as it should be 'public void act()'.
You need to login to post a reply.