test_jeu.py

Created by kmaulet5

Created on December 13, 2024

3.68 KB


from ion import keydown
from kandinsky import *
from random import randint
from time import sleep
liste_cartes = 0
txt = "Carte du Joueur:"
fill_rect(0,0,320,222,"#000000")
draw_string(txt, 42, 200,"#FFFFFF","#000000")
fill_rect(202,198,35,25,"#FFFFFF")
fill_rect(242,198,35,25,"#FFFFFF")
def sol_grotte(x,y): #is 1
    fill_rect(x*18,1+y*18,15,15,"#784212")
def herbe(x,y): #is 2
    fill_rect(x*18,1+y*18,15,15,"#609B41")
def rocher_dehors(x,y): #is 3
    fill_rect(x*18,1+y*18,15,15,"#424949")
def rocher_grotte(x,y):#is 4
    fill_rect(x*18,1+y*18,15,15,"#641E16")
def eau_dehors(x,y):#is 5
    fill_rect(x*18,1+y*18,15,15,"#0000FF")
def eau_grotte(x,y):#is 6
    fill_rect(x*18,1+y*18,15,15,"#403AAF")
matrice_x =[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]
matrice_y =[0,1,2,3,4,5,6,7,8,9,10]
corrdone = [3,2]
def font_ecran_generer(tab):
    for i in range(11):
        for v in range(18):
            if tab[i][v] == 1:
                sol_grotte(matrice_x[v],matrice_y[i])
            elif tab[i][v] == 2:
                herbe(matrice_x[v],matrice_y[i])
            elif tab[i][v] == 3:
                rocher_dehors(matrice_x[v],matrice_y[i])
            elif tab[i][v] == 4:
                rocher_grotte(matrice_x[v],matrice_y[i])
            elif tab[i][v] == 5:
                eau_dehors(matrice_x[v],matrice_y[i])
            elif tab[i][v] == 6:
                eau_grotte(matrice_x[v],matrice_y[i])
def joeur(tab):
        fill_rect(tab[0]*18,1+tab[1]*18,15,15,"#C70039")
        
carte_appa = [[3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4],
         [3,2,2,2,2,2,2,2,2,2,2,2,2,4,1,1,1,4],
         [3,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,4],
         [3,2,2,2,2,2,2,2,2,2,2,2,2,4,1,1,1,4],
         [3,2,2,2,2,2,2,2,2,2,2,2,2,4,1,1,1,4],
         [3,3,3,5,5,3,3,3,3,3,3,3,3,4,4,1,4,4],
         [3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,3],
         [3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,3],
         [3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,3],
         [3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,3],
         [3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3]]

carte_mouv = [[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
         [0,2,2,2,2,2,2,2,2,2,2,2,2,0,1,1,1,0],
         [0,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,0],
         [0,2,2,2,2,2,2,2,2,2,2,2,2,0,1,1,1,0],
         [0,2,2,2,2,2,2,2,2,2,2,2,2,0,1,1,1,0],
         [0,0,0,5,5,0,0,0,0,0,0,0,0,0,0,1,0,0],
         [0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0],
         [0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0],
         [0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0],
         [0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0],
         [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]
         
def mouvement(matrice_j):
    global corrdone,zone
    # Déplacement gauche
    if keydown(0) :
        if carte_mouv[corrdone[0]-1][corrdone[1]] != 0:
            corrdone[0] = corrdone[0] -1
            font_ecran_generer(carte_appa)
            joeur(corrdone)
             
    # Déplacement droite
    elif keydown(3):
     if carte_mouv[corrdone[0]+1][corrdone[1]] != 0:
            corrdone[0] = corrdone[0] +1
            font_ecran_generer(carte_appa)
            joeur(corrdone)             
        

    # Déplacement haut
    elif keydown(1) :
         if carte_mouv[corrdone[0]][corrdone[1]-1] != 0:
            corrdone[1] = corrdone[1] -1
            font_ecran_generer(carte_appa)
            joeur(corrdone)

             
    # Déplacement bas
    elif keydown(2) :
         if carte_mouv[corrdone[0]][corrdone[1]+1] != 0:
            corrdone[1] = corrdone[1] +1
            font_ecran_generer(carte_appa)
            joeur(corrdone)
             
    joeur(corrdone)
def jeu():
    font_ecran_generer(carte_appa)
    while liste_cartes == 0 or liste_cartes == 1:
        joeur(corrdone)
        mouvement(carte_mouv)
        sleep(0.173)
jeu()

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.