Skip to content

Instantly share code, notes, and snippets.

@bryanyang0528
Created July 12, 2014 03:13
Show Gist options
  • Save bryanyang0528/cdc6a7de22d69d509f28 to your computer and use it in GitHub Desktop.
Save bryanyang0528/cdc6a7de22d69d509f28 to your computer and use it in GitHub Desktop.
create the map
## create the map
land=[]
class Myland:
##建立一個場景物件
def creatLand(self,size,symbol):
#這邊有兩個參數,size決定邊長,symbol可讓使用者自行輸入想要的圖示
self.symbol = str(symbol) ##不管使用者輸入什麼都轉成str
for i in range(size):##用for迴圈做出i個row
land.append([self.symbol for x in range(size)]) #用內建迴圈做出一個row
def printLand(self,land): ##列印方法
for i in range(len(land)):
print " ".join(land[i])
def setLocate(self,land,name,locate): ##讓寵物出現在地圖上的方法
land[locate[1]][locate[0]] = name[0].upper() ##取名字的第一個字並轉大寫
def cleanLand(self,land,locate): ##當寵物掛點後要清除地圖
land[locate[1]][locate[0]] = self.symbol
myLand = Myland()
myLand.creatLand(10,"艸")
myLand.printLand(land)
"""
馬上就出現草皮了!!
艸 艸 艸 艸 艸 艸 艸 艸 艸 艸
艸 艸 艸 艸 艸 艸 艸 艸 艸 艸
艸 艸 艸 艸 艸 艸 艸 艸 艸 艸
艸 艸 艸 艸 艸 艸 艸 艸 艸 艸
艸 艸 艸 艸 艸 艸 艸 艸 艸 艸
艸 艸 艸 艸 艸 艸 艸 艸 艸 艸
艸 艸 艸 艸 艸 艸 艸 艸 艸 艸
艸 艸 艸 艸 艸 艸 艸 艸 艸 艸
艸 艸 艸 艸 艸 艸 艸 艸 艸 艸
艸 艸 艸 艸 艸 艸 艸 艸 艸 艸
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment