So I have this problem with my Snake holding to its length. After eating an apple he gets bigger for a while, but then he falls back to deafult size. Can anyone please help me with that issue?
Heres my code:
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 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Chvost here. * * @author (your name) * @version (a version number or a date) */ public class Chvost extends Actor { int x; /** * Act - do whatever the Chvost wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { //vymazuje koniec chvostu a zároveň ho zväčšuje int pocitadlo = this .getWorld().getObjects(Had. class ).get( 0 ).getPocitadlo(); int score = this .getWorld().getObjects(Had. class ).get( 0 ).getScore(); if (pocitadlo> score) { getWorld().removeObject( this ); } } } |