标签:span gif imp 子弹 class col let info dash
之前使用java进行一个比较简单的实验——模拟打枪游戏,具体内容就在这里不多说了,以下是python版本,对于python在语法要求上相对其他语言较为松散,所以在编写时遇到了一些坑。
代码:
1 class BULLET_BOX: 2 def __init__(self): 3 self.bullet_count = 0 4 5 def Add_Bullet(self, count): 6 self.bullet_count = count 7 8 def See_Bullet(self): 9 return self.bullet_count
1 class GUN: 2 def __init__(self, BULLET_BOX): 3 self.BULLET_BOX = BULLET_BOX 4 5 def Shoot(self): 6 self.count = self.BULLET_BOX.See_Bullet() 7 if (self.count > 0): 8 self.count = self.BULLET_BOX.See_Bullet() 9 self.count = self.count - 1 10 self.BULLET_BOX.Add_Bullet(self.count) 11 print("砰——") 12 print("当前子弹数:",self.count) 13 else: 14 print("子弹不足!")
1 class BULLET_BOX: 2 def __init__(self): 3 self.bullet_count = 0 4 5 def Add_Bullet(self, count): 6 self.bullet_count = count 7 8 def See_Bullet(self): 9 return self.bullet_count
1 import time, PEOPLE, GUN, BULLET_BOX 2 3 from PEOPLE import * 4 from GUN import * 5 from BULLET_BOX import * 6 7 a = BULLET_BOX() 8 a.Add_Bullet(5) 9 b = GUN(a) 10 c = PEOPLE(b) 11 12 while True: 13 c.Fire() 14 time.sleep(1)
代码效果:
标签:span gif imp 子弹 class col let info dash
原文地址:https://www.cnblogs.com/moegarn/p/12355113.html