选择梯式文字游戏的设计方法 [英] Choosing design method for ladder-like word game

查看:208
本文介绍了选择梯式文字游戏的设计方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图构建一个简单的应用程序,完成的程序看起来像这样:

I'm trying to build a simple application, with the finished program looking like this :

我还必须为此实现两种不同的GUI布局。现在我想弄清楚最好的方法来执行这个任务。我的教授告诉我引入具有4个状态的Element类:

- 空

- 不可见(用于GridLayout)

- 第一个字母

- 其他字母

I will also have to implement two different GUI layouts for this. Now I'm trying to figure out the best method to perform this task. My professor told me to introduce Element class with 4 states :
- empty
- invisible (used in GridLayout)
- first letter
- other letter

我已经考虑过以下解决方案(列表是指任何类型的集合):

1.元素是单字母,每行为Element []。游戏类将是数组Element []。我想这是最蠢的方式,验证可能会很麻烦。

2.像以前一样,但Line是元素列表。游戏是一个线阵列。

3.像以前一样,但游戏是线列表。

I've thought about following solutions (by List I mean any sort of Collection) :
1. Element is a single letter, and each line is Element[]. Game class will be array of arrays Element[]. I guess that's the dumbest way, and the validation might be troublesome.
2. Like previously but Line is a List of Element. Game is an array of Lines.
3. Like previously but Game is a List of Lines.

我应该选择哪一个?或者你有更好的想法吗?什么集合最好如果使用一个?

Which one should I choose ? Or maybe do you have better ideas ? What collection would be best if to use one ?

推荐答案

您的网格是您的内部数据模型(即除了您将使用它)。这就是为什么你可以选择一个是最方便的。

Your grid is your internal data model (i.e. none except for you will use it). That's why you can choose the one which is the most convinient for you.

我喜欢第一个解决方案与数组,因为代码将更加可读(至少为了我)。只需比较:

I would prefer the first solution with arrays because the code will be a little more readable (at least for me). Just compare:

grid[3][4] = element;

grid.get(3).add(4, element);

此外,如果您要使用集合,那么您可能需要使用

Moreover, if you want to use collections, then you probably need to use

Map<Integer, List<Element>> grid

其中Integer-key表示行索引。列表的列表很难插入新单词(只是想,你将如何实现列表只有)。

where Integer-key represents row index. With list of lists it's very difficult to insert new words (just think, how would you implement that with lists only).

这篇关于选择梯式文字游戏的设计方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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