need help with hashmaps and classes
i'm making a game at the moment.......
i need help with a way to check all the hashmaps of enimies in a class called room......i need to check if they all == 0...when they all equal zero the game ends......
i know i can check the size of a hash map with size().....but i want to check if all the hashmaps within all the rooms == 0.
[351 byte] By [
mollemana] at [2007-11-26 20:31:13]

Do you have a collection of rooms? Does every room have a collection of enemies (in a map, I assume)?
Check each room. If a room has more than zero monsters, stop checking and keep the game going. Otherwise, quit.~
but that is bad design...is there not away i could just search trough the Room classes objects for all the monsters within the game....
and also im working with zuul so if anyone can tell me how i could finish the game....like my way is that when i have zero monster the game ends...but i dont know how to end the game...i have a method called quit....but that no help at the moment
> but that is bad design...is there not away i could
> just search trough the Room classes objects for all
> the monsters within the game....
To do that, you need a way to access all the Room objects that you've created, which you'll need to keep a collection of.
> and also im working with zuul so if anyone can tell
> me how i could finish the game....like my way is that
> when i have zero monster the game ends...but i dont
> know how to end the game...i have a method called
> quit....but that no help at the moment
That depends on what you want "Ending the game" to mean. What do you want to happen? Do you want the game to shut down? Do you want to store the player's score then shutdown? Do you want to go back to the title screen, give the player the option of starting over, and display the high scores? You have to decide what you want to do before you know how to do it.
> but that is bad design...
No it isn't.
boolean keepTheGameGoing() {
for (Room r : rooms) {
if (r.hasMonsters()) return true;
}
return false;
}
Simple and clean.
~
do i do this within my game class or the room classmy game class is the controller class and the hashmaps of rooms is made withinis within rooms......
and also how will this end the game
> do i do this within my game class or the room class
>
> my game class is the controller class and the
> hashmaps of rooms is made within
> is within rooms......
If the Game class is where the collection of Rooms exists, then do your operations on that collection there.
> do i do this within my game class or the room classIt would make sense to me that a Game should decide whether or not it should keep going. A room doesn't need to know about the game.~
> and also how will this end the gameEnd the game when the value returned by that method is false.~
> and also how will this end the game
See reply 5. The easiest way to end the game would be System.exit(0); but I doubt that's what you want to happen. You have to tell us exactly what you want to do before we can tell you how to do it. Just describe it in simple English, what you want the user to see, what options they have, etc.
i would like for the game just to say ...you have finished the game and then end
> i would like for the game just to say ...you have
> finished the game and then end
void run() {
do {
mainGameLoop();
} while (!gameShouldEnd());
display("You have finished the game.");
}
~
i mean to me.....im reall lost..is there anywhere i could upload the whole code for you to look at.......