本文仅个人娱乐所用。
趁着空闲,把昨天的程序完善了下,做成了一个控制台小游戏。不得不说,我的智商被爆了。
import random
class ActionType:
Dec = 0 #将火柴移出
Inc = 1 #将火柴移入
SelfTrans = 2
class PositionType:
Default = 0
FrontEmpty = 1
class Side:
Left = 0
Right = 1
class Item:
def __init__(self,value,positionType,side):
self.value = value
self.positionType = positionType
self.side = side
class Match:
def __init__(self):
self.G = {
0: [1, 1, 1, 1, 1, 1, 0],
1: [0, 1, 1, 0, 0, 0, 0],
2: [1, 1, 0, 1, 1, 0, 1],
3: [1, 1, 1, 1, 0, 0, 1],
4: [0, 1, 1, 0, 0, 1, 1],
5: [1, 0, 1, 1, 0, 1, 1],
6: [1, 0, 1, 1, 1, 1, 1],
7: [1, 1, 1, 0, 0, 0, 0],
8: [1, 1, 1, 1, 1, 1, 1],
9: [1, 1, 1, 1, 0, 1, 1]
}
self.M = {}
self.image_cache = {}
def _makeImage(self,c):
image = None
if c == "+":
image = [
["*", "*", "*", "*", "*"],
["*", "*", "*", "*", "*"],
["*", "*", "@", "*", "*"],
["*", "*", "@", "*", "*"],
["@", "@", "@", "@", "@"],
["*", "*", "@", "*", "*"],
["*", "*", "@", "*", "*"],
["*", "*", "*", "*", "*"],
["*", "*", "*", "*", "*"]
]
elif c == "-":
image = [
["*", "*", "*", "*", "*"],
["*", "*", "*", "*", "*"],
["*", "*", "*", "*", "*"],
["*", "*", "*", "*", "*"],
["@", "@", "@", "@", "@"],
["*", "*", "*", "*", "*"],
["*", "*", "*", "*", "*"],
["*", "*", "*", "*", "*"],
["*", "*", "*", "*", "*"]
]
elif c == "=":
image = [
["*", "*", "*", "*", "*"],
["*", "*", "*", "*", "*"],
["*", "*", "*", "*", "*"],
["@", "@", "@", "@", "@"],
["*", "*", "*", "*", "*"],
["@", "@", "@", "@", "@"],
["*", "*", "*", "*", "*"],
["*", "*", "*", "*", "*"],
["*", "*", "*", "*", "*"]
]
else:
d = ord(c) - ord('0')
if 0 <= d <= 9:
image = [["*" for j in range(5)] for i in range(9)]
if self.G[d][0] == 1:
image[0][0] = "@"
image[0][1] = "@"
image[0][2] = "@"
image[0][3] = "@"
image[0][4] = "@"
if self.G[d][1] == 1:
image[0][4] = "@"