3D的ArrayList VS堆栈的ArrayList [英] 3d ArrayList vs arrayList of stack

查看:79
本文介绍了3D的ArrayList VS堆栈的ArrayList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图重新建立一个棋盘游戏。此板游戏有一个4×4的尺寸可以重新通过二维数组列表psented $ P $。不过,我有困难做的是决定这将是实现一个4x4的棋盘游戏,其中每行和每列可容纳4个项目(在堆栈的方式,其中上面的项目是最大的INT)的最佳方法是什么。将堆叠的二维数组列表是最有效的在这种情况下,还是会一个3D的ArrayList是要走的路。同样,我怎么会初始化整数数组列表3D?谢谢!

I'm trying to recreate a board game. This board game has a 4x4 dimension which can be represented by a 2D arraylist. However, what i'm having difficulty doing is deciding what would be the best method of implementing a 4x4 board game where each row and column can hold 4 items(In the fashion of a stack where the top item is the greatest int). Would a 2D arraylist of stacks be the most efficient in this case, or would a 3D arraylist be the way to go. Similarly, how would I initialize a 3D arraylist of integers? Thanks!

推荐答案

效率将是罚款无论哪种方式,做什么是最简单的供种,你需要用方块做的事情。你会通过X为引用的事情,Y坐标?然后,你可能希望只使用瓦片的2-D阵列,这样可以参考的东西为

Efficiency is going to be fine either way, do whatever is easiest for the kinds of things you need to do with the squares. Will you be referencing things by their X,Y coordinates? Then you might want to just use a 2-d array of tiles, so you can reference things as

tile = board[x][y]

这假定原点在电路板的左上角。这也是非常有效的,如果这实际上是一个问题。

This assumes that the origin is at the top-left of the board. It's also very efficient, if that were actually an issue.

这篇关于3D的ArrayList VS堆栈的ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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