|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import random
import pygame, sys
from pygame import *
from point类 import Point
pygame.init()
screen = pygame.display.set_mode((600,500))
#病患的患病程度数据监测
v_commonly_recover = -2
v_sick_beside = 0.5
v_get_worse = 1
#病患的三种健康程度颜色表示
healthy_green = 0,255,27
slightly_ill_yellow = 255,215,0
need_first_aid_red = 255,0,0
seriously_sick = set() #创建一个存储重病号位置的集合
#定义一个新的病人函数
class Patient():
def __init__(self, pos_x, pos_y,sick_percent = 65):
self.pos_bed = pos_x, pos_y, 90, 200 #这是画病床的位置
self.patient_vel_x = 0
self.patient_vel_y = 0
self.patient_pos_x = pos_x + 45
if pos_y < 200:
self.patient_pos_y = pos_y +18
self.patient_point =Point(self.patient_pos_x, self.patient_pos_y)
self.pos_patient = self.patient_pos_x, self.patient_pos_y #这是那个病人圆圈的位置
if pos_y > 200:
self.patient_pos_y = pos_y +200 -18
self.patient_point =Point(self.patient_pos_x, self.patient_pos_y)
self.pos_patient = self.patient_pos_x, self.patient_pos_y
self.sp = sick_percent
self.sp_flag = True
self.beside_sick_flag = False
self.x = pos_x + 95
self.y = pos_y + 5
self.pos_instruction = self.x, self.y, 5, 50 #这里是在画那个指示疾病指数的条的外框
self.sick_beside_number = 0 #这个是监测旁边的病人是否为重症的标志
def patient_change(self):
if self.beside_sick_flag:
i_sp_change = random.randint(1,4)
else:
i_sp_change = random.randint(1,7)
if self.sp <= 10:
self.sp_flag = False #设置的意义是为了使得患者在病情指数达到10以下后,就出院,因此会长期保持绿色
if self.sp_flag and i_sp_change == 1: #这是随机病重控制
for times in range(1,6):
self.sp = self.sp + v_get_worse
self.draw_a_patient()
pygame.time.delay(100)
elif self.sp_flag:
self.sp = self.sp + v_commonly_recover #这是标准恢复速度
self.draw_a_patient()
pygame.time.delay(100)
pygame.draw.line(screen,(255,255,255),(self.x+2,self.y+48), (self.x+2,self.y+3),3) #这是在刷新框里的颜色,否则进度条只增不减
pygame.draw.line(screen, (176,196,222),(self.x+2,self.y+50), (self.x+2,self.y+50-(self.sp//2)),3) #这是在描绘动态的指示条
def draw_a_patient(self):
if self.sp <= 10:
color = healthy_green
pygame.draw.circle(screen, color, self.pos_patient, 15, 0)
elif 10 < self.sp < 70:
color = slightly_ill_yellow
pygame.draw.circle(screen, color, self.pos_patient, 15, 0)
elif self.sp>= 70:
color = need_first_aid_red
pygame.draw.circle(screen, color, self.pos_patient, 15, 0)
def draw_a_bed(self): #这里是在画病床和指示条的框
blue = 176,196,222
pygame.draw.rect(screen, blue, self.pos_bed, 3)
pygame.draw.rect(screen, blue, self.pos_instruction, 1)
pygame.draw.line(screen, healthy_green, (self.x +7, self.y+50-5), (self.x + 10, self.y+50-5))
pygame.draw.line(screen, need_first_aid_red, (self.x +7, self.y+50-35), (self.x +10, self.y+50-35))
def watch_patient_beside(self): #这个函数就是用来监测一定距离内的病人是否为重症,主要想法就是如果这个病人指标达到重症,
#那么它的坐标就会被加入到一个集合中,同时关于这个病人也会判断在围绕着这个病人的一定的
#范围内,有没有其他重症患者,如果有,那么“self.beside_sick_flag”就会变成True,反馈到上面的函数中
self.sick_beside_number = 0
if self.sp>= 70 and self.patient_point not in seriously_sick:
seriously_sick.add(self.patient_point)
if self.sp < 70 and self.patient_point in seriously_sick:
seriously_sick.remove(self.patient_point)
for patient_pos in seriously_sick:
if 0 < self.patient_point.distance(patient_pos) < 301:
self.beside_sick_flag = True
self.sick_beside_number +=1
if self.sick_beside_number ==0 :
self.beside_sick_flag = False
def patient_move(self):
if self.patient_pos_x < pos_nurse_station_x:
self.patient_vel_x = 5
elif self.patient_pos_x > pos_nurse_station_x:
self.patient_vel_x = -5
if self.patient_pos_y < pos_nurse_station_y:
self.patient_vel_x = 5
elif self.patient_pos_y > pos_nurse_station_y:
self.patient_vel_x = -5
self.patient_pos_x += self.patient_vel_x
self.patient_pos_y += self.patient_vel_y
screen.fill((255,255,255))
pos_nurse_station = 186, 210, 228, 80
pos_nurse_station_x = 186
pos_nurse_station_y = 210
patient_1 = Patient(40,0)
patient_2 = Patient(40+138,0)
patient_3 = Patient(40+138*2,0)
patient_4 = Patient(40+138*3,0)
patient_5 = Patient(40,300)
patient_6 = Patient(40+138,300)
patient_7 = Patient(40+138*2,300)
patient_8 = Patient(40+138*3,300)
patient_1.draw_a_bed()
patient_2.draw_a_bed()
patient_3.draw_a_bed()
patient_4.draw_a_bed()
patient_5.draw_a_bed()
patient_6.draw_a_bed()
patient_7.draw_a_bed()
patient_8.draw_a_bed()
while True:
for event in pygame.event.get():
if event.type in (QUIT, KEYDOWN):
pygame.quit()
sys.exit()
pygame.draw.rect(screen,(135,206,250), pos_nurse_station, 0 )
pygame.draw.rect(screen,(255,0,0),(191,220,13,3),0)
pygame.draw.rect(screen,(255,0,0),(196,215,3,13),0)
myfont = pygame.font.Font(None, 46)
nurse_station = myfont.render("Nurse Station", True, (65,105,225))
screen.blit(nurse_station, (195,236))
patient_1.patient_move()
patient_2.patient_move()
patient_3.patient_move()
patient_4.patient_move()
patient_5.patient_move()
patient_6.patient_move()
patient_7.patient_move()
patient_8.patient_move()
patient_1.patient_change()
patient_2.patient_change()
patient_3.patient_change()
patient_4.patient_change()
patient_5.patient_change()
patient_6.patient_change()
patient_7.patient_change()
patient_8.patient_change()
patient_1.watch_patient_beside()
patient_2.watch_patient_beside()
patient_3.watch_patient_beside()
patient_4.watch_patient_beside()
patient_5.watch_patient_beside()
patient_6.watch_patient_beside()
patient_7.watch_patient_beside()
patient_8.watch_patient_beside()
pygame.display.update()
以上是代码,我想让表示病人的那几个圆圈动起来,为此设置了patient_move的函数,也没有报错,但是那个图形就是动不起来,请问这是为什么呢
非常感谢!
|
|