We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, Windows 7 with Processing 2.1.1 in JavaScript mode, here.
In Coursera's Intro to Python I made a simple memory game using images instead of numbers.
I'm trying to do something similar in Processing, but I'm stuck at mapping the randomized images to their numbers - in python you can just use a dictionary. In other words, if you click on a tile with the image of a number 1, I need to translate that into the integer number 1.
Any help would be appreciated.
Answers
Dictionaries in Java are Map structures. Processing officially supports HashMap as such implementation:
http://processing.org/reference/HashMap.html
A simpler implementation scheme w/o HashMap: %%-
Thanks. I've been trying to do that, but not correctly, obviously. For instance, does the key have to be a string? And if it does, how do I get the key from the value - .getKey() doesn't take arguments. Is it possible for the key to be the image and the value the integer, so I can just use .getValue on an image?
Updated my example above! L-)
Oops, we cross-posted. I'm going to try your suggestion right now.
Ha-ha success! I got a "ReferenceError: IntList is not defined" (?) with the IntList (even though It was defined), so I tried the "HashMap<PImage, Byte> imgs = new HashMap();" with this code in setup:
and this in my drawTiles() function:
and get the appropriate number every time I click a tile. Thanks a lot for your help. :)
Forgot that you wanted it on JS Mode, even though you haven't place this thread on that section! b-(
IntList is for Processing 2+. While JS Mode is eternally @ v1.4.1! :-L