themap_avec_gemme.py

Created by vgalletramond

Created on January 07, 2025

11 KB


from kandinsky import fill_rect as f_r,draw_string as d_s
from random import randint as rd
from ion import keydown as kd
from time import sleep as sl


col=('white','white','green','green','green','red','red','#FFD700')
zombie = {"PV":30,"AT":13,"DEF":1}
squelette = {"PV":35,"AT":15,"DEF":3}
araigne = {"PV":50,"AT":20,"DEF":4}
gobelin = {"PV":40,"AT":25,"DEF":2}
blob = {"PV":90,"AT":12,"DEF":7}
shadow = {"PV":70,"AT":42,"DEF":4}
hydre = {"PV":200,"AT":60,"DEF":20}
en = ((zombie,'Zombie'),(squelette,'Squelette'),(araigne,'Araignée'),(gobelin,'Gobelin'),(blob,'Blob'),(shadow,'Shadow'),(hydre,'Hydre'))

def event(n_e):
    if n_e == 2:
        a_s_h(2,0)
        modif = rd(10,30-8*(n//10)*(4*(n//5)>12)+12*(30-4*(n//5)<12))
        h["PV"] += modif
    elif n_e == 3:
        h["AT"] += 5
        modif = 5
    elif n_e == 4:
        h["DEF"] += 2
        modif = 2
    elif n_e == 5:
        modif = rd(10,15+5*(n//5))-h["DEF"]
        h["PV"] -= modif
        h["PV"] *= (h["PV"]>0)
        if h["PV"] <= 0:
            a_s_h(n_e,0,modif)
            sl(1)
            init_jeu()
    elif n_e == 6:
        a_s_h(n_e)
        combat(en[rd(0,1+(n//4)*(n<24)+5*(n>=24))])
        modif = 0
    elif n_e == 7:
        global n_g
        n_g+=1
        modif=0
    elif n_e == 0:
        modif = 0
    a_s_h(n_e*(n_e!=6),0,modif)
    return

def combat(m_i):
    e_c = 1
    a_s_h(0,e_c,0,m_i[0],m_i[1])
    sl(1)
    while e_c == 1:
        m_i[0]["PV"] -= h["AT"]-m_i[0]["DEF"]
        m_i[0]["PV"]*=(m_i[0]["PV"]>0)
        a_s_h(0,e_c,0,m_i[0],m_i[1])
        sl(1)
        if m_i[0]["PV"] <= 0:
            e_c = 0
            return 
        h["PV"] -= m_i[0]["AT"]-h["DEF"]
        h["PV"]*=(h["PV"]>0)
        a_s_h(0,e_c,0,m_i[0],m_i[1])
        sl(1)
        if h["PV"] <= 0:
            e_c = 0
            sl(1)
            return init_jeu()



def jeu():
    f_r(0,0,320,222,'black')
    for i in range(t_p):
        for j in range(t_p*2):
            red=(18+int((144-2)/t_p+1)*j,10+int((144-2)/t_p+1)*i,int((144-2)/t_p),int((144-2)/t_p))
            if g[i][j] == 'P':
                f_r(red[0],red[1],red[2],red[3],'gray')
                d_c(red[0],red[1],red[2])
            else:
                f_r(red[0],red[1],red[2],red[3],'white')
                d_q_m(red[0],red[1],red[2])
    a_g()
    a_g2()
    a_s_h()
    barre_bas()
    
        

def a_g(ori=[0,0]):
    for char in range(len(g)):
        for pers in range(len(g[char])):
            if g[char][pers] == 'P':
                g[char][pers] = 1
            elif g[char][pers] == 'P0':
                g[char][pers] = 0
    eve = g[h["pos"][1]][h["pos"][0]]
    if g[h["pos"][1]][h["pos"][0]] != 0:
        g[h["pos"][1]][h["pos"][0]] = 'P'
    else:
        g[h["pos"][1]][h["pos"][0]] = 'P0'
    f_r(18+int((144-2)/t_p+1)*ori[0],10+int((144-2)/t_p+1)*ori[1],int((144-2)/t_p),int((144-2)/t_p),'white')
    if g[ori[1]][ori[0]] == 0:
        f_t["0"](18+int((144-2)/t_p+1)*ori[0]+9*(t_p==3)+7*(t_p==4)+5*(t_p==5)+3*(t_p==6),10+int((144-2)/t_p+1)*ori[1]+9*(t_p==3)+7*(t_p==4)+5*(t_p==5)+3*(t_p==6),30*(t_p==3)+21*(t_p==4)+18*(t_p==5)+18*(t_p==6))
    f_r(18+int((144-2)/t_p+1)*h["pos"][0],10+int((144-2)/t_p+1)*h["pos"][1],int((144-2)/t_p),int((144-2)/t_p),'gray')
    d_c(18+int((144-2)/t_p+1)*h["pos"][0]+9*(t_p==3)+7*(t_p==4)+5*(t_p==5)+3*(t_p==6),10+int((144-2)/t_p+1)*h["pos"][1]+9*(t_p==3)+7*(t_p==4)+5*(t_p==5)+3*(t_p==6),30*(t_p==3)+21*(t_p==4)+18*(t_p==5)+18*(t_p==6))
    return eve

def a_g2():
    for j in range(0,t_p*2):
        for i in range(0+1*(j%2!=0),t_p,2):
            if not(j==0 and i==0):
                comp=(18+int((144-2)/t_p+1)*j,10+int((144-2)/t_p+1)*i,int((144-2)/t_p),int((144-2)/t_p))
                comp2=(18+int((144-2)/t_p+1)*j+9*(t_p==3)+7*(t_p==4)+5*(t_p==5)+3*(t_p==6),10+int((144-2)/t_p+1)*i+9*(t_p==3)+7*(t_p==4)+5*(t_p==5)+3*(t_p==6),30*(t_p==3)+21*(t_p==4)+18*(t_p==5)+18*(t_p==6))
                f_r(comp[0],comp[1],comp[2],comp[3],col[int(g[i][j])])
                if g[i][j] != 1:
                    f_t[str(g[i][j])](comp2[0],comp2[1],comp2[2])
                

def pixel_heart(x,y,t):
    for j in range(9):
        for i in range((j==0)+(j==3)+(j==4)*2+(j==5)+(j==8),4+1*((j==1)+(j==7))+2*((j==2)+(j==6))+3*((j==3)+(j==5))+4*(j==4)):
            f_r(x+int(t/9)*j+int(1/2*((t+5)/9)),y+int(t/9)*i+int(1/2*((t+15)/7)),int(t/9),int(t/9),'red')

def draw_cross(x,y,t):
    for j in range(5):
        for i in range(((j==1)+(j==3))+((j==2)+(j==5))*2,5,4*((j==0)+(j==4))+2*((j==1)+(j==3))+3*(j==2)):
            f_r(x+int(t/5)*j,y+int(t/5)*i,int(t/5),int(t/5),'red')

def draw_sword(x,y,t):
    for j in range(7):
        for i in range(6*(j==0)+3*((j==1)+(j==2))+2*(j==3)+1*(j==4),7-2*(j==2)-1*(j==3)-3*(j==4)-4*(j==5)-5*(j==6),1+1*(j==1)):
            f_r(x+int(t/7)*j,y+int(t/7)*i,int(t/7),int(t/7),'gray')

def draw_sword_m(x,y,t):
    for j in range(7):
        for i in range(6*(j==6)+3*((j==5)+(j==4))+2*(j==3)+1*(j==2),7-2*(j==4)-1*(j==3)-3*(j==2)-4*(j==1)-5*(j==0),1+1*(j==5)):
            f_r(x+int(t/7)*j,y+int(t/7)*i,int(t/7),int(t/7),'gray')

def draw_spike(x,y,t):
    for j in range(5):
        for i in range(3*((j==0)+(j==4))+1*((j==1)+(j==3)),4):
            f_r(x+int(t/5)*j,y+int(t/5)*i+int(1/2*(t/5)),int(t/5),int(t/5),'gray')

def draw_shield(x,y,t):
    for j in range(5):
        for i in range(6-2*((j==0)+(j==4))-1*((j==1)+(j==3))):
            f_r(x+int(t/6)*j+int(1/2*(t/6)),y+int(t/6)*i,int(t/6),int(t/6),'#7C3626')

def d_c(x,y,t):
    for j in range(5):
        for i in range(5*((j==0)+(j==4)),6*((j==0)+(j==4))+7*(j==2)+1*((j==1)+(j==3))):
            if (j==1)+(j==3):
                for k in range(3):
                    f_r(x+int(t/9)*j+int(2*(t/9)),y+int(t/9)*k,int(t/9),int(t/9),'black')
                f_r(x+int(t/9)*j+int(2*(t/9)),y+int(t/9)*4,int(t/9),int(t/9),'black')
                for k in range(2):
                    f_r(x+int(t/9)*j+int(2*(t/9)),y+int(t/9)*(k+7),int(t/9),int(t/9),'black')
                break
            else:
                f_r(x+int(t/9)*j+int(2*(t/9)),y+int(t/9)*i,int(t/9),int(t/9),'black')


def d_q_m(x,y,t):
    for j in range(5):
        for i in range(1*((j==0)+(j==4)),1*((j==2)+(j==1))+3*((j==0)+(j==4))+4*(j==3),1*(j!=3)+3*(j==3)):
            if (j==2):
                f_r(x+int(t/8)*j+int(1.9*(t/8)),y+int(t/8),int(t/8),int(t/8),'black')
                for k in range(2):
                    f_r(x+int(t/8)*j+int(1.9*(t/8)),y+int(t/8)*(k+4)+int(t/8),int(t/8),int(t/8),'black')
                f_r(x+int(t/8)*j+int(1.9*(t/8)),y+int(t/8)*7+int(t/8),int(t/8),int(t/8),'black')
                break
            else:
               f_r(x+int(t/8)*j+int(1.9*(t/8)),y+int(t/8)*i+int(t/8),int(t/8),int(t/8),'black')

def d_g(x,y,t):
    for j in range(5):
        for i in range(2*(j==0 or j==4)+1*(j==1 or j==3),5-2*(j==0 or j==4)-1*(j==1 or j==3)):
            f_r(x+int(t/5)*j,y+int(t/5)*i,int(t/5),int(t/5),'#46A2DA')
      
def barre_bas():
    f_r(0, 200, 320, 22, (148, 113, 222))
    d_s( "nsi.xyz/themap", 2, 202, (242,)*3, (148, 113,222))
    d_s("N:"+str(n), 155, 202, (242,)*3, (148, 113,222))
    d_s("Gemme:"+str(n_g)+'/1',205,202,(242,)*3, (148, 113,222))

#inspiré de nsi.xyz/escape
#a compacté comme nsi.xyz/escape
def a_s_h(n_e=0,e_c=0,modif=0,m='',n_m=''):
    f_r(0, 179, 320, 20, 'black')
    d_s("Heros",5,160,'white','black')
    txt=[]
    txt.append(str(int(h["PV"])))
    txt.append(str(int(h["AT"])))
    txt.append(str(int(h["DEF"])))
    d_s(txt[0],5, 180,(242,)*3, 'black')
    pixel_heart(7+10*len(txt[0]),180,18)
    d_s(txt[1],30+10*len(txt[0]), 180,(242,)*3, 'black')
    draw_sword(32+10*(len(txt[0])+len(txt[1])),180,18)
    d_s(txt[2],50+10*(len(txt[0])+len(txt[1])), 180,(242,)*3, 'black')
    draw_shield(52+10*(len(txt[0])+len(txt[1])+len(txt[2])),180,18)
    if n_e != 0 and n_e != 1:
        f_t[str(n_e)](151,180,18)
    if n_e == 2 or n_e == 3 or n_e == 4:
        d_s('+'+str(modif),200,180,(242,)*3, 'black')
        f_t[str(n_e)](215+10*len(str(modif)),180,18)
    elif n_e == 5:
        d_s('-'+str(modif),200,180,(242,)*3, 'black')
        f_t["2"](215+10*len(str(modif)),180,18)
    elif n_e == 7:
        d_s('+1',200,180,(242,)*3, 'black')
        f_t["7"](215+10,180,18)
    if e_c == 1:
        f_t["6"](151,180,18)
        d_s(str(n_m),225,160,'white','black')
        txt=[]
        txt.append(str(m["PV"]))
        txt.append(str(m["AT"]))
        txt.append(str(m["DEF"]))
        d_s(txt[0],175, 180,(242,)*3, 'black')
        pixel_heart(177+10*len(txt[0]),180,18)
        d_s(txt[1],200+10*len(txt[0]), 180,(242,)*3, 'black')
        draw_sword(202+10*(len(txt[0])+len(txt[1])),180,18)
        d_s(txt[2],220+10*(len(txt[0])+len(txt[1])), 180,(242,)*3, 'black')
        draw_shield(222+10*(len(txt[0])+len(txt[1])+len(txt[2])),180,18)
    elif e_c == 0:
        f_r(225, 160, 95, 19,'black')
        m=[hydre,shadow,blob,araigne,gobelin,squelette,zombie]
        for i in range(len(m)):
            m[i]["PV"] = 200*(i==0)+70*(i==1)+90*(i==2)+40*(i==3)+50*(i==4)+35*(i==5)+30*(i==6)
    d_s("Gemme:"+str(n_g)+'/1',205,202,(242,)*3, (148, 113,222))
        

def init_jeu():
    global t_p,g,h,n_g
    n_g = 0
    t_p = (3+n//(4+n//7)*(n<32)+3*(n>=32))
    g = [[rd(0,1) for i in range(t_p*2)] for j in range(t_p)]
    for i in range(t_p):
        for j in range(t_p*2):
            if g[i][j] == 0:
                g[i][j] = rd(1,4)
            else:
                g[i][j] = rd(5,6)
    g[rd(t_p-2,t_p-1)][rd(t_p*2-2,t_p*2-1)] = 0
    g[0][0] = 'P'
    while True:
        x,y=rd(1,t_p*2-1),rd(1,t_p-1)
        if g[y][x] != 0:
            g[y][x] = 7
            break
    h = {"PV":int(75+5*(n//4)),"AT":int(15+2*(n//5)),"DEF":int(0+1*(n//5)),"pos":[0,0]}
    return jeu()

f_t = {'P':d_c,'0':draw_cross,'2':pixel_heart,'3':draw_sword,'4':draw_shield,'5':draw_spike,'6':draw_sword_m,'7':d_g}
n = 1
init_jeu()
while True:
    sl(0.5)
    stop = 0
    while stop == 0:
        orig=[h["pos"][0],h["pos"][1]]
        if kd(2):
            stop = 1
            h["pos"][1] += 1*(h["pos"][1]+1<t_p)
            eve = a_g(orig)
            if eve == 0 and n_g == 1:
                n += 1
                init_jeu()
            elif eve !=1:
                event(eve)
            stop = 0
            sl(0.4)
        elif kd(3):
            stop = 1
            h["pos"][0] += 1*(h["pos"][0]+1<t_p*2)
            eve = a_g(orig)
            if eve == 0 and n_g == 1:
                n += 1
                init_jeu()
            elif eve !=1:
                event(eve)
            stop = 0
            sl(0.4)
        elif kd(1):
            stop = 1
            h["pos"][1] -= 1*(h["pos"][1]-1>=0)
            eve = a_g(orig)
            if eve == 0 and n_g == 1:
                n += 1
                init_jeu()
            elif eve !=1:
                event(eve)
            stop = 0
            sl(0.4)
        elif kd(0):
            stop = 1
            h["pos"][0] -= 1*(h["pos"][0]-1>=0)
            eve = a_g(orig)
            if eve == 0 and n_g == 1:
                n += 1
                init_jeu()
            elif eve !=1:
                event(eve)
            stop = 0
            sl(0.4)

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.