【发布时间】:2009-05-26 11:54:23
【问题描述】:
我有Tiles 代表游戏二维世界中的图块。瓷砖可以在任意数量的 4 个面上有墙。我现在有这样的事情:
interface Tile {
boolean isWallAtTop();
boolean isWallAtRight();
boolean isWallAtLeft();
boolean isWallAtBottom();
}
在其他地方,我也有 16 张图片,每个可能的瓷砖墙配置一张。像这样的:
static final Image WALLS_ALL_AROUND = ...
static final Image WALL_ON_TOP_AND_RIGHT = ...
/* etc etc all 16 possibilities */
我想写一篇
static Image getWallImage(Tile tile)
我想避免是经历像
这样的可能性的折磨if (tile.isWallTop && tile.isWallRight
&& !tile.isWallBottom && !tile.isWallLeft) {
return WALL_ON_TOP_AND_RIGHT;
}
有人知道更可爱的方法吗?
【问题讨论】:
标签: c# java c++ data-structures