Skip to content

Instantly share code, notes, and snippets.

@bryanyang0528
Created July 12, 2014 03:16
Show Gist options
  • Select an option

  • Save bryanyang0528/1c7421dccd8287ef0d2f to your computer and use it in GitHub Desktop.

Select an option

Save bryanyang0528/1c7421dccd8287ef0d2f to your computer and use it in GitHub Desktop.
monocell_v1.2
class monocell(threading.Thread):
lifeCost = 1
def __init__(self,name,life):
threading.Thread.__init__(self)
self.birthTime = datetime.datetime.now()
self.name = name
self.life = life
def run(self):
#print self.name, "is borned, and birth on", self.birthTime
self.locate = setbirthLocate(land) ##多了取得出生地點的方法
myLand.setLocate(land,self.name, self.locate) ##呼叫地圖物件,在地點上顯示位置
heart(self.name, self.life, self.lifeCost)
myLand.cleanLand(land,self.locate)##死亡後更新地圖物件
thread.exit()
def heart(name,life,lifecost):
while True:
if life <= 0:
print name,"is died"
break
#print name, "remain", life,"HP"
time.sleep(1)
life -= lifecost
def setbirthLocate(land): ##新增的方法,用隨機方式產生地點
locate =[0,0]
locate[0] = randint(0,len(land[0])-1)
locate[1] = randint(0, len(land)-1)
return locate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment