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

2013/6/7

Compile error - help

1
2
geekykid2013 geekykid2013

2013/6/7

#
I have craeted a countdown timer for my world but when I compile I get an error message - no suitable constructor found - I'm unsure what this means. Can you help?
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class CountdownTimer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class CountdownTimer extends TimeCounter
{
    /**
     * Act - do whatever the CountdownTimer wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
     private int startTime;
     private int endTime;
     private int deltaTime;
     
     private long sysTimeMark = System.currentTimeMillis();
     private boolean enabled = true;
     
     
     /**
      * Constructor for objects of class Timer
      */
     
     public CountdownTimer(String prefix, int startTime, int endTime)//main constructor
     
     {
         super(prefix);
         this.startTime = startTime;
         this.endTime = endTime;
         deltaTime = ((endTime - startTime)<0)?-1:1;
         setValue(startTime);
     }
     
     public CountdownTimer(String prefix, int secondsToCountDown)// constructor to countdown in seconds with a prefix
     {
         this(prefix, secondsToCountDown,true);
     }
    
     public CountdownTimer(int secondsToCountDown)//constructor to countdown in seconds with no prefix
     {
         this("",secondsToCountDown,true);
     }
        /**
         * implements the call of actEachInterval()method at the end of each interval of time set in the field interval
         */
        
        public void act()
        {
            if (enabled)
            {
                if((System.currentTimeMillis()- sysTimeMark)> 1000)
                {
                    int newTime = getValue()+ deltaTime;
                    setValue(newTime);
                    if(newTime == endTime)
                    {
                        enabled = false;
                        actCountingEnd(); //call this method at the end of the counting
                    }
                    else
                    {
                        sysTimeMark = System.currentTimeMillis();
                    }
                }
        
        /**
         * An example of a method - replace this comment with your own
         * @param y a sample parameter for a method
         * @return the sum of x and y
         */
    }
}
        public void stop()
        {
            enabled = false;
        }
        
        public void start()
        {
            enabled = true;
            sysTimeMark = System.currentTimeMillis();
        }
        public void reset()
        {
            enabled = true;
            setValue(startTime);
            sysTimeMark = System.currentTimeMillis();
        }
        /**
         * An example of a method - replace this comment with your own
         * @param y a sample parameter for a method
         * @return the sum of x and y
         */
        public void actCountingEnd()
        {
            Greenfoot.setWorld(new GameOverTimeExpired());
            Greenfoot.stop();
        }
    }


danpost danpost

2013/6/7

#
The constructors I see are (1) public CountdownTimer(int), (2) public CoundownTimer(String, int), and (3) public CoundownTimer(String, int, int) However, I see calls to what should be public CountdownTimer(String, int, boolean) which I do not see anywhere.
geekykid2013 geekykid2013

2013/6/7

#
the one I am referring to is in line 39, which is where the error is indicated.
geekykid2013 geekykid2013

2013/6/7

#
ok so I've added the boolean countDown to the ContdownTimer constructor. On compile I receive the following error - cannot find symbol - class GameOverTimeExpired am I to declare this as a variable?
danpost danpost

2013/6/7

#
Not as a variable; at least, not the way you have it coded.. Line 99 refers to a World sub-class called 'GameOverTimeExpired' which you obviously do not have (I am not saying that it is what you want or do not want, either).
Winstrol Winstrol

2013/6/7

#
Yes you need to declare a variable you idiot , that's what Greenfoot is asking you to do
geekykid2013 geekykid2013

2013/6/7

#
sorry I had called that object GameOverScreen not GameOverTimeExpired. I suppose tat was the reason for the error message - no syntax errors on compilation. However I get the following error cannot find symbol - variable countdown timer but I think I hav created this object in my field in the Square world. Here is my code.
geekykid2013 geekykid2013

2013/6/7

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;

/**
 * 
 * The square world. The square world has Gold Eggs that need to be collected
 * 
 * @author  
 * @version 1.0
 */
public class SquareWorld extends World
{

    private Counter counter;            // fields for Counter class
    private HealthBar healthBar;        //Fields for HealthBar
    private Paddle paddle;              // Fields for Paddle
    private Robot robot;                // Fields Robot  
    
    public static CountdownTimer countdowmTimer = new CountdownTimer("TimeLeft[sec]:",60,true);
    private final int TIME_LIMIT = 60; //Max time in second allowed to play the game
    /**
     * Constructor for objects of class SquareWorld.
     * 
     */

    public SquareWorld() // This is the Second Constructor Method
    {
        super(700, 700, 1, true); // Create a new world with 700x700 cells with a cell size of 1x1 pixels.
        SquareWorld.countDownTimer.setValue(TIME_LIMIT);
        addObject(SquareWorld.countdownTimer, 500,462); // where the object is located
        
        setPaintOrder ( Robot.class, Smoke.class );

        counter = new Counter();
        healthBar = new HealthBar ("Robot Health", "", 100, 100);
        robot = new Robot(counter, healthBar);

        addObject(counter, 100, 678); 
        addObject(healthBar, 600, 678);
        addObject(robot, getWidth()/2, getHeight()-90);
        paddle = new Paddle(robot);
        addObject(paddle, getWidth()/2, getHeight()-55);
        
        prepare();
        
   }

    
    /**
     * An example of a method - replace this comment with your own
     *
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y
     */
    public void act()
    {
        checkNextLevel();
    }

    /**
     * Check whether we should go to the next level, and if yes, start the next level.
     */
    private void checkNextLevel()
    {
      if (getObjects(GoldEgg.class).isEmpty()) 
        {
            Greenfoot.setWorld(new CircleWorld(counter, healthBar));
        }
    
    }
    
    private void prepare()
    {
        GoldEgg goldegg = new GoldEgg();
        addObject(goldegg, 319, 404);
        goldegg.setLocation(309, 397);
        GoldEgg goldegg2 = new GoldEgg();
        addObject(goldegg2, 316, 190);
        goldegg2.setLocation(308, 182);
        GoldEgg goldegg3 = new GoldEgg();
        addObject(goldegg3, 465, 262);
        goldegg3.setLocation(458, 259);
        GoldEgg goldegg4 = new GoldEgg();
        addObject(goldegg4, 556, 95);
        goldegg4.setLocation(552, 95);
        GoldEgg goldegg5 = new GoldEgg();
        addObject(goldegg5, 145, 97);
        goldegg5.setLocation(143, 91);
        GoldEgg goldegg6 = new GoldEgg();
        addObject(goldegg6, 151, 266);
        goldegg6.setLocation(142, 258);
        GoldEgg goldegg7 = new GoldEgg();
        addObject(goldegg7, 557, 417);
        goldegg7.setLocation(555, 411);
        GoldEgg goldegg8 = new GoldEgg();
        addObject(goldegg8, 237, 335);
        goldegg8.setLocation(232, 332);
        GoldEgg goldegg9 = new GoldEgg();
        addObject(goldegg9, 353, 291);
        goldegg9.setLocation(346, 286);
        GoldEgg goldegg10 = new GoldEgg();
        addObject(goldegg10, 146, 493);
        goldegg10.setLocation(144, 486);
        GoldEgg goldegg11 = new GoldEgg();
        addObject(goldegg11, 389, 494);
        goldegg11.setLocation(386, 483);
        GoldEgg goldegg12 = new GoldEgg();
        addObject(goldegg12, 564, 268);
        goldegg12.setLocation(553, 259);
        GoldEgg goldegg13 = new GoldEgg();
        addObject(goldegg13, 394, 100);
        goldegg13.setLocation(388, 91);
        RedEgg redegg = new RedEgg();
        addObject(redegg, 234, 100);
        redegg.setLocation(227, 92);
        BlueEgg blueegg = new BlueEgg();
        addObject(blueegg, 314, 100);
        blueegg.setLocation(307, 93);
        RedEgg redegg2 = new RedEgg();
        addObject(redegg2, 472, 101);
        redegg2.setLocation(462, 88);
        YellowEgg yellowegg = new YellowEgg();
        addObject(yellowegg, 393, 187);
        yellowegg.setLocation(389, 181);
        YellowEgg yellowegg2 = new YellowEgg();
        addObject(yellowegg2, 464, 334);
        yellowegg2.setLocation(453, 332);
        RedEgg redegg3 = new RedEgg();
        addObject(redegg3, 239, 267);
        redegg3.setLocation(233, 260);
        BlueEgg blueegg2 = new BlueEgg();
        addObject(blueegg2, 152, 341);
        blueegg2.setLocation(143, 332);
        BlueEgg blueegg3 = new BlueEgg();
        addObject(blueegg3, 464, 195);
        blueegg3.setLocation(458, 187);
        YellowEgg yellowegg3 = new YellowEgg();
        addObject(yellowegg3, 560, 190);
        yellowegg3.setLocation(553, 185);
        RedEgg redegg4 = new RedEgg();
        addObject(redegg4, 149, 418);
        redegg4.setLocation(144, 412);
        BlueEgg blueegg4 = new BlueEgg();
        addObject(blueegg4, 149, 195);
        blueegg4.setLocation(141, 182);
        YellowEgg yellowegg4 = new YellowEgg();
        addObject(yellowegg4, 236, 191);
        yellowegg4.setLocation(230, 184);
        RedEgg redegg5 = new RedEgg();
        addObject(redegg5, 456, 403);
        redegg5.setLocation(454, 394);
        YellowEgg yellowegg5 = new YellowEgg();
        addObject(yellowegg5, 241, 401);
        yellowegg5.setLocation(231, 392);
        RedEgg redegg6 = new RedEgg();
        addObject(redegg6, 307, 496);
        redegg6.setLocation(304, 486);
        BlueEgg blueegg5 = new BlueEgg();
        addObject(blueegg5, 388, 402);
        blueegg5.setLocation(381, 395);
        BlueEgg blueegg6 = new BlueEgg();
        addObject(blueegg6, 559, 340);
        blueegg6.setLocation(554, 335);
        YellowEgg yellowegg6 = new YellowEgg();
        addObject(yellowegg6, 558, 493);
        yellowegg6.setLocation(553, 490);
        RedEgg redegg7 = new RedEgg();
        addObject(redegg7, 233, 491);
        redegg7.setLocation(227, 485);
        BlueEgg blueegg7 = new BlueEgg();
        addObject(blueegg7, 472, 492);
        blueegg7.setLocation(461, 481);
        removeObject(redegg4);
        RedEgg redegg8 = new RedEgg();
        addObject(redegg8, 148, 416);
        redegg8.setLocation(142, 408);

        goldegg5.setLocation(171, 92);
        redegg.setLocation(243, 92);
        blueegg.setLocation(310, 91);
        goldegg13.setLocation(379, 88);
        redegg2.setLocation(442, 92);
        redegg2.setLocation(446, 90);
        goldegg4.setLocation(520, 87);
        yellowegg3.setLocation(519, 168);
        blueegg3.setLocation(439, 169);
        blueegg3.setLocation(436, 169);
        yellowegg.setLocation(378, 170);
        goldegg2.setLocation(313, 168);
        yellowegg4.setLocation(247, 169);
        blueegg4.setLocation(171, 169);
        goldegg6.setLocation(169, 233);
        blueegg2.setLocation(168, 297);
        redegg8.setLocation(168, 362);
        goldegg10.setLocation(171, 426);
        redegg3.setLocation(245, 236);
        goldegg8.setLocation(248, 292);
        yellowegg5.setLocation(246, 348);
        redegg7.setLocation(237, 424);
        goldegg.setLocation(311, 348);
        goldegg9.setLocation(342, 254);
        goldegg3.setLocation(441, 233);
        yellowegg2.setLocation(440, 292);
        redegg5.setLocation(438, 350);
        blueegg5.setLocation(380, 349);
        goldegg12.setLocation(521, 228);
        blueegg6.setLocation(518, 291);
        goldegg7.setLocation(524, 359);
        yellowegg6.setLocation(518, 424);
        blueegg7.setLocation(443, 423);
        goldegg11.setLocation(378, 423);
        redegg6.setLocation(313, 426);
    }    
}
geekykid2013 geekykid2013

2013/6/7

#
whats the problem winstrol no need to get offensive!
danpost danpost

2013/6/7

#
You have shown the code where you create one; but, where is the error occurring? show the code there.
Winstrol Winstrol

2013/6/7

#
I'm not offensive to you mate , just saying what I think .
geekykid2013 geekykid2013

2013/6/7

#
oh so you think i'm an idiot them. you don't even know me and I 'm not interested in what your persoanl thougts are about me (as we're not buddies) I'm loooking for support with you my coding if you don't want to support then doon't post a reply simple. MATE!
Winstrol Winstrol

2013/6/7

#
Coding ? As I have seen through like 20 pages , you have done nothing in that code , you just annoy people here with your stupidity
geekykid2013 geekykid2013

2013/6/7

#
OK danpost: My new error is occuring in my SquareWorld() saying cannot find the variable CountdownTimer just to let you know I AM new to Java and am still learning how to code so I do apologise for some of my posts no matter how silly they may sound. I am still learning after all. Here is my code
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;

/**
 * 
 * The square world. The square world has Gold Eggs that need to be collected
 * 
 * @author  
 * @version 1.0
 */
public class SquareWorld extends World
{

    private Counter counter;            // fields for Counter class
    private HealthBar healthBar;        //Fields for HealthBar
    private Paddle paddle;              // Fields for Paddle
    private Robot robot;                // Fields Robot  
    
    public static CountdownTimer countdowmTimer = new CountdownTimer("TimeLeft[sec]:",60,true);
    private final int TIME_LIMIT = 60; //Max time in second allowed to play the game
    /**
     * Constructor for objects of class SquareWorld.
     * 
     */

    public SquareWorld() // This is the Second Constructor Method
    {
        super(700, 700, 1, true); // Create a new world with 700x700 cells with a cell size of 1x1 pixels.
        SquareWorld.countDownTimer.setValue(TIME_LIMIT);
        addObject(SquareWorld.countdownTimer, 500,462); // where the object is located
        
        setPaintOrder ( Robot.class, Smoke.class );

        counter = new Counter();
        healthBar = new HealthBar ("Robot Health", "", 100, 100);
        robot = new Robot(counter, healthBar);

        addObject(counter, 100, 678); 
        addObject(healthBar, 600, 678);
        addObject(robot, getWidth()/2, getHeight()-90);
        paddle = new Paddle(robot);
        addObject(paddle, getWidth()/2, getHeight()-55);
        
        prepare();
        
   }

    
    /**
     * An example of a method - replace this comment with your own
     *
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y
     */
    public void act()
    {
        checkNextLevel();
    }

    /**
     * Check whether we should go to the next level, and if yes, start the next level.
     */
    private void checkNextLevel()
    {
      if (getObjects(GoldEgg.class).isEmpty()) 
        {
            Greenfoot.setWorld(new CircleWorld(counter, healthBar));
        }
    
    }
geekykid2013 geekykid2013

2013/6/7

#
Hey! don't post any more offensive rubbish you don't know me so i'm not interetsed in what you have to say! becasue you are making this personal
There are more replies on the next page.
1
2