[Tutor PyCZ] Help me
jak.petr na atlas.cz
jak.petr na atlas.cz
Pátek Únor 24 19:23:31 CET 2006
Dobry den,
potreboval bych pomoci s jednim mym programem a to jak mohu udelat aby se roboti ve hre pohybovali vsichni? Zde je zdrojovy a tak vas prosim aby jste mi rekli jak ho upravit.
Jo a je to ve verzi python 2.4.2
Děkuji
Ten kod:
import random
from livewires import *
begin_graphics()
allow_moveables()
class Player:
pass
class Robots:
pass
seznamRobotu=[]
hrac= Player()
robot= Robots()
hrac.x=1
hrac.y=1
0<hrac.x<640
0<hrac.y<480
robot.x=100
robot.y=100
0<robot.x<630
0<robot.y<470
global robot
def vyrobHrace():
global Player
hrac.x=random.randint(0, 630)
hrac.y=random.randint(0, 470)
hrac.telo = circle( hrac.x, hrac.y, 5)
sleep(0.1)
def opakovaniRobotu():
robot.x=random.randint(0, 630)
robot.y=random.randint(0, 470)
def vyrobRobota():
global Robots
robot.telo = circle( robot.x, robot.y, 5, filled=1)
sleep(0.1)
seznamRobotu.append(robot)
def vyrobRoboty():
for robots in range(10):
opakovaniRobotu()
vyrobRobota()
def posunHrace():
global klavesy
klavesy = keys_pressed()
global Player
if "8" in klavesy:
hrac.y=hrac.y+5
move_to(hrac.telo, hrac.x, hrac.y)
sleep(0.1)
if "9" in klavesy:
hrac.x=hrac.x+5
hrac.y=hrac.y+5
move_to(hrac.telo, hrac.x, hrac.y)
sleep(0.1)
if "7" in klavesy:
hrac.x=hrac.x-5
hrac.y=hrac.y+5
move_to(hrac.telo, hrac.x, hrac.y)
sleep(0.1)
if "4" in klavesy:
hrac.x=hrac.x-5
move_to(hrac.telo, hrac.x, hrac.y)
sleep(0.1)
if "6" in klavesy:
hrac.x=hrac.x+5
move_to(hrac.telo, hrac.x, hrac.y)
sleep(0.1)
if "1" in klavesy:
hrac.x=hrac.x-5
hrac.y=hrac.y-5
move_to(hrac.telo, hrac.x, hrac.y)
sleep(0.1)
if "2" in klavesy:
hrac.y=hrac.y-5
move_to(hrac.telo, hrac.x, hrac.y)
sleep(0.1)
if "3" in klavesy:
hrac.y=hrac.y-5
hrac.x=hrac.x+5
move_to(hrac.telo, hrac.x, hrac.y)
sleep(0.1)
def posunRobota():
global Robots
global Robots
if hrac.x<robot.x:
robot.x=robot.x-3
move_to(robot.telo, robot.x, robot.y)
sleep(0.1)
if hrac.x>robot.x:
robot.x=robot.x+3
move_to(robot.telo, robot.x, robot.y)
sleep(0.1)
if hrac.y>robot.y:
robot.y=robot.y+3
move_to(robot.telo, robot.x, robot.y)
sleep(0.1)
if hrac.y<robot.y:
robot.y=robot.y-3
move_to(robot.telo, robot.x, robot.y)
sleep(0.1)
def srazkaHrace():
global Player
for robot in seznamRobotu:
if round(hrac.x) == round(robot.x) and round(hrac.y) == round(robot.y):
return 1
return 0
vyrobHrace()
vyrobRoboty()
while not 0:
global klavesy
global Player
posunHrace()
srazkaHrace()
posunRobota()
srazkaHrace()
if "t" in klavesy:
hrac.x=random.randint(0,630)
hrac.y=random.randint(0,470)
sleep(0.1)
srazkaHrace()
if srazkaHrace():
break
end_graphics()
if "q" in klavesy:
break
end_graphics()
Další informace o konferenci Tutor