围绕二维数组移动的最佳方法(棋盘游戏) [英] Best way to move around a 2d Array (Board Game)

查看:365
本文介绍了围绕二维数组移动的最佳方法(棋盘游戏)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇什么是围绕Java中的二维数组移动最简单的方法?我创建了一个游戏板二维数组并用它来跟踪棋子的位置。所以,如果我有一个16×16的二维数组,我怎么让让玩家们可以围绕空间董事会X数字移动。

I am curious about what would be the easiest way to move around a 2d array in Java? I created a 2d array for a game board and use that to keep track of the positions of game pieces. So if I have a 16x16 2d array how do I make it so players can move around the board X number of spaces.

我知道的作品将移动从:

I know the pieces would move from:

[0] [0] - > [0] [16] - 顶部

[0][0] -> [0][16] - TOP

然后

[0] [16] - > [16] [16] - 右侧

[0][16] -> [16][16] - RIGHT SIDE

然后

[16] [16] - > [16] [0] - 底

[16][16] -> [16][0] - BOTTOM

然后终于回到了家中的空间为[0] [0]

then finally back to the home space being [0][0].

[16] [0] - > [0] [0] - 左边

[16][0] -> [0][0] - LEFT SIDE

任何帮助或建议将不胜AP preciated!

Any help or suggestions would be greatly appreciated!

编辑:我希望我能接受多个正确答案....叹息;(

I wish I could accept multiple correct answers.... sigh ;(

推荐答案

根据您的意见,您可以实现您与下面的伪code活动受限。我不是100%肯定,如果这是你想要的,但希望它有点帮助的。

Based on your comment, you could implement your restriction on movement with the following pseudocode. I'm not 100% sure if this is what you want, but hopefully it's somewhat helpful

if (user tries to move right) {
    if (posX < 15 && posY == 0)
         //move right
    else
         //don't
}

if (user tries to move left) {
    if (posX > 0 && posY == 15)
         //move left
    else
         //don't
}

等。这类似于你在找什么?在数组遍历的限制?我假设你的板子只允许基于你说什么了数组的边界运动,所以下面Ø位置是合法的,而X是非法的:

And so on. Is this similar to what you're looking for? Restrictions on array traversal? I'm assuming that your board only allows movement on the boundaries of the array based on what you say, so the following O positions are legal, and X are illegal:

OOOOOOOOOOOOOOO
OXXXXXXXXXXXXXO
OXXXXXXXXXXXXXO
...
OXXXXXXXXXXXXXO
OOOOOOOOOOOOOOO

这篇关于围绕二维数组移动的最佳方法(棋盘游戏)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆