views:

32

answers:

1

Hi there, I fixed my previous problem. But now when on my tile map... if I try to go 9 tiles to the RIGHT, and on trying to get to the 9th tile.... I will get this error:

Exception in thread "AWT-EventQueue-1" java.lang.ArrayIndexOutOfBoundsException: 8
    at tileGen.blocked(tileGen.java:125)
    at tileGen.keyPressed(tileGen.java:58)
    at java.awt.Component.processKeyEvent(Component.java:6221)
    at java.awt.Component.processEvent(Component.java:6040)
    at java.awt.Container.processEvent(Container.java:2041)
    at java.awt.Component.dispatchEventImpl(Component.java:4630)
    at java.awt.Container.dispatchEventImpl(Container.java:2099)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1850)
    at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:712)
    at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:990)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:855)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:676)
    at java.awt.Component.dispatchEventImpl(Component.java:4502)
    at java.awt.Container.dispatchEventImpl(Container.java:2099)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Here is code: http://www.so.pastebin.com/hYkpQf13

I have tried many solutions, all of which have failed. Maybe someone here can I help me?

Thank you.

+1  A: 

I believe the problem is you mix up the coordinates. You use X as the left-right coordinate and Y as the up-down, when it should be the other way around (or you should mirror your board).

Upon going right, you increment X, and on your board, that means effectively you move one row down. Since the board has 8 rows, the 9th move takes you out of bounds.

Péter Török
OH YES!!! I see the problem! :) Thanks. It's suppose to be ty, tx... :D
Dan
Another thing... do you think there is a better way to block tiles? That way It can just be one method and simple?
Dan
@Dan, I don't have any wise insights on this right now. I would leave `blocked` as it is, to me it makes the code more readable. OTOH the test expression would look simpler and more readable to me in this form: `if (!blocked(x1,y1))` - but this is a minor issue.
Péter Török