Table of Contents
Level class should maintain a searchable collection of
Script objects. I expect you will use an
ArrayList to hold this collection of objects.
1.1. Maintaining a list of The first order of business is to make yourself an
Level to hold your scripts, and get them adding and removing properly.
1.2. CheckpointTo test what you've done so far, in the BlueJ code pad, make yourself a Level and a Script and store them in variables:
new Script(3, 4, "Creature", "Bob")
Leaving off the semicolon at the end of these lines makes the object reference they create appear with a red square that you can drag to the object bench to store it in a variable. I would suggest putting these two in variables named
Next, you want to add the script to the level. Again, you can do this in the code pad:
Now, with the inspector, check to make sure that the
ArrayList in your level now has one object in it. (Remember that you can inspect an object by right-clicking a variable and selecting "Inspect" from the menu. Then, you can inspect an instance variable by clicking on it and hitting the "Inspect" button.
Now, you can test out
removeScript() in the same way: tell teh level to remove the script, and verify that it disappeared from the list.
1.3. Searching for Now, we need to write all the methods that search for scripts.
1.4. Test CaseAt this point, you shoudl be able to run the "Test Searching" test case and have it work properly.
2. ScriptBecause a
Script needs to be able to move around and interact with the other
Scripts in its level, it needs to know what
Level it belongs to. You will write methods to get the level and move the script, and you will change the
Level to keep the
Script informed about what
Level it's in.
2.1. A script should know what level it's inYour script class should store information on what level it's in. It starts out in no level (null); when it is added or removed from a level, its level is updated by
2.2. CheckpointAt this point, you can try creating a level and a script as described in section 1.2 above. First, verify that the script's
getLevel() returns null when it is first created. Then, add the script to the level, and verify that this is
script.getLevel() == level
2.3. Scripts can be moved or removedThe final thing you need to do in this project is to make it possible to ask a script to
remove() itself from a level, or move to a new location, possibly in another level.
Be careful that you check whether
Level variables are
null before telling them to do something, to avoid a
2.4. Test CaseOnce you have finished the items above, you can run the "Test AddAndRemove" test case. In fact, it would be a good idea to rerun all the test cases and make sure that everything is still working, since sometimes a change you make in one place can mess up something else.