クローズ
2246 ワード
# class; def(self), class private
# : class, , , , ( / )
CASE:
------------------------------------------------------------ --------------------------------------------------------
origin = [0, 0] #
legal_x = [0, 50] # x
legal_y = [0, 50] # y
def create(pos=origin):
def player(direction, step):
# direction,step , direction ,step
# x,y , , 。
new_x = pos[0] + direction[0] * step
new_y = pos[1] + direction[1] * step
pos[0] = new_x
pos[1] = new_y
# ! pos = [new_x, new_y],
return pos
return player
player = create() # player,
print player([1, 0], 10) # x 10
print player([0, 1], 20) # y 20
print player([-1, 0], 10) # x 10
################################################################ ########################################
origin = [0, 0] #
legal_x = [0, 50] # x
legal_y = [0, 50] # y
class create():
def __init__(self,origin):
self.pos = origin
def player(self,direction, step):
# direction,step , direction ,step
# x,y , , 。
new_x = self.pos[0] + direction[0] * step
new_y = self.pos[1] + direction[1] * step
self.pos[0] = new_x
self.pos[1] = new_y
# ! pos = [new_x, new_y],
print self.pos
c=create(origin)
c.player([1,0],10)
c.player([0,1],20)
c.player([-1,0],10)
----------------------------------------------------- ----------------------------------------------------------
def foo():
a = []
def bar():
a.append(100)
return a
return bar
if __name__ == "__main__":
b = foo()
c = foo()
print b()
print b()
print c()