drapeaux.py

Created by schraf

Created on February 14, 2023

2.04 KB

Jeu des drapeaux
Tapez sur la touche Ans pour répondre puis tapez le numéro du pays et Ans. Pour avoir un autre drapeau, tapez sur la touche +


from kandinsky import *
from random import *
from ion import *

b,bl,r,n,j,v = color(0,0,255),color(255,255,255),color(255,0,0),color(0,0,0),color(255,235,59),color(80,175,80)
dr =[["FRA",b,0,0,1,2,bl,1,0,2,2,r,2,0,3,2],\
    ["PAYS BAS",r,0,0,9,2,bl,0,2,9,4,b,0,4,9,6],\
    ["BELG",n,0,0,1,2,j,1,0,2,2,r,2,0,3,2],\
    ["ALL",n,0,0,5,1,r,0,1,5,2,j,0,2,5,3],\
    ["MALI",v,0,0,1,2,j,1,0,2,2,r,2,0,3,2],\
    ["ITAL",v,0,0,1,2,bl,1,0,2,2,r,2,0,3,2],\
    ["FINL",b,5,0,8,11,b,0,4,18,7],\
    ["SUED",b,0,0,16,10,j,5,0,7,10,j,0,4,16,6],\
    ["HONG",r,0,0,6,1,bl,0,1,6,2,v,0,2,6,3],\
    ["BULG",v,0,1,5,2,r,0,2,5,3],\
    ["ISL",b,0,0,25,18,bl,7,0,11,18,bl,0,7,25,11,r,8,0,10,18,r,0,8,25,10],\
    ["COLOMB",j,0,0,6,2,b,0,2,6,3,r,0,3,6,4],\
    ["THAI",r,0,0,9,1,b,0,2,9,4,r,0,5,9,6],\
    ["COSTA",b,0,0,9,1,r,0,2,9,4,b,0,5,9,6],\
    ["BOLIV",r,0,0,22,5,j,0,5,22,10,v,0,10,22,15],\
    ["MAUR",r,0,0,6,1,b,0,1,6,2,j,0,2,6,3,v,0,3,6,4]]

def ech(x,t,s):
  return int(t*x/s)

def dessin(x0,y0,t,g,xmax,ymax):
  s = max(xmax,ymax)
  fill_rect(x0,y0,t+1,t+1,bl)
  for i in range(len(g)//5):
    x = ech(g[5*i+1],t,s)
    y = ech(g[5*i+2],t,s)
    l = ech(g[5*i+3],t,s)-x
    h = ech(g[5*i+4],t,s)-y
    fill_rect(x0+x,y0+y,l,h,g[5*i])
  fill_rect(x0,y0,ech(xmax,t,s),1,n)  
  fill_rect(x0,y0+ech(ymax,t,s),ech(xmax,t,s),1,n)
  fill_rect(x0,y0,1,ech(ymax,t,s),n)  
  fill_rect(x0+ech(xmax,t,s),y0,1,ech(ymax,t,s),n)

def pause(k):
  while not(keydown(k)):continue

def jeu():
  while True:
    d = choice(dr)
    s,n,g = 0,d[0],d[1:]
    xmax,ymax = 0,0
    fill_rect(0,0,320,222,(255,)*3)
    for i,v in enumerate(g):
      if i%5 == 3: xmax=max(xmax,v)
      elif i%5 == 4: ymax=max(ymax,v)
    dessin(10,30,100,g,xmax,ymax)
    for i,d in enumerate(dr):
      if n == d[0]: ga = i
      draw_string(str(i+1)+" > "+d[0],150,14*i-2)
    pause(KEY_ANS)  
    ch = int(input())
    if ga == ch-1:
      draw_string("GAGNE !",10, 140)
    else:
      draw_string("PERDU !",10, 140)
    draw_string(n+"   ",10, 180) 
    dessin(140,170,50,g,xmax,ymax)
    pause(KEY_PLUS)

jeu()