les_agents_secrets.py

Created by dan-tabet

Created on January 13, 2025

7.17 KB


from math import *
from kandinsky import *
from random import *
from time import monotonic, sleep
from ion import *
texte = "Vous êtes le président \n de la C.I.A.\n Des documents confidentiels \n ont été volés,\n votre mission,\n si toutefois vous l'acceptez,\n est d'envoyer vos agents \n a travers le monde \n afin de re mettre la main \n sur ces 10 documents. \n \n Attention, il faut etre rapide !\n Vous avez environ 3 sec pour \n deplacez a l'aide des flèches \n le pointeur afin de viser \n les villes ciblées "
y_position = 320
reponse = input("vous etes sur calculatrice ou sur emulateur ? \n ")
if reponse == "calculatrice":
  vitesse = 1
else : 
  vitesse = 3
couleur_texte = color(0, 128, 0)
point = 0
temps_a_faire = 3
emplacement_villes = {
    "Paris": (143, 45), "New York": (80, 60), "Mexico": (60, 95), "Moscou": (170, 43),
    "Tokyo": (265, 60), "Vancouver": (40, 50), "Mumbai": (213, 95), "Buenos Aires": (93, 160),
    "Lagos": (143, 107), "Johannesburg": (168, 145)
}
amerique = [(27, 18, 15, 37), (15, 37, 36, 35), (36, 35, 37, 80), (37, 80, 66, 105),
            (66, 105, 62, 123), (62, 123, 85, 195), (85, 195, 107, 125), (107, 125, 70, 100),
            (70, 100, 50, 77), (50, 77, 67, 75), (67, 75, 95, 40), (95, 40, 85, 19),
            (85, 19, 28, 18)]
ile1 = [(62, 79, 70, 79), (70, 79, 69, 88), (69, 88, 62, 88), (62, 88, 62, 79)]
ile2 = [(71, 83, 77, 83), (77, 83, 77, 90), (77, 90, 71, 90), (71, 90, 71, 83)]
angleterre = [(137, 31, 142, 42), (142, 42, 135, 45), (135, 45, 137, 31)]
grand_continent = [(205, 9, 162, 17), (162, 17, 137, 47), (137, 47, 139, 52),
                   (139, 52, 132, 52), (132, 52, 130, 60), (130, 60, 135, 62), (135, 62, 125, 95),
                   (125, 95, 132, 109), (132, 109, 150, 110), (150, 110, 160, 165),
                   (160, 165, 178, 138), (178, 138, 187, 98), (187, 98, 180, 100),
                   (180, 100, 170, 72), (170, 72, 152, 68), (152, 68, 150, 65),
                   (150, 65, 137, 63), (137, 63, 150, 52), (150, 52, 155, 62),
                   (155, 62, 160, 55), (160, 55, 163, 63), (163, 63, 164, 58),
                   (164, 58, 169, 57), (169, 57, 168, 63), (168, 63, 173, 65),
                   (173, 65, 173, 70), (173, 70, 185, 95), (185, 95, 195, 85),
                   (195, 85, 183, 73), (183, 73, 207, 84), (207, 84, 212, 107),
                   (212, 107, 225, 84), (225, 84, 239, 127), (239, 127, 258, 130),
                   (258, 130, 240, 120), (240, 120, 235, 97), (235, 97, 240, 104),
                   (240, 104, 240, 84), (240, 84, 251, 75), (251, 75, 247, 59),
                   (247, 59, 256, 67), (256, 67, 254, 56), (254, 56, 276, 20),
                   (276, 20, 205, 9)]
japon = [(267, 50, 273, 63), (273, 63, 265, 70), (265, 70, 258, 66), (258, 66, 267, 50)]
oceanie = [(245, 148, 244, 169), (244, 169, 270, 170), (270, 170, 285, 144),
           (285, 144, 278, 132), (278, 132, 275, 140), (275, 140, 268, 133), (268, 133, 245, 148)]

def afficher_texte_deroulant(texte, y_position, vitesse):
    nombre_de_lignes = texte.count('\n') + 1
    hauteur_texte = nombre_de_lignes * 20
    
    while y_position > -hauteur_texte:
        fill_rect(0, 0, 320, 222, color(0, 0, 0))
        draw_string(texte, 10, y_position, couleur_texte, color(0, 0, 0))
        y_position -= vitesse
        sleep(0.03)
        if keydown(2) :
          break

def draw_line(x1, y1, x2, y2, c):
    width = x2 - x1
    height = y2 - y1
    if abs(width) >= abs(height):
        div = height / width
        for i in range(0, width, (width > 0) * 2 - 1):
            set_pixel(x1 + i, y1 + int(div * i + 0.5), c)
    else:
        div = width / height
        for i in range(0, height, (height > 0) * 2 - 1):
            set_pixel(x1 + int(div * i + 0.5), y1 + i, c)

def draw_circle(center_x, center_y, rayon, couleur):
    for x in range(center_x - rayon, center_x + rayon + 1):
        for y in range(center_y - rayon, center_y + rayon + 1):
            if (x - center_x) ** 2 + (y - center_y) ** 2 <= rayon ** 2:
                set_pixel(x, y, couleur)

def dessiner(continent):
    for line in continent:
        draw_line(line[0], line[1], line[2], line[3], (0, 255, 0))
        
def fond_ecran() :
  fill_rect(0, 0, 320, 222, (0, 0, 0))
  dessiner(amerique)
  dessiner(ile1)
  dessiner(ile2)
  dessiner(angleterre)
  dessiner(grand_continent)
  dessiner(japon)
  dessiner(oceanie)

def initialisation(etat=0):
    try:
        get_keys()
        os = (192, 53, 53)
    except:
        os = (255, 183, 52)
    if etat == 0:
        fill_rect(1, 204, 320, 18, os)
        draw_string("vous avez environ 3 secondes", 2, 204, (255, 255, 255), os)
    else:
        fill_rect(1, 204, 320, 18, os)

def personnage(position, aff=0):
    color = (255, 0, 0) 
    if aff : 
        fill_rect(position[0] - 5, position[1] - 5, 10, 10, (0, 0, 0))

    else :
        color = (255, 0, 0)
        fill_rect(position[0] - 5, position[1] - 1, 10, 2, color)
        fill_rect(position[0] - 1, position[1] - 5, 2, 10, color)
def collision(point_rouge, position):
    return (point_rouge[0] >= position[0] - 5 and point_rouge[0] <= position[0] + 5 and
            point_rouge[1] >= position[1] - 5 and point_rouge[1] <= position[1] + 5)

def move(position, bordure, vitesse):
    mvt = position[:]
    is_key_pressed = False

    if keydown(1):  # Haut
        mvt[1] = max(position[1] - vitesse, bordure[2])
        is_key_pressed = True

    if keydown(2):  # Bas
        mvt[1] = min(position[1] + vitesse, bordure[3])
        is_key_pressed = True

    if keydown(3):  # Droite
        mvt[0] = min(position[0] + vitesse, bordure[1])
        is_key_pressed = True

    if keydown(0):  # Gauche
        mvt[0] = max(position[0] - vitesse, bordure[0])
        is_key_pressed = True
    
    return mvt if is_key_pressed else position

def jeu(point, temps_a_faire,fond_ecran):
    position = [160, 111]
    bordure = (5, 319, 5, 201)

    liste_villes = list(emplacement_villes.keys())
    index_aleatoire = randint(0, len(liste_villes) - 1)
    ville = liste_villes[index_aleatoire]
    point_rouge = emplacement_villes[ville]

    draw_circle(point_rouge[0], point_rouge[1], 3, (255, 0, 0))
    draw_string(ville, point_rouge[0] + 10, point_rouge[1] - 20, (255, 0, 0),(0,0,0))

    start_time = monotonic()#chronometre

    while True:
        personnage(position,0)
        position = move(position, bordure, vitesse)
        personnage(position, 1)

        if collision(point_rouge, position):
            end_time = monotonic()
            elapsed_time = end_time - start_time

            if elapsed_time <= temps_a_faire:
                point += 1
                temps_a_faire -=  0.1
                draw_string("Bravo, tu gagnes 1 point!", 100, 160, (0, 255, 0),(0,0,0))
            else:
                draw_string("Trop lent ! Essaie encore.", 100, 160, (255, 0, 0),(0,0,0))

            sleep(1)
            fill_rect(0, 180, 320, 20, (0, 0, 0))
            fond_ecran()
            break

    return point, temps_a_faire

afficher_texte_deroulant(texte, y_position, vitesse)
sleep(1)
fond_ecran()
initialisation()

while point < 10:
    point, temps_a_faire = jeu(point, temps_a_faire,fond_ecran)
    initialisation()
draw_string("Felicitations, vous avez gagne !", 10, 100, (255, 0, 0))

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.