donky_kong.py

Created by marius-layan

Created on February 05, 2024

3.56 KB

Voici une reconstitution du jeu Donky Kong. Le but est simple: il faut éviter les tonneaux en sautant par dessus et arriver tout en haut. chaque tonneaux lancé par Donky Kong rapporte 50 points en plus, chaque fin de partie rapporte 1000 points.

pour se déplacer: [LEFT] , [RIGHT] ou [UP]

BON JEU !


from random import *
from kandinsky import *
from ion import *
from time import *
lader,p,p1,a,f,g,score=(0,140,104),[[175,25],[100,85],[235,55],[210,115],[70,145],[225,175]],[[40,200,240],[40,170,210],[70,140,210],[40,110,210],[70,80,210],[40,50,210],[130,20,60]],5,(183,28,28),(255,204,128),50
def laders():
  global a
  for i in range(6):
    fill_rect(p[i][0],p[i][1],15,25,lader)
    for j in range(4):
      if j==3:a=1
      fill_rect(p[i][0]+3,p[i][1]+j*8,9,a,(8,8,8))
      a=5
def stairs():
  for i in range(7):fill_rect(p1[i][0],p1[i][1],p1[i][2],5,'red')
while True:
  fill_rect(0,0,320,222,'black')
  laders()
  stairs()
  t,e,x,y,c=[[70,40]],0,50,190,0
  fill_rect(45,25,20,20,f);fill_rect(43,30,24,10,f);fill_rect(45,45,4,2,g);fill_rect(61,45,4,2,g);fill_rect(42,47,7,3,g);fill_rect(61,47,7,3,g);fill_rect(50,20,10,10,g);fill_rect(50,28,2,2,f);fill_rect(58,28,2,2,f);fill_rect(52,27,6,1,f);fill_rect(54,25,2,1,f);fill_rect(52,19,6,1,f);fill_rect(50,20,10,2,f);fill_rect(50,22,2,2,f);fill_rect(58,22,2,2,f);fill_rect(53,22,4,2,'white');fill_rect(54,23,1,1,f);fill_rect(56,23,1,1,f);fill_rect(50,35,10,10,'orange');fill_rect(51,35,1,10,'blue');fill_rect(58,35,1,10,'blue')
  while True:
    if get_pixel(x,y+10)==(0,0,0) and get_pixel(x+7,y+10)==(0,0,0):fill_rect(x,y,8,2,'black');y+=2
    laders();stairs()
    if c>0 or c==-9:fill_rect(x,z,8,10,'black')
    fill_rect(x,y,8,10,'blue')
    if keydown(KEY_UP) and (((get_pixel(x,y-1)==(0,140,104) or get_pixel(x,y-1)==(8,8,8)) and (get_pixel(x+8,y-1)==(0,140,104) or get_pixel(x+8,y-1)==(8,8,8))) or ((get_pixel(x,y+14)==(0,140,104) or get_pixel(x,y+14)==(8,8,8)) and (get_pixel(x+8,y+14)==(0,140,104) or get_pixel(x+8,y+14)==(8,8,8)))):y-=1
    elif keydown(KEY_RIGHT) and x<272 and get_pixel(x+4,y+14)!=(0,140,104) and get_pixel(x+4,y+14)!=(8,8,8):x+=1;fill_rect(x-1,y,1,10,'black')
    elif keydown(KEY_LEFT) and 40<x and get_pixel(x+4,y+14)!=(0,140,104) and get_pixel(x+4,y+14)!=(8,8,8):x-=1;fill_rect(x+8,y,1,10,'black')
    if keydown(KEY_UP) and c==0 and (get_pixel(x,y-1)==(0,0,0) and get_pixel(x+8,y-1)==(0,0,0)) and (get_pixel(x,y+10)==(248,0,0) or get_pixel(x+7,y+10)==(248,0,0)):c,d=1,y
    if c>0:
      z=y
      y=int(0.15*c**(2)-3*c+d)
      c+=1
      if get_pixel(x,y+10)==(248,0,0) or get_pixel(x+7,y+10)==(248,0,0) or c==21:c=-10
    if c<0:c+=1
    if randint(0,50)==0:
      if t[len(t)-1][1]!=40 or t[len(t)-1][0]>150:t.append([70,40]);score+=50
    if t[len(t)-1][1]==230:del t[len(t)-1]
    for i in range(len(t)):
      fill_rect(t[i][0],t[i][1],10,10,'black')
      if get_pixel(t[i][0],t[i][1]+10)==(0,0,0) and get_pixel(t[i][0]+9,t[i][1]+10)==(0,0,0):t[i][1]+=2
      if t[i][1]==40 or t[i][1]==100 or t[i][1]==160:t[i][0]+=2
      if t[i][1]==70 or t[i][1]==130 or t[i][1]==190:t[i][0]-=2
      fill_rect(t[i][0],t[i][1],10,10,'orange');fill_rect(t[i][0]+1,t[i][1],1,10,'blue');fill_rect(t[i][0]+8,t[i][1],1,10,'blue')
      if (t[i][1]<=y-1<t[i][1]+10 and t[i][0]<=x<t[i][0]+10) or (t[i][1]<=y+9<t[i][1]+10 and t[i][0]<=x<t[i][0]+10) or (t[i][1]<=y-1<t[i][1]+10 and t[i][0]<=x+7<t[i][0]+10) or (t[i][1]<=y+9<t[i][1]+10 and t[i][0]<=x+7<t[i][0]+10):e=1;break
    draw_string(str(score),5,0,'white','black')
    if e==1:break
    if y==10:e=2;break
    sleep(0.02)
  while e==2:draw_string("YOU WIN",210,15,'white','black');sleep(0.5);e=0;score+=1000;break
  while e==1:
    for j in range(8):
      for i in range(8):fill_rect(i*40,j*40,40,40,'black');sleep(0.01)
    for i in range(255):draw_string("GAME OVER",110,60,(i,0,0),'black');draw_string("Score: "+str(score),5,200,(i,i,0),'black');sleep(0.003)
    break
  if e==1:break