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

2014/11/21

Character Selection Game

1
2
3
4
joanne_wm joanne_wm

2015/1/5

#
let me try again. i think it should work now
joanne_wm joanne_wm

2015/1/5

#
alright, scratch that. I now got all the codes to work properly and it works nicely. Now, we need to go back to the problem to where I can't level up. In the public void act of the SpaceWorld, I inserted this:
    {if (Greenfoot.isKeyDown("A")) 
   Greenfoot.setWorld(new LB_HeavenWorld()); 
}
So after I've eaten all the supercandies and the pop up message comes out, instead of continue playing, the game was stopped, and I just can't go to the next world.
danpost danpost

2015/1/5

#
What is the message? and what is the code it points to?
joanne_wm joanne_wm

2015/1/6

#
there was no message that came out whatsoever, and there was no code that it pointed to. The game just stopped itself.
danpost danpost

2015/1/6

#
What code do you have for the CountdownClock class?
joanne_wm joanne_wm

2015/1/6

#
here it is
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
import java.util.Calendar;

/**
 *  Displays a digital clock in HH:MM:SS format.
 */
public class CountdownClock extends Actor
{
    private int width  = 60;        // Dimensions of the display
    private int height = 20;
    private int prevSecond = -1;
    private int counter = 0;

    /**
     *  The constructor creates the actor's image.
     */
    public CountdownClock(int startSeconds) 
    {
        counter = startSeconds;
        GreenfootImage image = new GreenfootImage(width, height);
        image.setColor(Color.WHITE);
        image.fill();
        image.setColor(Color.BLACK);
        image.drawRect(0, 0 ,width - 1, height - 1);
        setImage(image);
        updateDisplay(counter + ".0");
    }

    public CountdownClock()
    {
        this(15);
    }

    /**
     *  The clock is tick'd on every act() call, but the display changes
     *  only when the second's increments.
     */
    public void act()
    {
       if (counter > 0)
       {
           updateDisplay(tick());
       }
    }

    /**
     *  Increment the display string for the clock.
     */
    public String tick()
    {
        // Compose new display string
        Calendar calendar = Calendar.getInstance();
        int    sec  = calendar.get(Calendar.SECOND);
        int    tsec = calendar.get(Calendar.MILLISECOND) / 100;

        if (counter == 0)
        {
            return("0.0");
        }
        if (sec != prevSecond )
        {
            prevSecond = sec;
            counter = counter - 1;
        }
        return(counter + "." + tsec);
    }

    /**
     *  Update the clock with the new time string.
     */
    public void updateDisplay(String newTime)
    {
        // x and y relative to the image. baseline of leftmost character.
        int x = 5;
        int y = 15;
        // Repaint the clock display
        GreenfootImage image = getImage();
        image.setColor(Color.WHITE);
        image.fillRect(1, 1, width-2, height-2);    // "erase" the display
        image.setColor(Color.BLACK);
        image.drawString(newTime, x, y);
        setImage(image);
    }

    /**
     *  Returns the current value of the clock.
     */
    public int getCounter()
    {
        return counter;
    }
}











danpost danpost

2015/1/6

#
It is definitely not in the CountdownClock class. I reviewed previous code posts and found that in the 'L4_SpaceWorld' class, in the 'gameOver(String)' method, you are using a 'Greenfoot.stop' call which will stop the scenario -- remove that line to proceed to whatever problem lies ahead.
joanne_wm joanne_wm

2015/1/6

#
THank you very very very much! NOw my game is complete!!!!
You need to login to post a reply.
1
2
3
4