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

2017/6/13

Title/Start screen

1
2
3
SchoolStuff SchoolStuff

2017/6/15

#
Ok, I have only one problem now, I made a game over screen just like the title screen, but if I use this code it won't work, do I make another game over thing but this time in class or is there a way to use the one thaf I made in th world.
danpost danpost

2017/6/15

#
For game over, you can use something like the following in your world act method:
if (getObjects(Block.class).isEmpty()) wonGame();
if (Greenfoot.mouseClicked(this)) lostGame();
Then create the methods 'wonGame' and 'lostGame' to do whatever is needed in each.
SchoolStuff SchoolStuff

2017/6/16

#
So we made 3 counters and I have put all the codes but it still won't work, I get an error if I put this code private Counter_w1() { counter_w1 = new counter_w1("Score : "); addObject(counter_w1, 300, 50); } counter_w1 counter_w1 = new counter_w1(); it can't find class or it says constructor counter_w1 in class counter_w1 cannot be applied to given types; required: java.lang.String; found: no aguments; reason: actual and formal argument lists differ in length. And if I import java.lang.String.*; it still won't work.
danpost danpost

2017/6/16

#
You really need to show the entire class -- and have the code indented properly -- and use code tags (see here).
SchoolStuff SchoolStuff

2017/6/16

#
If I put this code public class Tile extends Actor { public void act() { if (Greenfoot.mouseClicked(this)) { //code for pressed tile } } I only get points if I click on the background, but I only want to get points if I click on the blocks, I only want to use this code, because the other ones keep giving me errors, I won't make "if the block is out the screen and you haven't clicked on it yet game over", because that is too much work and I have to hand it in soon.
SchoolStuff SchoolStuff

2017/6/16

#
SchoolStuff SchoolStuff

2017/6/16

#
public void act() {
     this.setLocation (getX(), getY() +1);
        if (getY()>getWorld().getHeight()+10)
        {
            this.getWorld().removeObject(this);
        }
        if (Greenfoot.mousePressed(this)) 
        {
            Greenfoot.playSound(soundfile);
            turnWhite();
        }    
 if (Greenfoot.mouseClicked(this)) {
            //code for pressed tile
        }
    }
I mean this is what I used
danpost danpost

2017/6/16

#
Remove:
if(Greenfoot.mouseClicked(null)){
            addScore();
from the counter class. Use:
public class Tile extends Actor {
    public void act() {
        if (Greenfoot.mouseClicked(this)) {
            ((Counter)getWorld().getObjects(Counter.class).get(0)).addScore();
        }
    }
}
SchoolStuff SchoolStuff

2017/6/16

#
Ok, I used it, it is almost working, the only thing now is that it doesn't add a score if I click on the block, but the problem with the background is gone :)
danpost danpost

2017/6/16

#
SchoolStuff wrote...
Ok, I used it, it is almost working, the only thing now is that it doesn't add a score if I click on the block, but the problem with the background is gone :)
What does your Counter class currently look like? Another question -- is a Tile object (an actor created from the Tile class) what you consider to be a 'block'?
SchoolStuff SchoolStuff

2017/6/16

#
So if you click on the background nothing happens, which we wanted, but if you click on a block/tile it doesn't add a score. Yes, it is called a block in the game class.
public class Counter_w5 extends Actor
{
    int score = 0;
    int max = 20;
    
    /**
     * Act - do whatever the Counter_w5 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        setImage(new GreenfootImage("Score : " + score, 24, Color.BLACK, Color.WHITE));
        if (Greenfoot.mouseClicked(this)) 
        {
            ((Counter_w5)getWorld().getObjects(Counter_w5.class).get(0)).addScore();
        }
    }
danpost danpost

2017/6/16

#
Lines 13 through 16 do not belong in this act method. They belong in the act method of the Tile or Block class.
Super_Hippo Super_Hippo

2017/6/16

#
Look at this scenario. I only slightly modified what I told you to do on page 1.
SchoolStuff SchoolStuff

2017/6/16

#
Thank you all so much! It is working and I don't have any problems anymore!!
SchoolStuff SchoolStuff

2017/6/16

#
Never mind... by the second world I got greenfoot: terminal window I have no idea how to copy it.
There are more replies on the next page.
1
2
3