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

2013/7/9

I keep getting the error cannot find method for gameOver(); how do i fix this properly?? im very confused

qsapp.3 qsapp.3

2013/7/9

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

/**
 * Main player. Gets controlled by user.
 * 
 * @author (Quinn Sapp) 
 * @version (5 July 2013)
 */
public class MainPlayer extends Animal
{
    private Counter counter;
    public MainPlayer(Counter pointCounter)
    {
        counter = pointCounter;
    }
    public void act()
    {
        checkKeyPress();
        lookForPoint();
        checkNextLevel();
        checkNextLevel2();
        checkNextLevel3();
        checkNextLevel4();
        checkNextLevel5();
    }// end act
    public void checkKeyPress(){
        if (Greenfoot.isKeyDown("left")){
            turn(-4);
        }
        if (Greenfoot.isKeyDown("right")){
            turn(4);
        }
        if (Greenfoot.isKeyDown("up")){
            turn(4);
        }
        if (Greenfoot.isKeyDown("down")){
            turn(4);
        }
        if (Greenfoot.isKeyDown("space")){
            move(2);
        }
    }//end checkKeys
    public void lookForPoint(){
       if (canSee(Point.class)){
        eat(Point.class);
        counter.add(2);
        Greenfoot.playSound("au.wav");
       }
       
       if(counter.getValue() >= 80){
           gameOver();
        }
    }  //end lookForPoint
    public void checkNextLevel(){   
       if (getOneIntersectingObject(Finish.class) != null) {  
         //reached the end object;
         //start the new level;  
        Greenfoot.setWorld(new Level2());
   }  
  }//end MainPlayer Class
      public void checkNextLevel2(){   
       if (getOneIntersectingObject(Finish2.class) != null) {  
         //reached the end object;
         //start the new level;  
        Greenfoot.setWorld(new Level3());
   }  
  }
      public void checkNextLevel3(){   
       if (getOneIntersectingObject(Finish3.class) != null) {  
         //reached the end object;
         //start the new level;  
        Greenfoot.setWorld(new Level4());
   }  
  }
      public void checkNextLevel4(){   
       if (getOneIntersectingObject(Finish4.class) != null) {  
         //reached the end object;
         //start the new level;  
        Greenfoot.setWorld(new Level5());
   }  
  }
        public void checkNextLevel5(){   
       if (getOneIntersectingObject(Finish5.class) != null) {  
         //reached the end object;
         //start the new level;  
        Greenfoot.setWorld(new WINNER());
   }  
  }
}
danpost danpost

2013/7/9

#
Just add one.
public void gameOver()
{
    // whatever you want to do before stopping the scenario
    Greenfoot.stop();
}
Gevater_Tod4711 Gevater_Tod4711

2013/7/9

#
The problem is that you want to execute the method gameOver() in line 51 but ther is no such method in your MainPlayer class. To fix this problem you have to declare the method or copy it into the MainPlayer class if you already got one.
qsapp.3 qsapp.3

2013/7/9

#
// now it says illegal start of expression
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Main player. Gets controlled by user.
 * 
 * @author (Quinn Sapp) 
 * @version (5 July 2013)
 */
public class MainPlayer extends Animal
{
    private Counter counter;
    public MainPlayer(Counter pointCounter)
    {
        counter = pointCounter;
    }
    public void act()
    {
        checkKeyPress();
        lookForPoint();
        gameOver();
        checkNextLevel();
        checkNextLevel2();
        checkNextLevel3();
        checkNextLevel4();
        checkNextLevel5();
    }// end act
    public void checkKeyPress(){
        if (Greenfoot.isKeyDown("left")){
            turn(-4);
        }
        if (Greenfoot.isKeyDown("right")){
            turn(4);
        }
        if (Greenfoot.isKeyDown("up")){
            turn(4);
        }
        if (Greenfoot.isKeyDown("down")){
            turn(4);
        }
        if (Greenfoot.isKeyDown("space")){
            move(2);
        }
    }//end checkKeys
    public void lookForPoint(){
       if (canSee(Point.class)){
        eat(Point.class);
        counter.add(2);
        Greenfoot.playSound("au.wav");
       }
    public void gameOver(){
       if(counter.getValue() >= 80){
           gameOver();
           Greenfoot.stop();
        }
    } //end lookForPoint
  }
    public void checkNextLevel(){   
       if (getOneIntersectingObject(Finish.class) != null) {  
         //reached the end object;
         //start the new level;  
        Greenfoot.setWorld(new Level2());
   }  
  }//end MainPlayer Class
      public void checkNextLevel2(){   
       if (getOneIntersectingObject(Finish2.class) != null) {  
         //reached the end object;
         //start the new level;  
        Greenfoot.setWorld(new Level3());
   }  
  }
      public void checkNextLevel3(){   
       if (getOneIntersectingObject(Finish3.class) != null) {  
         //reached the end object;
         //start the new level;  
        Greenfoot.setWorld(new Level4());
   }  
  }
      public void checkNextLevel4(){   
       if (getOneIntersectingObject(Finish4.class) != null) {  
         //reached the end object;
         //start the new level;  
        Greenfoot.setWorld(new Level5());
   }  
  }
        public void checkNextLevel5(){   
       if (getOneIntersectingObject(Finish5.class) != null) {  
         //reached the end object;
         //start the new level;  
        Greenfoot.setWorld(new WINNER());
   }  
  }
}
danpost danpost

2013/7/9

#
You placed the gameOver method within another method. Move a closing bracket at the end of the method to before it.
qsapp.3 qsapp.3

2013/7/10

#
Thank you so much!
You need to login to post a reply.