bin目錄: lib目錄: common.py src目錄: users_business.py admin_business.py Story_start.py ...
- bin目錄:
Simulated_life_start.py
1 #!usr/bin/env python 2 # -*- coding:utf-8 -*- 3 # auther:Mr.chen 4 # 描述: 5 6 7 import sys 8 sys.path.append('..') 9 from src import users_business 10 11 12 users_business.user_Main()
- lib目錄:
Small_monster_model.py
1 #!usr/bin/env python 2 # -*- coding:utf-8 -*- 3 # auther:Mr.chen 4 # 描述:教師模型類 5 6 import random,time,os,sys 7 sys.path.append('..') 8 from lib import common 9 DIR = os.path.dirname(__file__) 10 DIR = DIR.replace('src', 'db/') 11 DICT = common.log_info_read(DIR + 'config_conf') 12 13 class small_monster_Model: 14 ''' 15 小怪物模型類 16 ''' 17 def __init__(self,name,hurt): 18 self.Name = name # 怪物名 19 self.Hurt = hurt # 破壞力 20 self.Drop = ['大還丹','小還丹'] # 掉寶 21 22 23 def __str__(self): 24 return self.Name
Lock_demon_tower_model.py
1 #!usr/bin/env python 2 # -*- coding:utf-8 -*- 3 # auther:Mr.chen 4 # 描述: 5 6 import random,time,sys,os 7 sys.path.append('..') 8 from lib import common 9 10 11 12 13 class lock_demon_tower_Model: 14 ''' 15 鎖妖塔模型類 16 ''' 17 18 19 20 def __init__(self,lname,difficulty,mlist_obj): 21 self.Lname = lname #塔名 22 self.Difficulty = difficulty #難度(小怪攻擊力倍增) 23 self.Mlist_obj = mlist_obj #小怪列表 24 25 26 def __str__(self): 27 return self.Lname
Players_model.py
1 #!usr/bin/env python 2 # -*- coding:utf-8 -*- 3 # auther:Mr.chen 4 # 描述: 5 import random,time,os,sys 6 sys.path.append('..') 7 import common 8 9 DIR = os.path.dirname(__file__) 10 DIR = DIR.replace('src', 'db/') 11 DICT = common.log_info_read(DIR + 'config_conf') 12 13 14 class players_Model: 15 ''' 16 玩家模型類 17 ''' 18 19 20 def __init__(self,name,age,nationality,specialty,gamemode,tlist_obj): 21 self.Name = name # 姓名 22 self.Age = age # 年齡 23 self.Nationality = nationality # 國籍 24 self.Specialty = specialty # 特長 25 self.Strength = 1000 # 體力 26 self.GameMode = gamemode # 游戲模式 27 self.Tlist_obj = tlist_obj # 鎖妖塔層關數列表 28 self.Force = random.randrange(40, 60) # 隨機武力 29 self.IQ= random.randrange(40,60) # 隨機智力 30 self.Charm= random.randrange(40,60) # 隨機魅力 31 self.Item = {'大還丹':0,'小還丹':0} # 背包欄 32 self.schedule = {} 33 self.num = {} 34 for obj in self.Tlist_obj: 35 self.schedule[obj] = 0 #鎖妖塔每層進度率 36 self.num[obj] = 0 #闖塔次數 37 38 39 40 def Begins(self,tobj): #闖塔 41 time.sleep(1) 42 print("{0}慢慢的走了過去,用儘力量推開了{1}的大門,第{2}次闖塔開始!").format(self.Name,tobj,str(self.num[tobj]+1)) 43 re = self.success_Radio() 44 if re != True: 45 self.Battle(tobj) 46 else: 47 time.sleep(1) 48 print ("很幸運,這次沒遇到敵人!") 49 self.schedule[tobj] += 10 50 self.num[tobj] += 1 51 time.sleep(1) 52 print ("{0}結束了本次創塔,{1}的進度率變為{2}%,".format(self.Name, tobj, self.schedule[tobj])) 53 if self.schedule[tobj] == 100: 54 return False 55 else: 56 return True 57 58 59 60 61 def Battle(self,tobj): #戰鬥 62 num = random.randrange(1,len(tobj.Mlist_obj)) 63 bum = random.randrange(1,1000) 64 if bum > self.Charm * 10 : #暴擊判定 65 hurt = (int(tobj.Mlist_obj[num - 1].Hurt) - (self.Force / 20)) * int(tobj.Difficulty) * 2 66 self.Strength = self.Strength - hurt 67 time.sleep(1) 68 print ("{0}對你發起了毀滅性攻擊(暴擊),造成了{1}體力的傷害,你還剩餘{2}體力".format(tobj.Mlist_obj[num - 1].Name, hurt, self.Strength)) 69 else: 70 hurt = (int(tobj.Mlist_obj[num - 1].Hurt) - (self.Force / 20)) * int(tobj.Difficulty) 71 self.Strength = self.Strength - hurt 72 time.sleep(1) 73 print ("{0}對你發起了打擊,造成了{1}體力的傷害,你還剩餘{2}體力".format(tobj.Mlist_obj[num - 1].Name, hurt, self.Strength)) 74 num = random.randrange(1,1000) 75 if num >= 800: 76 print ("費盡艱辛,你終於打敗了怪物,從一堆渣子中你發現了大還丹!!") 77 self.Item['大還丹'] +=1 78 elif num >500 and num <800: 79 print ("費盡艱辛,你終於打敗了怪物,從一堆渣子中你發現了小還丹!!") 80 self.Item['小還丹'] += 1 81 else: 82 print ("費勁艱辛打敗怪物你的,仍舊一無所獲。。。") 83 84 85 def success_Radio(self): #遇敵判定 86 num = random.randrange(1, 1100) 87 if num <= self.IQ * 10: 88 return True 89 else: 90 a = random.randrange(1,5) 91 # print (type(a)) 92 players_Model.event(str(a)) 93 return False 94 95 96 @staticmethod 97 def event(num): #戰鬥事件 98 dict = {'1':'你不小心猜了一坨屎,沒想到當中居然有個怪物,突然向你襲來','2':'你看到一幅畫,畫里的人正是靈兒,突然它看了過來...', 99 '3':'一個怪物坐在一個獨木橋中間,沒辦法你只能向它殺了過去','4':'一個衚衕黑乎乎的,正當你想該往哪走的時候,有個東西摸了你的背後...', 100 '5':'你靜悄悄的緩步繞路,意圖躲開怪物,但是它的同伴卻發現了你....'} 101 time.sleep(1) 102 print (dict[num])
common.py
1 #!usr/bin/env python 2 # -*- coding:utf-8 -*- 3 # auther:Mr.chen 4 # 描述: 5 6 #!/usr/bin/python 7 # -*- coding: utf-8 -*- 8 # 公共方法層 9 10 import os,time,random,pickle 11 12 DIR = os.path.dirname(__file__) 13 DIR = DIR.replace('lib','db/') 14 15 16 TAG = True #迴圈控制標誌 17 18 19 def Exit(): 20 ''' 21 系統退出 22 :return:None 23 ''' 24 print ('程式退出!') 25 exit() 26 27 28 def MD5(password): 29 ''' 30 加密函數 31 :param firstsite: 密碼字元串 32 :return: 加密字元串 33 ''' 34 import hashlib 35 return hashlib.md5(password).hexdigest() 36 37 38 def Verification_input(): 39 ''' 40 登錄驗證碼校驗 41 :return: True 42 ''' 43 while TAG: 44 re = Verification_Code() 45 code = raw_input('請輸入括弧里的驗證碼,不區分大小寫({0}):'.format(re)) 46 if code.strip().lower() != re.lower(): 47 print('您輸入的驗證碼有誤,請重新輸入!') 48 else: 49 return True 50 51 52 def Verification_Code(): 53 ''' 54 生成隨機的6位驗證碼:大小寫字母數字的組合 55 :return: 驗證碼 56 ''' 57 code = '' 58 b = random.randrange(0, 5) 59 c = random.randrange(0, 5) 60 for i in range(6): 61 if i == b: 62 a = random.randrange(1, 9) 63 code = code + str(a) 64 else: 65 a = random.randrange(65, 90) 66 if i == c: 67 code = code + chr(a).lower() 68 else: 69 code = code + chr(a) 70 return code 71 72 73 74 75 76 def log_info_read(dir): 77 ''' 78 配置文件全部讀取 79 :param user:用戶名 80 :return:dict字典 81 如果無文件返回False 82 ''' 83 if os.path.exists(dir): 84 with open(dir,'r') as f: 85 dict = pickle.load(f) 86 return dict 87 else: 88 return False 89 90 91 92 93 def log_info_write(dir,dict): 94 ''' 95 配置文件全部寫入 96 :param user:用戶名 97 :param dict: 日誌字典 98 :return: True or False 99 ''' 100 #if os.path.exists(user+'_log'): 101 #print (DIR+user+'_log') 102 with open(dir,'w') as f: 103 pickle.dump(dict,f) 104 return True
- src目錄:
users_business.py
1 #!usr/bin/env python 2 # -*- coding:utf-8 -*- 3 # auther:Mr.chen 4 # 描述: 5 6 LOGIN = [] 7 TAG = True 8 import os,sys 9 sys.path.append('..') 10 from lib import common 11 from lib.Players_model import players_Model 12 import Story_start 13 14 DIR = os.path.dirname(__file__) 15 DIR = DIR.replace('src','db/') 16 17 18 19 def user_Login(): 20 num = 0 21 List = [] 22 dict = common.log_info_read(DIR + 'config_conf') 23 if dict == False: 24 print ("請讓管理員先創建怪物及鎖妖塔模型後再來!") 25 return 26 if len(dict['players']) == 0: 27 print ("請註冊角色以後再來!") 28 return 29 while TAG: 30 text = """ 31 你一共創建了{0}個角色如下: 32 """.format(str(len(dict['players']))) 33 print (text) 34 for P in dict['players']: 35 print ("{0},姓名:{1},年齡:{2},國籍:{3},特長:{4},體力:{5},武力:{6},智力:{7},魅力:{8},游戲模式:{9}" 36 .format(str(num+1),P.Name,P.Age,P.Nationality,P.Specialty,P.Strength,P.Force,P.IQ,P.Charm,P.GameMode)) 37 num += 1 38 List.append(str(num)) 39 choose = raw_input("請輸入索引選擇登陸角色(單選):") 40 if choose in List: 41 LOGIN.insert(0,dict['players'][int(choose)-1]) 42 print ("{0}角色登陸成功!".format(LOGIN[0].Name)) 43 return 44 else: 45 print ("您的選擇有誤,請重新選擇!") 46 num = 0 47 48 49 50 51 52 53 54 def login_Check(): 55 dict = common.log_info_read(DIR + 'config_conf') 56 57 name = raw_input("請輸入你的姓名:") 58 age = raw_input("請輸入你的年齡:") 59 nationality = raw_input("請輸入你的國籍:") 60 61 text = """ 62 游戲可選特長如下: 63 1,無雙(初始武力+10,武力越高,敵人的傷害越低) 64 2,奇才 (初始智力+10,智力越高遇敵率越低) 65 3,妖異 (初始魅力+10,魅力越高,敵人暴擊率越低) 66 4,守財 (初始體力+300,體力越高越耐打) 67 """ 68 while TAG: 69 print(text) 70 specialty = raw_input("請輸入索引選擇你的特長(單選):") 71 Dic = {'1':'無雙','2':'奇才','3':'妖異','4':'守財'} 72 if specialty in Dic.keys(): 73 specialty = Dic[specialty] 74 break 75 else: 76 print ("你的輸入有誤,請重新輸入!") 77 while TAG: 78 decide = raw_input("是否開啟作弊模式?(y/n)") 79 if decide == 'y': 80 gamemode = '作弊模式' 81 break 82 elif decide == 'n': 83 gamemode = '正常模式' 84 break 85 else: 86 print ("你的輸入有誤!") 87 text = """ 88 你的註冊信息如下: 89 姓名:{0} 90 年齡:{1} 91 國籍:{2} 92 特長:{3} 93 模式:{4} 94 """.format(name,age,nationality,specialty,gamemode) 95 while TAG: 96 print (text) 97 decide = raw_input("是否確認(y/n):") 98 if decide == 'y': 99 P = players_Model(name,age,nationality,specialty,gamemode,dict['towers']) 100 # Dict = {'無雙': 'Force', '奇才': 'IQ', '妖異': 'Charm'} 101 if specialty == '無雙': 102 P.Force += 10 103 elif specialty == '奇才': 104 P.IQ += 10 105 elif specialty == '妖異': 106 P.Charm += 10 107 else: 108 P.Strength += 300 109 if gamemode == '作弊模式': 110 P.Force = 100 111 P.IQ = 100 112 P.Charm = 100 113 P.Strength = 100000 114 115 dict['players'].append(P) 116 common.log_info_write(DIR + 'config_conf', dict) 117 print ('信息註冊成功') 118 return 119 elif decide == 'n': 120 return 121 else: 122 print ('你的輸入有誤!') 123 124 125 126 127 128 129 130 def user_Main(): 131 132 text = """ 133 歡迎體驗模擬的人生 134 1,角色選擇 135 2,角色註冊 136 3,游戲開始 137 4,游戲退出 138 """ 139 while TAG: 140 print (text) 141 dict = {'1':user_Login,'2':login_Check,'3':Story_start.Pre_chapter,'4':common.Exit} 142 choose = raw_input("請輸入你的選擇:") 143 if choose in dict.keys(): 144 if choose == '3' and LOGIN != []: 145 dict[choose](LOGIN[0]) 146 elif choose == '3': 147 print ("請登陸角色後再來!") 148 else: 149 dict[choose]() 150 else: 151 print ("你的輸入有誤!") 152 153 if __name__ == "__main__": 154 user_Main()
admin_business.py
1 #!usr/bin/env python 2 # -*- coding:utf-8 -*- 3 # auther:Mr.chen 4 # 描述: 5 6 import os,sys 7 sys.path.append('..') 8 from lib.Small_monster_model import small_monster_Model 9 from lib.Lock_demon_tower_model import lock_demon_tower_Model 10 from lib import common 11 12 DIR = os.path.dirname(__file__) 13 DIR = DIR.replace('src','db/') 14 15 TAG = True 16 17 def create_monsters_model(): 18 """ 19 創建小怪模型 20 :return: None 21 """ 22 while TAG: 23 name = raw_input("請輸入怪物的姓名:") 24 hurt = raw_input("請輸入怪物的破壞力:") 25 text = """ 26 怪物信息如下: 27 姓名: {0} 28 破壞力:{1} 29 """.format(name,hurt) 30 print (text) 31 decide = raw_input("是否確認(y/n):") 32 if decide == 'y': 33 M = small_monster_Model(name,hurt) 34 dict = common.log_info_read(DIR+'config_conf') 35 if dict != False: 36 dict['monsters'].append(M) 37 common.log_info_write(DIR + 'config_conf', dict) 38 print ("怪物信息保存成功!") 39 return 40 else: 41 dict = { 42 'monsters