pen.py

Created by 4223

Created on September 01, 2025

2.02 KB

voetbal


# Tfrom kandinsky import *
from ion import *
from time import sleep
from random import choice

WIDTH, HEIGHT = 320, 222
WHITE = color(255,255,255)
BLACK = color(0,0,0)
GREEN = color(0,255,0)
RED = color(255,0,0)

score_player = 0
score_keeper = 0
rounds = 5

directions = ["Links", "Midden", "Rechts"]

def draw_field():
    fill_rect(0,0,WIDTH,HEIGHT,GREEN)
    draw_string("Penalty Shootout", 70, 10, WHITE, GREEN)
    draw_string("Score Jij: "+str(score_player), 10, 30, WHITE, GREEN)
    draw_string("Score Keeper: "+str(score_keeper), 170, 30, WHITE, GREEN)
    draw_string("Kies Richting:", 90, 60, WHITE, GREEN)
    draw_string("[1]=Links  [OK]=Midden  [3]=Rechts", 20, 80, WHITE, GREEN)

def draw_result(msg, color):
    draw_string(msg, 100, 150, color, GREEN)

for r in range(1, rounds+1):
    draw_field()
    draw_string("Ronde "+str(r)+" van "+str(rounds), 100, 110, WHITE, GREEN)

    # Wachten op input
    choice_made = False
    while not choice_made:
        if keydown(KEY_ONE):
            player_choice = "Links"
            choice_made = True
        elif keydown(KEY_OK):
            player_choice = "Midden"
            choice_made = True
        elif keydown(KEY_THREE):
            player_choice = "Rechts"
            choice_made = True
        sleep(0.05)

    keeper_choice = choice(directions)

    # Resultaat
    if player_choice == keeper_choice:
        draw_result("GESTOPT! Keeper koos "+keeper_choice, RED)
        score_keeper += 1
    else:
        draw_result("GOAL! Keeper koos "+keeper_choice, WHITE)
        score_player += 1

    sleep(2)

# Einde spel
fill_rect(0,0,WIDTH,HEIGHT,BLACK)
draw_string("EINDSTAND", 110, 80, WHITE, BLACK)
draw_string("Jij: "+str(score_player), 110, 110, WHITE, BLACK)
draw_string("Keeper: "+str(score_keeper), 110, 130, WHITE, BLACK)

if score_player > score_keeper:
    draw_string("JE WINT!", 110, 160, WHITE, BLACK)
elif score_player < score_keeper:
    draw_string("JE VERLIEST!", 110, 160, WHITE, BLACK)
else:
    draw_string("GELIJKSPEL!", 110, 160, WHITE, BLACK)
ype your text here

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.