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

2014/7/18

Old languege

SUPERc00lBudder SUPERc00lBudder

2014/7/18

#
I can no longer use .isEmpty, why?
lordhershey lordhershey

2014/7/18

#
I think you might need to put it like listObj.isEmpty() , without the "()" it does not see listObj.isEmpty as a function call.
SUPERc00lBudder SUPERc00lBudder

2014/7/18

#
I am trying to make a space invaders game and this part is need, is there an alternative?
SUPERc00lBudder SUPERc00lBudder

2014/7/18

#
one sec ill post the page
SUPERc00lBudder SUPERc00lBudder

2014/7/18

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.List; /** * Write a description of class Space here. * * @author (your name) * @version (a version number or a date) */ public class Space extends World { private static final int WIDTH = 640; private static final int HEIGHT = 480; private static final int ROW_LENGTH = 500; private static final int FIRING = 30; private int actcounter = 0; /** * Constructor for objects of class Space. * */ public Space() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(WIDTH, HEIGHT, 1); prepare(); } /** * Prepare the world for the start of the program. That is: create the initial * objects and add them to the world. */ private void prepare() { Shooter shooter = new Shooter(); addObject(shooter, 320, 420); for(int i=0; i<11; i++) { addObject(new Spaceinvader3(), (WIDTH-ROW_LENGTH)/2+i*ROW_LENGTH/10, 50); } } public void act() { actcounter++; if (actcounter > FIRING) { List invaders = getObjects(Spaceinvader3.class); if (!Spaceinvader3.isEmpty()) { int number_of_invaders = Spaceinvader3.size(); int i = Greentfoot.getRandomNumber(number_of_invaders); Spaceinvader3 ramdominvader = (Spaceinvader3)invader.get(1); } actcounter = 0; } } }
lordhershey lordhershey

2014/7/18

#
change this: if (!Spaceinvader3.isEmpty()) { to this: if (!invaders.isEmpty()) { Your list is called invaders.
SUPERc00lBudder SUPERc00lBudder

2014/7/18

#
uhh
SUPERc00lBudder SUPERc00lBudder

2014/7/18

#
fail
SUPERc00lBudder SUPERc00lBudder

2014/7/18

#
thanks for the help by the way
lordhershey lordhershey

2014/7/18

#
No problem :D
You need to login to post a reply.