I'd like to build an hardware interface device that sits between
two game controllers and maps controller buttons based on which
game is to be played. So the device will run some java app where
I've statically coded all the mappings. There's one mapping for
each controller (EnumTGC and EnumPGC) and multiple
controller:controller mappings. Also, multiple games can use the
same controller:controller mapping but one game can only use one
controller:controller mapping. So....
so far so good. but here I run into trouble
when combined with the executable
Does that make sense? Overall idea here is the user will select which game is to be played
(hardcoded here to shrink the problem) and the associated controller:controller mapping gets used.
As always, all help/suggestions/advice/constructive criticism are all welcome,
Maybe the following example is useful for you. I have replaced EnumTGC and EnumPGC with interfaces with the more descriptive names Command and Button.
The point is that eventually all your games should care about is some mapping from Buttons to Commands. We can use the following type for this:
If your game detects that a certain button is pushed, it can easily look up the associated command like so:
Here's how it would look:
Joined: Oct 02, 2008
Genius! I thought the EnumMap might be of help but have not worked with it before. I'll give it a try.
Thanks for your help!!
Stephan van Hulst
Joined: Sep 20, 2010
Note that you're programming to an interface, so it doesn't really matter whether you use a HashMap or an EnumMap. EnumMaps are just slightly more efficient than HashMaps are.