计时器 2.5s刷新
计数器 —— 标准计数器(1, 0, 0)
代码实现
import random
class Enemy:
def __init__(self):
self.hit = 0
self.hit_all = 0
self.time = 0.0
self.flag = True
self.restart = True
self.jihua = 1
self.gap = 0.0
def renew(self):
self.hit = 0
self.hit_all = 0
self.time = 0.0
self.flag = True
self.restart = True
self.jihua = 1
self.gap = 0.0
def do_restart(self, time):
self.restart = True
self.hit = 1
self.hit_all += 1
self.jihua += 1
self.time = time
def enemy_time_hit(self, time=0.0):
if self.flag:
self.time = time
self.flag = False
self.gap = time - self.time
if self.hit == 3 or self.gap >= 2.5:
self.do_restart(time)
else:
self.restart = False
self.hit += 1
self.hit_all += 1
def jihua_rate(self):
return self.jihua, self.hit_all
def create_sha_sheng_ying(head):
return [head, head+3, head+6, head+9, head+12]
def ssy_sum(*args):
s = []
for i in args:
s = s + i
s.sort()
return s
if __name__ == '__main__':
enemy_1 = Enemy()
enemy_2 = Enemy()
enemy_3 = Enemy()
enemy_4 = Enemy()
enemy_5 = Enemy()
enemy_6 = Enemy()
enemy_7 = Enemy()
enemy_8 = Enemy()
s = []
count = 1000
ssy1 = create_sha_sheng_ying(0)
ssy2 = create_sha_sheng_ying(0.5)
ssy3 = create_sha_sheng_ying(1)
ssy = ssy_sum(ssy1, ssy2, ssy3)
print(ssy)
for j in range(count):
enemy_1.renew()
for i in range(len(ssy)):
enemy_1.enemy_time_hit(ssy[i])
num_1, all_1 = enemy_1.jihua_rate()
s.append(num_1 / all_1)
print(sum(s) / count)
s = []
for j in range(count):
enemy_1.renew()
enemy_2.renew()
for i in range(len(ssy)):
k = random.randint(0, 1)
if k == 0:
enemy_1.enemy_time_hit(ssy[i])
elif k == 1:
enemy_2.enemy_time_hit(ssy[i])
num_1, all_1 = enemy_1.jihua_rate()
num_2, all_2 = enemy_2.jihua_rate()
s.append((num_1 + num_2) / (all_1 + all_2))
print(sum(s)/count)
s = []
for j in range(count):
enemy_1.renew()
enemy_2.renew()
enemy_3.renew()
for i in range(len(ssy)):
k = random.randint(0, 2)
if k == 0:
enemy_1.enemy_time_hit(ssy[i])
elif k == 1:
enemy_2.enemy_time_hit(ssy[i])
elif k == 2:
enemy_3.enemy_time_hit(ssy[i])
num_1, all_1 = enemy_1.jihua_rate()
num_2, all_2 = enemy_2.jihua_rate()
num_3, all_3 = enemy_3.jihua_rate()
s.append((num_1 + num_2 + num_3) / (all_1 + all_2 + all_3))
print(sum(s)/count)
s = []
for j in range(count):
enemy_1.renew()
enemy_2.renew()
enemy_3.renew()
enemy_4.renew()
enemy_5.renew()
for i in range(len(ssy)):
k = random.randint(0, 4)
if k == 0:
enemy_1.enemy_time_hit(ssy[i])
elif k == 1:
enemy_2.enemy_time_hit(ssy[i])
elif k == 2:
enemy_3.enemy_time_hit(ssy[i])
elif k == 3:
enemy_4.enemy_time_hit(ssy[i])
elif k == 4:
enemy_5.enemy_time_hit(ssy[i])
num_1, all_1 = enemy_1.jihua_rate()
num_2, all_2 = enemy_2.jihua_rate()
num_3, all_3 = enemy_3.jihua_rate()
num_4, all_4 = enemy_4.jihua_rate()
num_5, all_5 = enemy_5.jihua_rate()
s.append((num_1 + num_2 + num_3 + num_4 + num_5) / (all_1 + all_2 + all_3 + all_4 + all_5))
print(sum(s) / count)
# s = []
# for j in range(count):
# enemy_1.renew()
# enemy_2.renew()
# enemy_3.renew()
# enemy_4.renew()
# enemy_5.renew()
# enemy_6.renew()
# enemy_7.renew()
# enemy_8.renew()
# for i in range(len(ssy)):
# k = random.randint(0, 7)
# if k == 0:
# enemy_1.enemy_time_hit(ssy[i])
# elif k == 1:
# enemy_2.enemy_time_hit(ssy[i])
# elif k == 2:
# enemy_3.enemy_time_hit(ssy[i])
# elif k == 3:
# enemy_4.enemy_time_hit(ssy[i])
# elif k == 4:
# enemy_5.enemy_time_hit(ssy[i])
# elif k == 5:
# enemy_6.enemy_time_hit(ssy[i])
# elif k == 6:
# enemy_7.enemy_time_hit(ssy[i])
# elif k == 7:
# enemy_8.enemy_time_hit(ssy[i])
# num_1, all_1 = enemy_1.jihua_rate()
# num_2, all_2 = enemy_2.jihua_rate()
# num_3, all_3 = enemy_3.jihua_rate()
# num_4, all_4 = enemy_4.jihua_rate()
# num_5, all_5 = enemy_5.jihua_rate()
# num_6, all_6 = enemy_6.jihua_rate()
# num_7, all_7 = enemy_7.jihua_rate()
# num_8, all_8 = enemy_8.jihua_rate()
# s.append((num_1 + num_2 + num_3 + num_4 + num_5 + num_6 + num_7 + num_8) /
# (all_1 + all_2 + all_3 + all_4 + all_5 + all_6 + all_7 + all_8))
# print(sum(s) / count)