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

Comments for Castle Defense

Return to Castle Defense

A new version of this scenario was uploaded on Fri Apr 24 19:29:03 UTC 2009
A new version of this scenario was uploaded on Fri Apr 24 19:29:40 UTC 2009
MuZiKMuZiK

2009/4/24

Sorry about loading 3 times. Had to get the image right lol...
mjrb4mjrb4

2009/4/24

711 - and ouch my finger hurts!!
MuZiKMuZiK

2009/4/24

Does anyone know how to remove a drive partition? I cant download greenfoot on my home pc because the c drive is "full".
mjrb4mjrb4

2009/4/25

Windows XP? And do you want to remove it as in get rid of all the data on it? If so... Start => Run => compmgmt.msc, click on disk management, right click on the partition you want to delete and select delete partition. It probably goes without saying, but remember you will lose all the data on that partition when you delete it!!
MuZiKMuZiK

2009/4/26

Yeah i know how to do that, but what I was wondering was if there was a way to combine them through windows XP. Turns out there's not and the only way to do so is to reformat...So, that's what I've been doing for the past 3 or so hours. BTW, they built that feature into Vista, yet they won't update XP to include it... 832 :P
A new version of this scenario was uploaded on Thu Apr 30 01:09:45 UTC 2009
BlackholeGFBlackholeGF

2009/4/30

w00t 1145
MuZiKMuZiK

2009/4/30

I need help with my bomb class. It probably seems stupid, but I've been trying at it for a while now, and cant get the result i want. I know it's probably a simple problem, and when I find it I'm gonna feel like a dumbass...
mjrb4mjrb4

2009/4/30

The problem is here: public void kill() { enemy = new Enemy(); getWorld().getObjects(Enemy.class); getWorld().removeObject(enemy); } In this method you're doing 3 things: 1) Creating a new enemy 2) Getting all the enemy objects in the world but not storing them anywhere 3) Removing the new enemy you created (but never added to the world.) What you actually need to do is store the result of the getObjects() method in a variable, and then loop through that list and tell the world to remove each item in it :-)
MuZiKMuZiK

2009/4/30

I actually tried this, but received an error. Maybe I just made a small mistake, I'll try it again. Can't do it at school because I'm supposed to be doing a databases course.............................KILL ME!
MuZiKMuZiK

2009/4/30

i keep getting an unexpected type error.
mjrb4mjrb4

2009/4/30

When you get your list, try casting it like the following: List<Enemy> enemies = (List<Enemy>)getWorld().getObjects(Enemy.class); ...and you'll also need to import java.util.List. If that doesn't help then just post the code you get the error for and I'll tell you what's wrong with it!
MuZiKMuZiK

2009/5/1

Well, I remember from my java basics course that there was an iterator class or interface, but I can't remember how to use it :(
mjrb4mjrb4

2009/5/1

There is, but you don't need it for this - just use a foreach loop: for(Enemy enemy : enemies) { //Do what you like with enemy } That will loop through each enemy in enemies so you can do what you like with each of them. It's basically an easier way of writing: for(in i=0 ; i<enemies.size() ; i++) { Enemy enemy = enemies.get(i); } You CAN use iterators if you like, but they're more commonly used for looping through things like sets and maps (collections that have no defined order). Foreach loops are a nice quick easy way to loop through an entire collection if you don't need to modify its contents (and most of the time, you generally don't.) When you do need to modify an element then you'll have to either use a for loop or an iterator.
MuZiKMuZiK

2009/5/1

Wow, to be honest, I had totally forgotten about the foreach loop...
MuZiKMuZiK

2009/5/1

java.lang.NullPointerException at Bomb.kill(Bomb.java:29) at Bomb.explode(Bomb.java:22) at Bomb.act(Bomb.java:16) at greenfoot.core.Simulation.runOneLoop(Simulation.java:288) at greenfoot.core.Simulation.run(Simulation.java:158) I'm getting that run-time error. for this code: public void kill() { List<Enemy> enemies = (List<Enemy>)getWorld().getObjects(Enemy.class); for (Enemy enemy : enemies) { enemies.removeAll(enemies); getWorld().modifyScore(enemies.size()*2); } }
MuZiKMuZiK

2009/5/1

The error just somehow changed... java.util.ConcurrentModificationException at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372) at java.util.AbstractList$Itr.next(AbstractList.java:343) at Bomb.kill(Bomb.java:28) at Bomb.explode(Bomb.java:21) at Bomb.act(Bomb.java:15) at greenfoot.core.Simulation.runOneLoop(Simulation.java:288) at greenfoot.core.Simulation.run(Simulation.java:158)
MuZiKMuZiK

2009/5/1

The javaDoc says it's thrown when a collection that is being iterated through is modified.
mjrb4mjrb4

2009/5/1

That's because you're trying to modify the contents of the list: enemies.removeAll(enemies); There you're trying to empty the list you've just formed, which isn't what you want to do (and why you're getting said exception). Instead you want to remove each object from the world: getWorld().removeObject(enemy); You need to be careful about what you're actually removing the object from!
MuZiKMuZiK

2009/5/2

HA! I don't know where my common sense was today... Why would I try to remove from the list instead of the WORLD. Sometimes I surprise myself with stupidity.
A new version of this scenario was uploaded on Sat May 02 02:47:33 UTC 2009
MuZiKMuZiK

2009/5/2

2539, but my reset() method isn't working properly. I'll take another look at it.
mjrb4mjrb4

2009/5/2

What's wrong with the reset? It seems to work ok for me at a glance.
MuZiKMuZiK

2009/5/2

Well, since the spawning of the enemies is relative to the round number, I was wanting it to reset the round number every time a bomb is used, so the player isn't immediately overwhelmed again. btw, i finally finished reformatting, so i can use my good pc...
mjrb4mjrb4

2009/5/2

I'll give you a clue. Comment out your reset method in Bomb and try compiling ;)
MuZiKMuZiK

2009/5/2

Now my greenfoot wont load the scenario when i compile it. Do i need something besides the JDK?
mjrb4mjrb4

2009/5/2

That's odd - nope you should just need the JDK. Try deleting all the class files in the folder and restart to force a recompile.
MuZiKMuZiK

2009/5/3

it says this where the game should come up "Your browser is ignoring the <APPLET> tag."
mjrb4mjrb4

2009/5/3

It seems that your JDK install might be corrupted or didn't install properly - you could try uninstalling / reinstalling?
MuZiKMuZiK

2009/5/4

Yeah, I tried that commenting that out and the same thing happens. I called it directly from the Enemy class, but it didn't change anything. It's supposed make it so only one enemy spawns after the bomb is used.
A new version of this scenario was uploaded on Mon May 04 18:29:01 UTC 2009
MuZiKMuZiK

2009/5/4

Updated the source.
A new version of this scenario was uploaded on Tue May 05 20:08:12 UTC 2009
MuZiKMuZiK

2009/5/6

This is really aggravating. It technically SHOULD work, but it doesn't...
mjrb4mjrb4

2009/5/6

Nah it shouldn't, at least not how it's written at the moment ;) Have a look at your kill method - you might be resetting it, but you're also spawning as many enemies as you're removing. Only one line that's in the loop should actually be in a loop, take the other two outside of it and it works.
A new version of this scenario was uploaded on Wed May 06 19:06:07 UTC 2009
MuZiKMuZiK

2009/5/7

I hate those kinds of problems. Always hard to find, thanks.
MuZiKMuZiK

2009/5/9

I just found out why the games weren't loading on this site. I didn't have JAVA itself installed...
mjrb4mjrb4

2009/5/9

Oops. You'll definitely need that...!
A new version of this scenario was uploaded on Thu Jan 21 18:47:43 UTC 2010
A new version of this scenario was uploaded on Thu Jan 21 18:49:51 UTC 2010
A new version of this scenario was uploaded on Thu Jan 21 18:55:38 UTC 2010
MuZiKMuZiK

2010/1/21

Been away for a while doing html, css, javascript, xml, jsp and mysql. Now, I'm starting .NET...