i curious easiest way move around 2d array in java? created 2d array game board , use keep track of positions of game pieces. if have 16x16 2d array how make players can move around board x number of spaces.
i know pieces move from:
[0][0] -> [0][16] - top
then
[0][16] -> [16][16] - right side
then
[16][16] -> [16][0] - bottom
then home space being [0][0].
[16][0] -> [0][0] - left side
any or suggestions appreciated!
edit: wish accept multiple correct answers.... sigh ;(
based on comment, implement restriction on movement following pseudocode. i'm not 100% sure if want, it's helpful
if (user tries move right) { if (posx < 15 && posy == 0) //move right else //don't } if (user tries move left) { if (posx > 0 && posy == 15) //move left else //don't }
and on. similar you're looking for? restrictions on array traversal? i'm assuming board allows movement on boundaries of array based on say, following o positions legal, , x illegal:
ooooooooooooooo oxxxxxxxxxxxxxo oxxxxxxxxxxxxxo ... oxxxxxxxxxxxxxo ooooooooooooooo
Comments
Post a Comment