from play_and_code import *
import random

tick_speed(2)

gegner_antwort = 0
phase = 0
auswahl = 0
def main():
    global phase, gegner_antwort, auswahl

    if phase == 0:
        schere_farbe = WHITE
        stein_farbe = WHITE
        papier_farbe = WHITE

        if is_key_pressed(SPACE):
            phase = phase  + 1
        
        if is_key_pressed(UP):
            auswahl = auswahl - 1

        if is_key_pressed(DOWN):
            auswahl = auswahl + 1

        if auswahl > 2:
            auswahl = 0
        elif auswahl < 0:
            auswahl = 2

        if auswahl == 0:
            schere_farbe = RED
        elif auswahl == 1:
            stein_farbe = RED
        elif auswahl == 2:
            papier_farbe = RED
        
        text("Schere", schere_farbe, 100, WINDOW_HEIGHT/2 - 100, 28)
        text("Stein", stein_farbe, 100, WINDOW_HEIGHT/2, 28)
        text("Papier", papier_farbe, 100, WINDOW_HEIGHT/2 + 100, 28)
    
    elif phase == 1:
        gegner_antwort = random.randint(0,2)
        phase = phase + 1

    elif phase == 2:
        gegner_ausgabe = ""
        if gegner_antwort == 0:
            gegner_ausgabe = "Schere"
        elif gegner_antwort == 1:
            gegner_ausgabe = "Stein"
        else:
            gegner_ausgabe = "Papier"
            
        ausgabe = ""
        if auswahl == 0:
            ausgabe = "Schere"
        elif auswahl == 1:
            ausgabe = "Stein"
        else:
            ausgabe = "Papier"

        text("Der gegner hat " + gegner_ausgabe, WHITE, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2 - 100, 48)
        text("Du hast " + ausgabe, WHITE, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, 48)
        
        if auswahl == gegner_antwort:
            text("Es gibt keinen Gewinner, beide haben das gleiche", WHITE, WINDOW_WIDTH / 2,  WINDOW_HEIGHT / 2 + 100, 28)


        if auswahl == 0 and gegner_antwort == 1:
            text("Du hast verloren", RED, WINDOW_WIDTH / 2,  WINDOW_HEIGHT / 2 + 100, 28)
        if auswahl == 0 and gegner_antwort == 2:
            text("Du hast gewonnen", GREEN, WINDOW_WIDTH / 2,  WINDOW_HEIGHT / 2 + 100, 28)

        if auswahl == 1 and gegner_antwort == 0:
            text("Du hast gewonnen", GREEN, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2 + 100, 28)
        if auswahl == 1 and gegner_antwort == 2:
            text("Du hast verloren", RED, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2 + 100, 28)
            
        if auswahl == 2 and gegner_antwort == 0:
            text("Du hast verloren", RED, WINDOW_WIDTH / 2,  WINDOW_HEIGHT / 2 + 100, 28)
        if auswahl == 2 and gegner_antwort == 1:
            text("Du hast gewonnen", GREEN, WINDOW_WIDTH / 2,  WINDOW_HEIGHT / 2 + 100, 28)
        
        if is_key_pressed(RIGHT):
            phase = 0

start(main)

