I'm trying to put in a counter using this video
I get this error:
constructor User_fish in class User_fish cannot be applied to given types;
required:Label
found: no arguments
reason: actual and formal argument lists differ in length
the rest of my code involving this:
1 2 3 4 5 6 7 | public void prepare() { User_fish user_fish = new User_fish(); addObject(user_fish, 770 , 405 ); Label label = new Label( "Score: 0" ); addObject (label, 830 , 40 ); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | public class Label extends Actor { public Label(String text) { GreenfootImage img = new GreenfootImage (text.length()* 20 , 50 ); img.drawString(text, 2 , 20 ); setImage(img); } public void setText(String text) { GreenfootImage img = getImage(); img.clear(); img.drawString (text, 2 , 20 ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | public class User_fish extends Actor { private int movementspeed = 6 ; private GreenfootImage[] images = { new GreenfootImage( "User_fish-left.png" ), new GreenfootImage( "User_fish-right.png" )}; private int size = 50 ; private Label myLabel; private int count = 1 ; public User_fish(Label label) { updateImages(); setImage(images[ 1 ]); myLabel = label; } public void act() { checkKeys(); eat(); } public void eat() { AI f = (AI) getOneIntersectingObject(AI. class ); if (f != null ) { if (size > f.size) { getWorld().removeObject(f); size++; updateImages(); count++; myLabel.setText( "Score: " + count); } else if (size < f.size) //idk how you want to handle same size { getWorld().removeObject( this ); Greenfoot.setWorld( new Gameover_world()); } } } |