labyrinth_2.py

Created by pikube

Created on November 08, 2019

3.71 KB

ATTENTION: CE PROGRAMME EXIGE TOUTE LA MEMOIRE DE LA CALCULATRICE, ET LE SCRIPT frames_2.py (voir mes autres scripts) DOIT AUSSI ETRE INSTALLE SOUS PEINE DE DYSFONCTIONNEMENT.

Jeu de labyrithe: Atteignez la coupe pour gagner, en utilisant les touches 4;2;8 et 6 suivies de EXE pour aller à gauche;bas;haut;droite respectivement. Si vous souhaitez modifier le niveau: 0=vide; 1=arbre; 2=eau; 3=terre; 5=coupe; tous les multiples de 10=clés d’ID égal au multiple choisi; tous les multiples négatifs de 10=portes d’ID égal au multiple choisi. Noter qu’une porte ne peut être ouverte qu’une fois avec une clé de même ID.

UPDATE par rapport à l’ancien script: Ajout d’un inventaire, nouveau labyrinthe, optimisation des déplacements et des contrôles (la dernière direction choisie reste enregistrée dans la mémoire, donc directement appuyer sur EXE sans retaper la même direction; entre autres, la coupe peut être attrapée de tous les côtés), légères optimisations de la vitesse d’affichage,etc…


import kandinsky as k
import random
from frames_2 import *
x_size=15
y_size=13
#rendered tiles on y\x axis
#needs to be odd
def fill(a,b,c,d,e):
  k.fill_rect(a,b,c,d,e)
level=[
[3,3,1,1,1,1,1,1,3,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1],
[3,3,1,0,0,0,0,0,1,0,0,0,910,1,0,1,2,2,0,0,0,0,1,1,1,0,0,5,1],
[1,1,1,0,1,1,1,0,1,0,1,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,2,1],
[1,0,0,0,1,0,1,0,0,0,0,0,0,1,1,1,1,-280,1,2,1,1,1,1,1,1,1,1,1],
[1,0,1,1,1,0,1,1,1,1,1,1,0,1,0,1,0,0,1,1,1,0,0,0,1,3,3,3,3],
[1,0,1,0,0,0,0,0,0,2,2,1,0,0,0,0,0,0,1,700,0,0,1,0,1,1,1,1,1],
[1,0,1,0,1,1,1,1,1,1,1,1,1,1,2,2,1,1,1,1,1,1,1,0,1,0,-910,0,1],
[1,0,1,0,1,0,0,0,0,0,-50,0,0,1,1,1,1,2,2,2,2,0,0,0,1,0,1,0,1],
[1,0,1,0,1,0,1,1,1,1,1,1,0,1,0,1,2,2,2,0,0,0,0,2,1,0,1,0,1],
[1,0,1,0,1,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,2,2,2,1,0,1,0,1],
[1,0,1,0,0,0,1,0,1,1,1,0,1,1,0,0,0,0,0,1,1,1,1,1,1,0,1,0,1],
[1,0,0,0,2,2,1,0,0,0,1,1,1,0,0,0,1,1,0,1,0,0,1,0,50,0,1,0,1],
[3,1,1,2,2,2,1,0,2,0,-270,0,0,0,0,0,1,2,0,1,1,0,1,1,1,0,1,0,1],
[1,270,1,1,1,1,1,600,0,1,1,0,0,0,0,0,1,2,0,0,1,0,1,0,0,0,1,0,1],
[1,0,1,0,0,0,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,0,1,0,0,1,1,0,1],
[1,0,0,0,1,0,-700,0,0,0,0,0,0,0,0,0,0,0,-600,0,0,0,0,0,0,1,280,0,1],
[1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,1,1],
]
def credits():
  e=["Felicitations!","Vous etes sorti du labyrinthe","","","Merci d'avoir joue,","Pikube"]
  t=0
  while 1:
    fill(0,0,320,222,(0,0,0))
    for cx in range(len(e)):
      k.draw_string("%s"%e[cx],int(160-len(e[cx])*5),-t+222+40*cx,(255,255,255),(0,0,0))
    time.sleep(0.05)
    t+=1
class player():
  def __init__(self):
    self.y=(len(level)-1)/2
    self.x=(len(level[0])-1)/2
    self.dy,self.dx=0,0
    self.key=[]
    while 1:
      self.act()
  def find(self,u):
    for cy in range(len(level)):
      if level[cy].count(u)>0:
        return(cy,level[cy].index(u))
  def render(self):
    #boarders and refresh
    refresh()
    #render each case
    up,left=int(self.y-(y_size-1)/2),int(self.x-(x_size-1)/2)
    for cux in range(x_size):
      for cuy in range(y_size):
        cy=up+cuy
        cx=left+cux
        #in the bounds
        px,py=21*cux+2,17*cuy
        if cy<len(level) and cy>=0 and cx<len(level[0]) and cx>=0:
          if level[cy][cx]==0:
            draw_grass(px,py,1)
          if level[cy][cx]==1:
            draw_tree(px,py)
          if level[cy][cx]==2:
            draw_water(px,py)
          if level[cy][cx]==3:
            draw_rock(px,py)
          if level[cy][cx]==5:
            draw_trophey(px,py)
          if level[cy][cx]>0 and level[cy][cx]%10==0:
            draw_terrain(px,py)
            draw_key(px,py,level[cy][cx])
          if level[cy][cx]<0 and level[cy][cx]%10==0:
            draw_wall(px,py,level[cy][cx])
        #out of bounds
        else:
          draw_rock(px,py)
      if cux==len(self.key):
        draw_inventory(self.key)
    #player
    draw_player(160-11,111-9)
  def act(self):
    #moves
    self.render()
    k=input()
    #collision system
    if self.y<(len(level)-1) and self.y>0 and self.x>0 and self.x<len(level[0])-1:
      if k=="6":
        self.dx,self.dy=1,0
      if k=="4":
        self.dx,self.dy=-1,0
      if k=="2":
        self.dx,self.dy=0,1
      if k=="8":
        self.dx,self.dy=0,-1
      if level[int(self.y+self.dy)][int(self.x+self.dx)]==0:
        self.y+=self.dy
        self.x+=self.dx
      else:
        u=level[int(self.y+self.dy)][int(self.x+self.dx)]
        if u%10==0 and u>0:
          self.y+=self.dy
          self.x+=self.dx
          self.key.append(u)
          level[self.find(u)[0]][self.find(u)[1]]=0
        if u%10==0 and u<0:
          if self.key.count(-u)>0:
            level[self.find(u)[0]][self.find(u)[1]]=0
            self.key.remove(-u)
        if u==5:
          credits()
p=player()

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.