The problem relates to
world.placeFood(1);
and the error is = cannot find symbol - method placeberry(int)
i'm trying to make it so that when the snake eats a berry it removes that berry and adds another one to the world.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class SnakeWorld here. * * @author (your name) * @version (a version number or a date) */ public class SnakeWorld extends World { private berry berry1; /** * Constructor for objects of class SnakeWorld. * */ public SnakeWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 400, 1); setBackground("Black.jpg"); prepare(); placeberry(1); } /** * Prepare the world for the start of the program. That is: create the initial * objects and add them to the world. */ private void prepare() { Snake snake = new Snake(); addObject(snake, 183, 205); } { Greenfoot.playSound("skrillex.mp3"); } public void placeberry(int amountOfFood) { for (int i = 0; i < amountOfFood; i++) { addObject(new berry(), Greenfoot.getRandomNumber(499)+1, Greenfoot.getRandomNumber(419)+1); } } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Snake here. * * @author (your name) * @version (a version number or a date) */ public class Snake extends Actor { /** * Act - do whatever the Snake wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { moveAndTurn(); eat(); if (getX() <=5 || getX() >= getWorld().getWidth() -5) { getWorld().removeObject(this); return; } if (getY() <=5 || getY() >= getWorld().getHeight() -5) { getWorld().removeObject(this); return; } } public void moveAndTurn() { move(2); if (Greenfoot.isKeyDown("left")) { setRotation(180); } if (Greenfoot.isKeyDown("right")) { setRotation(0); } if (Greenfoot.isKeyDown("down")) { setRotation(90); } if (Greenfoot.isKeyDown("up")) { setRotation(270); } } public void eat() { Actor berry; berry = getOneObjectAtOffset(0, 0, berry.class); if (berry != null) { World world; world = getWorld(); world.removeObject(berry); world.placeFood(1); } } }