pipemania.py

Created by schraf

Created on July 07, 2022

4.35 KB

D’autres jeux pour la NUMWORKS sur ma chaine Youtube : Rubika, solitaire, Mission missile, démineur, carré magique, TRON, défis de blanche…

Explications en vidéo

Le célèbre jeu Pipe Mania (Pipe Dream) pour votre Numworks.

Pour jouer

  • Evitez la fuite en plaçant des tuyaux et formez un parcours
  • Flèches de directions
  • Touche EXE pour placer un tuyau
  • Pour passer au niveau suivant, dist doit être égal à zéro
  • OK pour passer au tour suivant


from random import choice, randint
from kandinsky import fill_rect as fr, draw_string as dt
from ion import *
from time import monotonic

PIECES = 'gb,db,hb,gd,gdhb,gh,hd,d,g,h,b'.split(',')
CASES = {'g': (0,1), 'd': (2,1), 'c' : (1,1), 'b': (1,2), 'h': (1,0)}
COLORS = ((50, 50, 50), (75, 115, 153), (192, 192, 192), (255, 255, 0),(0,255,0), (255,0,0))
SENS = ((1,0), (-1,0), (0,-1), (0,1))
EAU_DEP = 8

def plateau():
  fr(0, 0, 320, 222, COLORS[0])
  [fr(x * 28 + 1, y * 28 + 1, 27, 27, COLORS[2]) for y in range(7) for x in range(10)]
  carre(COLORS[3]) 
  change_score(0)

def infos():
  for i in range(5):
    piece(10, 5 - i, PIECES[suivants[i]], COLORS[1], 7)

def change_score(n):
  global score
  score = max(score + n, 0)
  dt('score : ' + str(score) + '   ', 10, 200, COLORS[2], COLORS[0])
  dt('dist : ' + str(dist) + '   ', 180, 200, COLORS[2], COLORS[0])

def depart():
  global dx, dy, dep, grid
  dx, dy = randint(1, 8), randint(1, 5)
  dep = choice(range(4))
  grid[dx][dy] = 7 + dep 
  piece(dx, dy, PIECES[7 + dep], COLORS[4])

def piece(x, y, s, c, m = 0):
    fr(x * 28 + m + 1, y * 28 + 1, 27, 27, COLORS[2])
    for a in s + 'c':
        [u, v] = CASES[a]
        fr(x * 28 + 9 * u + m + 1, y * 28 + 9 * v + 1, 9, 9, c)
    carre(COLORS[3])

def carre(col):
    (x, y) = (coo[0] * 28, coo[1] * 28)
    fr(x, y, 28, 1, col)
    fr(x, y + 28, 28, 1, col)
    fr(x, y + 1, 1, 27, col)
    fr(x + 28, y + 1, 1, 27, col)

def cur(n):
    global key, coo
    vx, vy = SENS[n]
    if monotonic() - key['tps'] > 0.125:
        key['tps'] = monotonic()
        carre(COLORS[0])
        coo[0] += vx
        coo[1] += vy
        carre(COLORS[3])

def remplir(x, y, u, v):
  fr(x * 28 + 9 * u + 1, y * 28 + 9 * v + 1, 9, 9, COLORS[4])

def inv(v):
  return {'g':'d', 'd':'g', 'h':'b', 'b':'h'}[v]

def go():
  global key, coo, suivants, grid, dx, dy, dep, score, dist
  game, score = 1, 0
  while game:
    grid = [[-1 for x in range(7)] for y in range(10)]
    eau = {'delai': EAU_DEP, 'av': False, 'tps': monotonic()}
    key = {'rel': True, 'tps': monotonic()}
    coo = [0, 0]
    run = 1
    dist = min(8 + game, 25)
    suivants = [choice(range(7)) for _ in range(5)]
    plateau()
    depart()
    infos()
    while run:
        if keydown(KEY_RIGHT) and coo[0] < 9: cur(0)
        elif keydown(KEY_LEFT) and coo[0] > 0: cur(1)
        elif keydown(KEY_UP) and coo[1] > 0: cur(2)
        elif keydown(KEY_DOWN) and coo[1] < 6: cur(3)
        elif keydown(KEY_PLUS) and eau['av']: 
          eau['delai'] /= 1.5
          key['tps'] = monotonic()
        elif keydown(KEY_BACK): run, game = 0, 0
        elif keydown(KEY_EXE) and grid[coo[0]][coo[1]] < 7:
            if key['rel']:
                if grid[coo[0]][coo[1]] != -1: change_score(-50)
                grid[coo[0]][coo[1]] = suivants[0]
                key['rel'] = False
                piece(coo[0], coo[1], PIECES[suivants.pop(0)], COLORS[0])
                suivants.append(choice(range(7)))
                infos()
        else: key['rel'] = True
        if monotonic() - eau['tps'] > eau['delai']:
          if eau['delai'] == EAU_DEP: eau['delai'] = 1
          eau['tps'] = monotonic()
          if not(eau['av']):
            dx, dy = dx + SENS[dep][0], dy + SENS[dep][1]
            if 0 <= dx <= 9 and 0 <= dy < 7:
              vg = grid[dx][dy] % 100
              dist = max(dist - 1, 0)
              if 0 <= vg < 7:
                t = PIECES[vg]
                grid[dx][dy] = vg + 100
                d = 'gdbh'[dep]
                if d in t:
                  if len(t) == 4: t = d + inv(d)
                  elif d != t[0]: t = ''.join(list(reversed(t)))
                  etape = 0
                  eau['av'] = True
                  change_score(50)
                  (u,v) = CASES[t[0]]         
                  remplir(dx, dy, u, v)
                else: run = 0
              else: run = 0  
            else: run = 0    
          else:
            etape += 1
            change_score(50)
            if etape == 1:
              remplir(dx, dy, 1, 1)
            else:
              (u,v) = CASES[t[1]]         
              remplir(dx, dy, u, v)
            if etape == 2:
              dep = 'dghb'.index(t[1])
              eau['av'] = False
    if dist == 0:
      change_score(1000)
      dt('TOUCHE OK', 100, 85)
    else:
      game = 0
      dt('GAME OVER', 100, 85)
    while not(keydown(KEY_OK)): continue

go()

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.