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

2014/7/8

can't spot the error green foot says cannot find symbol-method counterScore(Int)

FlatbushNYC FlatbushNYC

2014/7/8

#
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) import java.util.List; /** * A rock in space * @author matthew andries * @author Poul Henriksen */ public class Asteroid extends SmoothMover { private Counter counter; /** Size of this asteroid */ private int size; /** When the stability reaches 0 the asteroid will explode */ private int stability; public Asteroid(Counter scoreCounter) { counter=scoreCounter; } public Asteroid() { this(50); } public Asteroid(int size) { super(new Vector(Greenfoot.getRandomNumber(360), 2)); setSize(size); } public Asteroid(int size, Vector speed) { super(speed); setSize(size); } public void act() { move(); } /** * Set the size of this asteroid. Note that stability is directly * related to size. Smaller asteroids are less stable. */ public void setSize(int size) { stability = size; this.size = size; GreenfootImage image = getImage(); image.scale(size, size); } /** * Return the current stability of this asteroid. (If it goes down to * zero, it breaks up.) */ public int getStability() { return stability; } /** * Hit this asteroid dealing the given amount of damage. */ public void hit(int damage) { stability = stability - damage; if(stability <= 0) breakUp (); } /** * Break up this asteroid. If we are still big enough, this will create two * smaller asteroids. If we are small already, just disappear. */ private void breakUp() { Space space = (Space) getWorld(); Greenfoot.playSound("Explosion.wav"); ((Space)getWorld()).countScore(); if(size <= 16) { getWorld().removeObject(this); space.counterScore(25); //adds 25 points for removing astreriod. } else { int r = getMovement().getDirection() + Greenfoot.getRandomNumber(45); double l = getMovement().getLength(); Vector speed1 = new Vector(r + 60, l * 1.2); Vector speed2 = new Vector(r - 60, l * 1.2); Asteroid a1 = new Asteroid(size/2, speed1); Asteroid a2 = new Asteroid(size/2, speed2); getWorld().addObject(a1, getX(), getY()); getWorld().addObject(a2, getX(), getY()); a1.move(); a2.move(); getWorld().removeObject(this); space.countScore(10); //adds 10 points for splitting an asteroid. } }
sengst sengst

2014/7/8

#
From asteroids 3 from the book, I don't have counterScore() in space. Make sure that counterScore() is in space. If it isn't, find where it is. Then you have to call it there.
danpost danpost

2014/7/8

#
First, what does this do (your third line in the 'breakUp' method):
((Space)getWorld()).countScore();
Then, it appears you are using two different method names in each part of the 'if' statement in that method:
// first call
space.counterScore(25); //adds 25 points for removing astreriod
// second call
space.countScore(10);  //adds 10 points for splitting an asteroid
I doubt that both are valid calls.
FlatbushNYC FlatbushNYC

2014/7/9

#
the problem was I didn't have counterScore() in my space that fix the problem thanks.
You need to login to post a reply.