int[][] array not working - java applet
OK so the array is not working.
My code: http://www.javadan.pastebin.com/C9QiVySe
I am trying to check if blocked(lastX,lastY)
of the following tile he is on. I count 开发者_C百科the tile the player is standing on by adding or minusing X and Y when they go up, down, left, or right. So if the player starts at 0,0, they press down twice and right once. they will be at (2,1). Then the code checks to see if board[2][1] is blocked (which is not). The code specifically states that board[1][1] is blocked but the console says its true for random tiles... :(
Help? Thanks.
Well, (1,1) is not blocked (BLOCKED == 1, and board[1][1] == 2). On the other hand, (2,1) is blocked. Speaking of which, you might be a bit confused by indexing: given your layout of the blocked array, you should index it using [lastY][lastX], not the other way around.
Also, I don't see any call to blocked() in keyPressed, so you're not actually checking for blockage before moving the player.
What exactly are you asking? You mentioned moving to (2, 1), but (2, 1) is blocked in the array you load. You do realize that BLOCKED == 1
, right?
You also never check if the player is blocked at all in keyPressed
.
精彩评论