labyrinthev1.py

Created by stimorol

Created on December 16, 2021

1.73 KB

Jeu simple d’un labyrinthe: Le joueur peut se déplacer grâce aux flèches de la calculatrice, et son but est d’atteindre le côté droit de l’écran. Vous pouvez modifier la difficulté du labyrinthe et beaucoup d’autres paramètres depuis le script (comme l’écart entre les murs, la longueur des murs ou encore le nombre de murs…). D’autres mises a jour de ce programme sont susceptibles d’arriver dans les prochaines semaines, notamment pour l’ajout d’un menu pour modifier les graphismes


from kandinsky import *
from ion import *
from random import *
from turtle import *
from time import *

keys=[KEY_UP,KEY_DOWN,KEY_RIGHT,KEY_LEFT]
movementsKey=[-1,1,1,-1]

def draw_lab(diff,maxx=16,maxy=11,coef=20,lenMurs=60):
  reset()
  numx=numy=[]
  hideturtle()
  draw_line(322,0,322,111,'green')
  draw_line(321,0,321,111,'green')
  draw_line(0,0,322,0,'black')
  draw_line(0,0,0,222,'black')
  draw_line(0,222,322,222,'black')
  for i in range(diff):
    x, y=randint(1,maxx)*coef, randint(1,maxy)*coef
    if numx.count(x)==2:
      x=randint(1,maxx)*coef
      if numx.count(x)==2:x=randint(1,maxx)*coef
    numx.append(x)
    draw_line(x,y,x+randint(20,lenMurs),y,'black')
    x, y=randint(0,maxx)*coef, randint(0,maxy)*coef
    if numy.count(y)==2:
      y=randint(0,maxy)*coef
      if numy.count(y)==2:y=randint(0,maxy)*coef
    numy.append(y)
    draw_line(x,y,x,y+randint(20,lenMurs),'black')
  
def labyrinthe(diff,maxx=16,maxy=11,coef=20,lenMurs=60, level=0):
  draw_lab(diff,maxx,maxy,coef,lenMurs)
  x, y, stop=3, 111, False
  set_pixel(x,y,'red')
  while not stop:
    for i in keys:
      if keydown(i):
        number=keys.index(i)
        if number>=2:movementX, movementY=movementsKey[number], 0
        elif number<2:movementX, movementY=0, movementsKey[number]
        while keydown(i):
          x+=movementX
          y+=movementY
          if get_pixel(x,y)[0] == (248):set_pixel(x,y,'red')
          else:
            x-=movementX
            y-=movementY
          sleep(0.0075)
    if x >= 318:
      reset()
      hideturtle()
      level+=1
      draw_string("BRAVO!\n       NIVEAU "+str(level)+" REUSSI",110,90)
      sleep(1.5)
      labyrinthe(diff+1, maxx, maxy, coef, lenMurs, level)

labyrinthe(86,11,20,55)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

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.