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

2015/5/8

leveling up

Regw03 Regw03

2015/5/8

#
Im having issues getting my game to level up and having both my score board to show each what level im on and having it go away after 60 time steps can anyone help
/**
 * A world for the boids.
 * 
 * @author Poul Henriksen 
 * @version 2.0
 */
public class Sky extends World
{
    /**
     * Counter Object Used to keep the score
     */
    private ScoreBoard;
    private Counter scoreCounter;
    private Timer gameTimer;
    private int numberOfBoids;
    private double percentageToWin;
    private int level = 1;
    /**
     * ADD CODE HERE
     * You need a variable to keep track of what level you are on.
     */
    
    
    /**
     * Constructor for objects of class Sky.
     * 
     */
    public Sky()
    {    
        /**
         * EDIT CODE
         * Sort your code, move the "stuff" that changes to your level up method
         * The "stuff" that stays the same can stay in the constructor
         */
        
        super(800, 600, 1);
        getBackground().setColor(new Color(220,220,100));
        getBackground().fill();
        // Create a new scoreCounter object and then add it to the world
        scoreCounter = new Counter("Score: ");
        addObject(scoreCounter, 55, 580);
        ScoreBoard = new ScoreBoard("levelUp: ");
        
        /**
          * ADD CODE HERE
          * Call your level up method
          */
         levelUp();
    }
    
    /**
     * This is your level up method
     */
    public void levelUp()
    {
        /**
         * ADD CODE HERE
         * If you are not on level one, then show a scoreboard that says you have leveled up
         * Leave it on the screen for 60 time steps
         */
        if(level!=1)
        {         
            addObject(new ScoreBoard(scoreCounter.getValue()), getWidth()/2, getHeight()/2);
            Greenfoot.delay(60);
            removeObtect(ScoreBoard);
        }
        
        /**
          * ADD CODE HERE
          * Once you scoreboard goes away, you need to clear the world of all objects
          */
         Greenfoot.delay(120);
        removeObject(gameTimer);
        removeObjects(getObjects(Boid.class));
        removeObjects(getObjects(Tree.class));
        removeObjects(getObjects(Hunter.class));
         /**
          * ADD CODE HERE
          * All of the "stuff" that changes goes here
          */
         
        /**
         * Create a new timer object and then add it to the world
         */
        gameTimer = new Timer("Time Remaining: ");
        addObject(gameTimer, 100, 560);
         /**
         * Set the number of boids and the percentage to win the game
         */
        numberOfBoids = 50;
        percentageToWin = 0.25;
        populateTrees(100);
        populateBoids(numberOfBoids);
        /**
         * Create a shooter
         */
        Hunter myHunter = new Hunter();
        addObject(myHunter, getWidth()/2 ,getHeight()/2);
        /**
         * Make a predator and add it to the world
         */
        Predator myPredator = new Predator();
        addObject(myPredator, 0 , 0); 
         
         /**
          * ADD CODE HERE
          * Now that you have done everything, don't forget to add 1 to your level
          */
        
        level++;
    }
Super_Hippo Super_Hippo

2015/5/8

#
Don't use delays. You can add the objects and tell them to disappear after a certain time. For example for your ScoreBoard:
private int time = 60;

public void act()
{
    time--;
    if (time==0) getWorld().removeObject(this);
}
Regw03 Regw03

2015/5/8

#
ok I fixed that part but now how do I get my Score board to show what level i am on and how do i get it to where after the first level is passed that takes more than on kill of a boid to level up
danpost danpost

2015/5/8

#
There are no issues with using delays here. The level display is temporary and no other actions are to occur during the short time it is displayed. The ScoreBoard object created at line 63 is not assigned to 'ScoreBoard' (which you appear to be removing from the world at line 65 with the misspelt method name 'removeObtect'); the 'ScoreBoard' field is not declared; and, the apparent field that is to hold a ScoreBoard object is not identified. Those are the issues.
You need to login to post a reply.