frommathimport*fromkandinskyimport*fromrandomimport*fromtimeimportsleep,timefromionimport*defdraw_line(x1,y1,x2,y2,c):width=x2-x1height=y2-y1ifabs(width)>=abs(height):div=height/widthforiinrange(0,width,(width>0)*2-1):set_pixel(x1+i,y1+int(div*i+0.5),c)else:div=width/heightforiinrange(0,height,(height>0)*2-1):set_pixel(x1+int(div*i+0.5),y1+i,c)defdraw_circle(center_x,center_y,rayon,couleur):forxinrange(center_x-rayon,center_x+rayon+1):foryinrange(center_y-rayon,center_y+rayon+1):if (x-center_x)**2+(y-center_y)**2<=rayon**2:set_pixel(x,y,couleur)definitialisation(etat=0):try:get_keys()os_color=(192,53,53)except:os_color=(255,183,52)ifetat==0:fill_rect(1,204,320,18,os_color)draw_string("Documents retrouvés :",2,204,(255,255,255),os_color)else:fill_rect(1,204,320,18,os_color)defpersonnage(position,aff=0):color=(255,0,0)ifaffelse (0,0,0)fill_rect(position[0]-5,position[1]-1,10,2,color)fill_rect(position[0]-1,position[1]-5,2,10,color)defcollision(point_rouge,position):return (point_rouge[0]>=position[0]-5andpoint_rouge[0]<=position[0]+5andpoint_rouge[1]>=position[1]-5andpoint_rouge[1]<=position[1]+5)defmove(position,bordure,vitesse):mvt=position[:]is_key_pressed=Falseifkeydown(1):# Haut
mvt[1]=max(position[1]-vitesse,bordure[2])is_key_pressed=Trueifkeydown(2):# Bas
mvt[1]=min(position[1]+vitesse,bordure[3])is_key_pressed=Trueifkeydown(3):# Droite
mvt[0]=min(position[0]+vitesse,bordure[1])is_key_pressed=Trueifkeydown(0):# Gauche
mvt[0]=max(position[0]-vitesse,bordure[0])is_key_pressed=Truereturnmvtifis_key_pressedelsepositiondefjeu(point,temps_a_faire):position=[160,111]start_time=Nonebordure=(5,319,5,201)# x_min, x_max, y_min, y_max
# Affichage initial
initialisation(etat=0)personnage(position,1)# Choix d'une ville aléatoire
liste_villes=list(emplacement_villes.keys())index_aleatoire=randint(0,len(liste_villes)-1)ville=liste_villes[index_aleatoire]point_rouge=emplacement_villes[ville]# Dessine le point rouge
draw_circle(point_rouge[0],point_rouge[1],3,(255,0,0))draw_string(ville,point_rouge[0]+10,point_rouge[1]-20,(255,0,0))whileTrue:sleep(0.1)personnage(position,0)# Efface ancienne position
position=move(position,bordure,vitesse=5)personnage(position,1)# Dessine nouvelle position
ifcollision(point_rouge,position):end_time=time()ifstart_timeisNone:start_time=time()elapsed_time=end_time-start_timeifelapsed_time<=temps_a_faire:point+=1temps_a_faire-=0.1draw_string("Bravo, tu gagnes 1 point!",100,100,(0,255,0))else:draw_string("Dommage, un peu trop lent...",100,100,(255,0,0))breakreturnpoint,temps_a_faire# Variables initiales
point=0temps_a_faire=3emplacement_villes={"Paris":(143,45),"New York":(80,60),"Mexico":(60,95),"Moscou":(170,43),"Tokyo":(265,60),"Vancouver":(40,50),"Mumbai":(213,95),"Buenos Aires":(93,160),"Lagos":(143,107),"Johannesburg":(168,145)}# Boucle principale du jeu
whilepoint<10:point,temps_a_faire=jeu(point,temps_a_faire)# Fin du jeu
draw_string("Félicitations, vous avez gagné !",100,100,(0,255,0))
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.