【发布时间】:2012-06-01 12:58:14
【问题描述】:
我正在为我的学校项目创建一个游戏,所以我在这里不是为了任何类型的代码,只是关于如何做我想做的事情的全球想法......
我有 Pieces,每件都有自己的颜色和类型,如下所示:
片 1 - 黄色 - 简单
第 2 部分 - 黄色 - 易爆
....
Piece 10 - 蓝色 - 改变颜色
在游戏开始时,该列表中的随机棋子(之前创建的列表中只有一种棋子),如果我们连续有 3 个或更多棋子,游戏将删除它们并计算分数,但是如果三个(或更多)中的一个具有任何“力量效应”,那么周围的碎片必须对这种力量做出反应(我的英语水平很难解释,但我认为你明白了:S..)
目前我的游戏只有简单的部分,为此我使用了这样的枚举:
public enum CorPeca
{
AMARELO,
AZUL,
VERMELHO;
}
在板课上我是这样做的:
this.arrayPecas = new ArrayList<Peca>();
for (CorPeca corPeca : CorPeca.values())
this.arrayPecas.add(new Peca(corPeca));
在 Pieces 课上我正在这样做
public Peca(CorPeca tipoPeca)
{
this.definirPeca(tipoPeca);
}
public CorPeca getCorPeca() { return this.corPeca; }
public char getCharPeca() { return this.charPeca; }
public void definirPeca(CorPeca tipoPeca)
{
switch (tipoPeca)
{
case AMARELO:
this.charPeca = 'a';
this.corPeca = CorPeca.AMARELO;
break;
case AZUL:
this.charPeca = 'u';
this.corPeca = CorPeca.AZUL;
break;
case VERMELHO:
this.charPeca = 'e';
this.corPeca = CorPeca.VERMELHO;
break;
}
}
但我在想一个很好的方法来轻松添加那些“Power Pieces”,但更重要的是,将来能够添加更多颜色和更多“Powers”......
我正在考虑创建子类并使用扩展,但整个想法并没有填满我的脑海,因为我们不能扩展多个类...
那么谁能给我一个关于如何存档的全局想法?
【问题讨论】: