Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (292)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Question about collections  (Read 739 times)
0 Members and 1 Guest are viewing this topic.
Offline Fokusas

Senior Member


Medals: 3
Projects: 1



« Posted 2011-10-17 20:20:20 »

Hello,
I am creating simple (for now Cheesy) game (for learning purpose) and would like to ask you for advise.
I would like to ask you which collection type should i use.
I have LinkedList named Isradimai (Inventions) which contains all Isradimas (Invention) type objects. (For now it only contains 20 but later it could contain 100-400 objects). Also there is another LinkedList named Ismintis (Wisdom) which contains only discovered inventions (Isradimas objects). And there also is 2 more LinkedLists named galimiIsradimai (available inventions) and galimiDarbai(available jobs). GalimiIsradimai contains only new discoverable Isradimas object and are show to player to pick new invention. GalimiIsradimai are populated by cloning Isradimai and then removing all that are contained in Ismintis. Then i iterate over it and examine each object to see if it fits needed requirements. If it fails it is removed. Each time player "invents" new invention i clear and repopulate galimiIsradimai and player have a new list of possible inventions it also clears and repopulates galimiDarbai.  
GalimiDarbai contains all available actions for player. Sometimes inventing new inventions unlocks new actions for player to perform.That list is populated by iterating over Ismintis "and" Darbai (HashMap). If Isradimas object (contained in Ismintis) unlocks new action i look in HashMap and put received Darbas object in galimiDarbai.
Everything works very well. But one day i got idea that it could be better to replace all LinkedList to HashMap. So what do you think?
If you see some flaws in my design please post them too

Thanks in advance.
P.S. Sorry if i made some mistakes
Offline aazimon

Senior Member


Medals: 5



« Reply #1 - Posted 2011-10-17 20:35:41 »

I don't see any flaws. The main advantage of a HashMap to a LinkedList, is that you can retrieve the object faster when you have the key. I would make the Isradimai a HashMap for faster retrieval.
For the Discoverable list, I would create a HashMap, the key being the discovering event (a level or whatever), and the value to be a list of Isradimai keys.
Offline sproingie
« Reply #2 - Posted 2011-10-17 22:13:20 »

Your choice should really be down to HashMap or ArrayList.  Other Map implementations are for specialty purposes, and there is hardly any circumstance whatsoever where LinkedList is a better option than ArrayList; LinkedList  even fails for functional data structures, since it isn't recursively defined.

Edit: naturally, the choice between HashMap and ArrayList wouldn't be down to which performs better, but which operations you actually need.
Games published by our own members! Check 'em out!
Try the Free Demo of Revenge of the Titans
Offline Fokusas

Senior Member


Medals: 3
Projects: 1



« Reply #3 - Posted 2011-10-19 07:53:22 »

Thanks for your answers.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (66 views)
2013-05-17 21:29:12

alaslipknot (75 views)
2013-05-16 21:24:48

gouessej (106 views)
2013-05-16 00:53:38

gouessej (103 views)
2013-05-16 00:17:58

theagentd (114 views)
2013-05-15 15:01:13

theagentd (103 views)
2013-05-15 15:00:54

StreetDoggy (148 views)
2013-05-14 15:56:26

kutucuk (171 views)
2013-05-12 17:10:36

kutucuk (169 views)
2013-05-12 15:36:09

UnluckyDevil (178 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.079 seconds with 20 queries.