如何简化这个if语句?它是一个加号: http://i.stack.imgur.com/PtHO1.png
如果语句完成,则在x和y坐标处设置一个块。在
for y in range(MAP_HEIGHT):
for x in range(MAP_WIDTH):
if (x%5 == 2 or x%5 == 3 or x%5 == 4) and \
(y%5 == 2 or y%5 == 3 or y%5 == 4) and \
not(x%5 == 2 and y%5 == 2) and \
not(x%5 == 4 and y%5 == 2) and \
not(x%5 == 2 and y%5 == 4) and \
not(x%5 == 4 and y%5 == 4):
...
有两个小问题:
x % 5
和y % 5
的结果in
或链式<
来测试这些值:另外,
<= 4
(或< 5
)的测试实际上是多余的,因为lx
和ly
的每个值都是<;5。在或者您可以保留一个实际允许的元组列表:
^{pr2}$基本上你是平铺一个5x5二进制模式。这里有一个明确的表述:
这是一个非常简单和通用的方法,它可以很容易地修改模式。在
这是一样的:
相关问题 更多 >
编程相关推荐