memory.py

Created by cent20

Created on December 19, 2024

3.2 KB


from ion import keydown
from kandinsky import *
from random import randint as r
from time import sleep

"""
for x in range(0,8,1):
    for y in range(0,4,1):
        fill_rect(5+x*40,5+y*50,28,42,"#ee0042")"""
        
# draw_string("As", 49, 18,"#ffffff","#ee0042")

carte = ["As", "R", "D", "V", "10","9","8","7"]
"""
x = 10
for txt in carte:
    draw_string(txt, x, 50,"#ffffff","#ee0042")
    x += 50"""

position = [1,1]
pulled = ["", ""]
score = [0,0]

def wait(keys=(0,1,2,3,4,52)):  # input keyboard
    while True:
        for k in keys:
            if keydown(k):
                while keydown(k): True  # Fonction anti-rebond
                return k

def affiche(x,y,t,c):
    draw_string(t, 5+28*x+12*x+10, 5+42*y+8*y+15,"#ffffff",c)


draw_string("Joueur 1 :", 5, 200)
draw_string("Joueur 2 :", 180, 200)


jeux = ["AR", "RR", "DR", "VR", "XR","9R","8R","7R","AN", "RN", "DN", "VN", "XN","9N","8N","7N"]

jeux = jeux +jeux 

carte = [[0 for x in range(8)] for y in range(4)]


# shuffle n'existe pas donc on va devoir réécrire le code ci dessous...
# shuffle(jeux)

def refresh():
    for y in range(4):
        for x in range(8):
            if carte[y][x][1] == "N":
                col = (0,0,0)
            else:
                col = (255,0,0)
            fill_rect(5+x*40,5+y*50,28,42,col)
            affiche(x,y,carte[y][x][0], col)

i = 0
for y in range(4):
    for x in range(8):
        carte[y][x] = jeux[i]
        i += 1
        
print(carte)

def shuffle():
    for _ in range(1000):
        y0, x0, y1,x1 = r(0,3), r(0,7), r(0,3), r(0,7)
        carte[y0][x0], carte[y1][x1] = carte[y1][x1], carte[y0][x0]

def deal():
    for x in range(0,8,1):
        for y in range(0,4,1):
            fill_rect(5+x*40,5+y*50,28,42,(148, 113,222))

def select():
    fill_rect(5+position[0]*40,5+position[1]*50,28,42,(255,183,52))

def unselect():
    fill_rect(5+position[0]*40,5+position[1]*50,28,42,(148, 113,222))

deal()

shuffle()     
# refresh()

print(carte)
select()

def show(x,y):
    if carte[y][x][1] == "N":
        col = (0,0,0)
    else:
         col = (255,0,0)
    fill_rect(5+x*40,5+y*50,28,42,col)
    draw_string(carte[y][x][0], 5+28*x+12*x+10, 5+42*y+8*y+15,"#ffffff",col)

def pull():
    if pulled[0] =="":
        pulled[0] = carte[position[1]][position[0]]
        print(pulled)
    elif pulled[0] !="":
        pulled[1] = carte[position[1]][position[0]]
        if pulled[0] == pulled[1]:
            score[0] = score[0] + 1
            draw_string("Joueur 1 :"+str( score[0]), 5, 200)
            draw_string("Joueur 2 :"+str( score[1]), 180, 200)
        else:
            pulled[0] = ""
            pulled[1] = ""

while True:
    k = wait()
    print(k)
    unselect()
    if k == 3:        
        #position[0] = min(position[0] + 1,7)
        position[0] = (position[0] + 1)%8
    elif k == 0:
        #position[0] = max(position[0] - 1,0)
        position[0] = (position[0] - 1)%8
    elif k == 1:
        #position[1] = max(position[1] - 1,0)
        position[1] = (position[1] - 1)%4
    elif k == 2:
        #position[1] = min(position[1] + 1,3)
        position[1] = (position[1] + 1)%4
    select()
    if k == 4 or k == 52:
        show(position[0], position[1])
        pull()

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.