When I place the "return true" statement in this position,
It gives me an unreachable statement error, however when i place it in this postion,
It never returns true. Any help is appreciated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | public boolean eat() { Food f1 = new Food(); Actor f; f = getOneObjectAtOffset( 0 , 0 , Food. class ); if (f != null ) { return true ; World world; world = getWorld(); world.removeObject(f); getWorld().addObject(f1, ( int )(Math.random()* 36 + 1 ), ( int )(Math.random()* 25 + 1 )); foodEaten += 1 ; } else return false ; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | public boolean eat() { Food f1 = new Food(); Actor f; f = getOneObjectAtOffset( 0 , 0 , Food. class ); if (f != null ) { World world; world = getWorld(); world.removeObject(f); getWorld().addObject(f1, ( int )(Math.random()* 36 + 1 ), ( int )(Math.random()* 25 + 1 )); foodEaten += 1 ; return true ; } else return false ; } |