Участник: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
def placemove(self,x,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 moveplace(self,x,y):
update_when('key_pressed') self.x=x
key self.y= keys_pressed()[0]y
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
self.y=y
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:
z.move(x.x,x.y)
 
robot_list_copy = robot_list[:]
x.move() # Player.move(x)
for z in robot_list_copy:
finished = finished or stolk_odnogo_i_vseh(x,robot_list) or stolk_odnogo_i_vseh(x,fire_list)
vse_krome_z = robot_list_copy[:]
for z in vse_krome_z.remove(z)robot_list:
self z.move(x=.x,x.y)
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 = if z_stolkrobot_list[:]
# udalyaem z
for z in robot_listrobot_list_copy:
remove_from_screen(z.shape)
vse_krome_z = robot_list.remove(z)robot_list_copy[:]
fire_listvse_krome_z.append(Fireremove(z.x,z.y))
z_stolk = stolk_odnogo_i_vseh(z, vse_krome_z) or stolk_odnogo_i_vseh(z, fire_list)
if n_bomb:
play_sound(mus_bomb) n_bomb = n_bomb or z_stolk
n_bomb = n_bomb orif z_stolk:
 
# 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!