今天用Python写的文字游戏,部分代码分享一下:
import random
global gl
gl={1:'diamond_helmet',2:'diamond_chesplate',3:'diamond_legging',4:'diamond_boot',5:'iron_helmet',6:'iron_chesplate',7:'iron_legging',8:'iron_boot',9:'diamond_sword',10:'iron_sword',11:'gun',12:'bullet'}
class thing:
class object:
class minecart():
def coin(s,l):
return random.seed(s*l)%50
def gears(s,l):
return gl[random.seed(s)%13]
class box():
def coin(s,l):
return random.seed(s*l)%50
def gears(s,l):
return gl[random.seed(s)%13]
class mobs():
class nonhostile():
def trader(t,s):
if type=='armor':
a=input('everything for',random.seed(s),'! \n enter nunber for your choose:',gl[1:8])
#TODO:make the player -money and +gear
else:
a=input('everything for',random.seed(s),'! \n enter nunber for your choose:',gl[9:])
这部分代码主要是定义了一些“mob”与“NPC”,并用清晰地class分类法分类,如果你们有什么NPC想让我加入游戏的,可以在评论中发出,谢谢!