Commit 05344d1f by BellCodeEditor

save project

parent 67966cb5
Showing with 20 additions and 5 deletions
import random import random
name_log = [] co_log = {}
hp_log = [] log = {}
class yx: class yx:
def __init__(self,name,hp,lv): def __init__(self,name,hp,lv):
self.name = name self.name = name
self.lv = lv self.lv = lv
self.hp = hp self.hp = hp
self.att = random.randint(1,200) self.att = random.randint(1,200)
self.num = 0
print('角色',str(self.name),'创建成功!血量:',str(self.hp),'攻击力:',str(self.att),'等级:',str(self.lv)) print('角色',str(self.name),'创建成功!血量:',str(self.hp),'攻击力:',str(self.att),'等级:',str(self.lv))
def combat(self, name): def combat(self, name):
name.hp = name.hp - self.att name.hp = name.hp - self.att
print(str(self.name),'向',str(name.name),'使用了',str(self.att),'点伤害,',str(name.name),'还剩',str(name.hp),'点血量') print(str(self.name),'向',str(name.name),'使用了',str(self.att),'点伤害,',str(name.name),'还剩',str(name.hp),'点血量')
co_log["发起攻击"] = self.name
co_log["受到攻击"] = name.name
co_log["伤害点数"] = self.att
co_log["剩余点数"] = name.hp
log[self.num] = co_log
self.num = self.num + 1
a = yx('a',200,1) a = yx('a',200,1)
b = yx('b',2000,1) b = yx('b',3000,1)
a.combat(b) while True:
\ No newline at end of file if input("请输入指令:") == "1":
a.combat(b)
else:
print("无效的字符数!")
if int(b.hp) < 0:
print('游戏结束!')
print(log)
break
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment