005 基于面向对象设计一个简单的游戏
这是一个非常简单的python面向对象游戏,其中瑞文与盖文互相攻击的代码
class ruiwen:
print("""
国服售价:6300金币/3500点卷;英雄标签:上单,战士,刺客;魔法值:0;
魔法回复:0;暴击加成:200;魔法减免:23%;移动范围:350;
攻击范围:125;攻击速度:0.62,护甲:12;魔法抗性:30.
""")
def init(self, name, gongjili, shengmingzhi = 414):
self.name = name
self.gongjili = gongjili
self.shengmingzhi = shengmingzhi
def gongji(self, target):
target.shengmingzhi -= self.gongjili
print("""
%s瑞文攻击了一下%s盖文,
盖文掉血:%s
盖文的血量剩余:%s
"""%( self.name, target.name, self.gongjili, target.shengmingzhi))
class gaiwen:
print("""
国服售价:3100金币/2000点卷;英雄标签:近战,爆发,tank;
生命回复:9.0;魔法值:0;
魔法回复:0;移动速度:200;攻击范围:125;
攻击速度:0.69,护甲:19;魔法抗性:30;
暴击加成:0%;魔法减免:0%
""")
def __init__(self, name, gongjili, shengmingzhi):
self.name = name
self.gongjili = gongjili
self.shengmingzhi = shengmingzhi
def gongji(self, target):
target.shengmingzhi -= self.gongjili
print("""
%s盖文攻击了一下%s瑞文,
瑞文掉血:%s
瑞文的血量剩余:%s
""" % (self.name, target.name, self.gongjili, target.shengmingzhi))
ruiwen1 = ruiwen('ruiwen', 54, 414)
gaiwen1 = gaiwen('gaiwen', 56, 455)
ruiwen1.gongji(gaiwen1)
print(gaiwen1.shengmingzhi)
ruiwen1.gongji(gaiwen1)
print(ruiwen1.shengmingzhi)
gaiwen1.gongji(ruiwen1)
print(ruiwen1.shengmingzhi)