Участник:EgBud/Песочница: различия между версиями
Содержимое удалено Содержимое добавлено
EgBud (обсуждение | вклад) Нет описания правки |
EgBud (обсуждение | вклад) Нет описания правки |
||
Строка 13:
from gasp import * # As usual
class Player:
def __init__(self,x,y):
print "Here I am!"
self.x=x
self.y=y
self.shape = Circle(( self.x*10+5,self.y*10+5 ), 5, filled=True, color=color.RED)
def place(self,x,y):
print "Here I am!"
self.x=x
self.y=y
update_when('key_pressed')
key = keys_pressed()[0]
if key=="1" and self.x!=0 and self.y!=0:▼
self.x=self.x-1▼
self.y=self.y-1▼
elif key=="2" and self.y!=0 :▼
self.y=self.y-1▼
elif key=="3" and self.x!=63 and self.y!=0:▼
self.x=self.x+1▼
self.y=self.y-1▼
elif key=="7" and self.x!=0 and self.y!=47:▼
self.x=self.x-1▼
self.y=self.y+1▼
elif key=="8" and self.y!=47:▼
self.y=self.y+1▼
elif key=="9" and self.y!=47 and self.x!=63:▼
self.x=self.x+1▼
self.y=self.y+1▼
elif key=="4" and self.x!=0:▼
self.x=self.x-1▼
elif key=="6"and self.x!=63:▼
self.x=self.x+1▼
self.shape.move_to((self.x*10+5,self.y*10+5))▼
class Robot:▼
def __init__(self,x,y):▼
self.x=x▼
self.y=y▼
self.shape = Box((10*self.x, 10*self.y), 10, 10)▼
def
▲ if key=="1" and self.x!=0 and self.y!=0:
▲ self.x=self.x-1
▲ self.y=self.y-1
▲ elif key=="2" and self.y!=0 :
▲ self.y=self.y-1
▲ elif key=="3" and self.x!=63 and self.y!=0:
▲ self.x=self.x+1
▲ self.y=self.y-1
▲ elif key=="7" and self.x!=0 and self.y!=47:
▲ self.x=self.x-1
▲ self.y=self.y+1
▲ elif key=="8" and self.y!=47:
▲ self.y=self.y+1
▲ elif key=="9" and self.y!=47 and self.x!=63:
▲ self.x=self.x+1
▲ self.y=self.y+1
▲ elif key=="4" and self.x!=0:
▲ self.x=self.x-1
▲ elif key=="6"and self.x!=63:
▲ self.x=self.x+1
▲ self.shape.move_to((self.x*10+5,self.y*10+5))
▲class Robot:
▲ def __init__(self,x,y):
▲ self.x=x
▲ self.y=y
▲ self.shape = Box((10*self.x, 10*self.y), 10, 10)
▲ def place(self,x,y):
self.x=x▼
def move(self, x_pl,y_pl):
if x_pl>self.x:
self.x=self.x+1
elif x_pl<self.x:
self.x=self.x-1
if y_pl<self.y:
self.y=self.y-1
elif y_pl>self.y:
self.y=self.y+1
self.shape.move_to((self.x*10,self.y*10))
class Fire:
def __init__(self,x,y):
self.x=x
self.y=y
self.shape = Image("fire.bmp", (self.x*10- 5,self.y*10-5), 20, height=20)
def stolk_dvuh(r_1,r_2):
return r_1.x == r_2.x and r_1.y == r_2.y
def stolk_odnogo_i_vseh(r_1, vse):
for y in vse:
if stolk_dvuh(r_1,y):
return True
return False
begin_graphics() # So that you can draw things
finished = False
x = Player(random_between(0, 63),random_between(0, 47))
robot_list=[]
for r in range(60):
robot_list.append(Robot(random_between(0, 63),random_between(0, 47) ))
fire_list=[]
mus_bomb = Sound("bomb.wav")
while not finished and robot_list != []:
n_bomb=False
x.move()
finished = stolk_odnogo_i_vseh(x,robot_list) or stolk_odnogo_i_vseh(x,fire_list)
x.move() # Player.move(x)▼
finished = finished or stolk_odnogo_i_vseh(x,robot_list) or stolk_odnogo_i_vseh(x,fire_list)▼
for z in robot_list:▼
▲ x.move() # Player.move(x)
▲ finished = finished or stolk_odnogo_i_vseh(x,robot_list) or stolk_odnogo_i_vseh(x,fire_list)
for z in
z_stolk = stolk_odnogo_i_vseh(z, vse_krome_z) or stolk_odnogo_i_vseh(z, fire_list)▼
n_bomb = n_bomb or z_stolk▼
robot_list_copy =
remove_from_screen(z.shape)▼
vse_krome_z =
▲ z_stolk = stolk_odnogo_i_vseh(z, vse_krome_z) or stolk_odnogo_i_vseh(z, fire_list)
▲ # udalyaem z
finished = finished or stolk_odnogo_i_vseh(x,robot_list) or stolk_odnogo_i_vseh(x,fire_list)▼
▲ remove_from_screen(z.shape)
robot_list.remove(z)
fire_list.append(Fire(z.x,z.y))
▲ if n_bomb:
play_sound(mus_bomb)
▲ finished = finished or stolk_odnogo_i_vseh(x,robot_list) or stolk_odnogo_i_vseh(x,fire_list)
if robot_list==[]:
Text("YOU WIN", (220,240), color=color.RED, size=70)
else:
Text("YOU LOSE", (220,240), color=color.RED, size=70)
update_when('key_pressed')
end_graphics() # Finished!
|