import pyxel
import math

# -----------------------------------------------------------------------
WIDTH  = 512
HEIGHT = 512
FPS    = 60

# Farben
COL_BG      = 1
COL_ICE     = 6
COL_HOUSE4  = 8
COL_HOUSE3  = 14
COL_HOUSE2  = 7
COL_BUTTON  = 11
COL_P1      = 8
COL_P2      = 9
COL_TEXT    = 7
COL_GOLD    = 10
COL_GRAY    = 5
COL_BLACK   = 0
COL_WHITE   = 7
COL_BROWN   = 4
COL_BEAK    = 10
STAND_COL1  = 2
STAND_COL2  = 5

# Spielfeld
SHEET_X = 56
SHEET_W = 400
SHEET_Y = 8
SHEET_H = 496
SHEET_R = SHEET_X + SHEET_W

HOUSE_CX = SHEET_X + SHEET_W // 2
HOUSE_CY = SHEET_Y + 104
BUTTON_R = 10
RING1_R  = 28
RING2_R  = 48
RING3_R  = 76
SCORE_ZONE_R = RING3_R

HOG_Y  = SHEET_Y + 220
HACK_Y = SHEET_Y + SHEET_H - 32

WALL_L  = SHEET_X
WALL_R  = SHEET_X + SHEET_W
BACK_Y  = SHEET_Y
FRONT_Y = SHEET_Y + SHEET_H

# Spielkonstanten
STONE_R             = 13
MAX_STONES_PER_TEAM = 8
MAX_ROUNDS          = 6
MAX_POWER   = 100
POWER_SPEED = 1.5
FRICTION    = 0.987
SWEEP_FRICTION_BONUS = 0.005
SWEEP_STEER       = 0.002
SWEEP_STEER_CURVE = 0.010

SPECIAL_POWER  = 0
SPECIAL_CURVE  = 1
SPECIAL_DOUBLE = 2
SPECIAL_NAMES  = ["POWER", "CURVE", "DOUBLE"]
SPECIAL_KEYS_P1 = [pyxel.KEY_R, pyxel.KEY_T, pyxel.KEY_G]
SPECIAL_KEYS_P2 = [pyxel.KEY_U, pyxel.KEY_I, pyxel.KEY_J]

STATE_AIM      = 0
STATE_POWER    = 1
STATE_SLIDING  = 2
STATE_SCORE    = 4
STATE_GAMEOVER = 5

def vlen(vx, vy):
    return math.sqrt(vx*vx + vy*vy)

def dist(ax, ay, bx, by):
    return math.sqrt((ax-bx)**2 + (ay-by)**2)

# -----------------------------------------------------------------------
# Pinguin  (schaut nach rechts; left=True → spiegeln)
# -----------------------------------------------------------------------
def _draw_penguin(cx, cy, sweater_col, jump=0, sign=False, sign_text="", left=False):
    y = cy - jump
    # Körper
    pyxel.circ(cx, y-8, 4, COL_BLACK)
    pyxel.rect(cx-3, y-15, 7, 9, COL_BLACK)
    # Bauch
    pyxel.rect(cx-1, y-14, 3, 7, COL_WHITE)
    # Pullover
    pyxel.rect(cx-3, y-12, 7, 2, sweater_col)
    # Schnabel
    if left:
        pyxel.pset(cx-4, y-8, COL_BEAK)
        pyxel.pset(cx-5, y-8, COL_BEAK)
    else:
        pyxel.pset(cx+4, y-8, COL_BEAK)
        pyxel.pset(cx+5, y-8, COL_BEAK)
    # Augen
    pyxel.pset(cx-1, y-10, COL_WHITE)
    pyxel.pset(cx+1, y-10, COL_WHITE)
    # Füsse
    pyxel.pset(cx-2, y-1, COL_BEAK)
    pyxel.pset(cx+2, y-1, COL_BEAK)
    # Flügel heben sich beim Springen
    wy = y - 11 - (jump // 2)
    pyxel.line(cx-3, y-13, cx-6, wy, COL_BLACK)
    pyxel.line(cx+3, y-13, cx+6, wy, COL_BLACK)
    # Plakat
    if sign:
        if left:
            sx, sy2 = cx-22, y-24
            pyxel.rect(sx, sy2, 16, 10, COL_WHITE)
            pyxel.rectb(sx, sy2, 16, 10, COL_BLACK)
            for li, ln in enumerate(sign_text.split("\n")):
                pyxel.text(sx+1, sy2+1+li*5, ln, sweater_col)
            pyxel.line(cx-6, wy, sx+16, sy2+10, COL_BROWN)
        else:
            sx, sy2 = cx+8, y-24
            pyxel.rect(sx, sy2, 16, 10, COL_WHITE)
            pyxel.rectb(sx, sy2, 16, 10, COL_BLACK)
            for li, ln in enumerate(sign_text.split("\n")):
                pyxel.text(sx+1, sy2+1+li*5, ln, sweater_col)
            pyxel.line(cx+6, wy, sx, sy2+10, COL_BROWN)

# -----------------------------------------------------------------------
# Tribünen
# -----------------------------------------------------------------------
def draw_stands(frame):
    lw  = SHEET_X        # Breite links = 56
    rx  = SHEET_R        # Start rechts = 456
    rw  = WIDTH - rx     # Breite rechts = 56

    N_STEPS  = 8
    step_h   = HEIGHT // N_STEPS   # ~64px pro Stufe

    # Stufen zeichnen
    for i in range(N_STEPS):
        y   = HEIGHT - (i+1)*step_h
        col = STAND_COL1 if i % 2 == 0 else STAND_COL2
        pyxel.rect(0,  y, lw, step_h, col)
        pyxel.rect(rx, y, rw, step_h, col)
        pyxel.line(0,  y, lw-1, y, COL_BLACK)
        pyxel.line(rx, y, WIDTH-1, y, COL_BLACK)

    # Oberer Handlauf
    pyxel.rect(0,  0, lw, 8, STAND_COL1)
    pyxel.rect(rx, 0, rw, 8, STAND_COL1)

    # --- LINKE PINGUINE (rot, schauen nach rechts) ---
    # 5 Pinguine pro Stufe × 8 Stufen = 40 Pinguine
    for step in range(N_STEPS):
        base_y  = HEIGHT - step*step_h - 4
        # 5 Positionen in 56px: x = 6,16,26,38,50
        xs = [6, 16, 26, 38, 50]
        for k, px in enumerate(xs):
            idx      = step*5 + k
            jump     = int(abs(math.sin(frame*0.07 + idx*0.85)) * 6)
            has_sign = (k == 2 and step % 3 == 0)
            _draw_penguin(px, base_y, COL_P1, jump,
                          sign=has_sign, sign_text="go\nred", left=False)

    # --- RECHTE PINGUINE (orange, schauen nach links) ---
    for step in range(N_STEPS):
        base_y = HEIGHT - step*step_h - 4
        xs = [rx+6, rx+16, rx+28, rx+40, rx+50]
        for k, px in enumerate(xs):
            idx      = step*5 + k
            jump     = int(abs(math.sin(frame*0.08 + idx*0.95)) * 6)
            has_sign = (k == 2 and step % 3 == 1)
            _draw_penguin(px, base_y, COL_P2, jump,
                          sign=has_sign, sign_text="go\norg", left=True)

# -----------------------------------------------------------------------
# Stein
# -----------------------------------------------------------------------
class Stone:
    def __init__(self, x, y, team, is_double=False):
        self.x  = float(x)
        self.y  = float(y)
        self.vx = 0.0
        self.vy = 0.0
        self.team      = team
        self.active    = False
        self.placed    = False
        self.is_double = is_double
        self.r         = STONE_R

    def touch_wall(self):
        return self.x - self.r < WALL_L or self.x + self.r > WALL_R

    def out_back(self):   return self.y - self.r < BACK_Y
    def out_front(self):  return self.y + self.r > FRONT_Y
    def behind_hog(self): return self.placed and self.y > HOG_Y

    def draw(self, is_current=False):
        ix, iy = int(self.x), int(self.y)
        col = COL_P1 if self.team == 0 else COL_P2
        pyxel.circ(ix, iy, self.r, col)
        pyxel.circb(ix, iy, self.r, COL_BLACK)
        if self.is_double:
            pyxel.circb(ix, iy, self.r-3, COL_GOLD)
        if is_current:
            pyxel.circb(ix, iy, self.r+3, COL_GOLD)

# -----------------------------------------------------------------------
# Kollision
# -----------------------------------------------------------------------
def collide_stones(a, b):
    dx = b.x-a.x;  dy = b.y-a.y
    d  = math.sqrt(dx*dx + dy*dy)
    min_d = a.r+b.r
    if d >= min_d or d < 0.0001:
        return
    nx = dx/d;  ny = dy/d
    tx = -ny;   ty =  nx
    an = a.vx*nx+a.vy*ny;  at = a.vx*tx+a.vy*ty
    bn = b.vx*nx+b.vy*ny;  bt = b.vx*tx+b.vy*ty
    if an-bn <= 0:
        return
    a.vx = bn*nx+at*tx;  a.vy = bn*ny+at*ty
    b.vx = an*nx+bt*tx;  b.vy = an*ny+bt*ty
    if not b.active:
        b.active = True;  b.placed = False
    push = (min_d-d)/2.0
    a.x -= nx*push;  a.y -= ny*push
    b.x += nx*push;  b.y += ny*push

# -----------------------------------------------------------------------
# Spiel
# -----------------------------------------------------------------------
class CurlingGame:
    def __init__(self):
        pyxel.init(WIDTH, HEIGHT, title="Curling", fps=FPS)
        self.frame = 0
        self.reset_game()
        pyxel.run(self.update, self.draw)

    def reset_game(self):
        self.round         = 1
        self.scores        = [0, 0]
        self.round_scores  = [[0]*MAX_ROUNDS, [0]*MAX_ROUNDS]
        self.current_team  = 0
        self.stones_thrown = [0, 0]
        self.stones        = []
        self.current_stone = None
        self.state         = STATE_AIM
        self.power         = 0
        self.power_dir     = 1
        self.aim_angle     = -math.pi/2
        self.sweep_boost   = 0.0
        self.score_msg     = ""
        self.score_timer   = 0
        self.specials_used     = [[False,False,False],[False,False,False]]
        self.selected_special  = [None, None]
        self.active_special    = None
        self.info_msg      = ""
        self.info_timer    = 0
        self._spawn_new_stone()

    def reset_round(self):
        self.stones = []
        self.stones_thrown = [0, 0]
        self.current_team = (self.round-1) % 2
        self.active_special = None
        self._spawn_new_stone()

    def _spawn_new_stone(self):
        team = self.current_team
        self.current_stone  = Stone(HOUSE_CX, HACK_Y, team)
        self.aim_angle      = -math.pi/2
        self.sweep_boost    = 0.0
        self.state          = STATE_AIM
        self.active_special = self.selected_special[team]

    def stones_in_flight(self):
        return any(s.vx != 0.0 or s.vy != 0.0 for s in self.stones)

    def all_thrown(self):
        return (self.stones_thrown[0] >= MAX_STONES_PER_TEAM and
                self.stones_thrown[1] >= MAX_STONES_PER_TEAM)

    def update(self):
        self.frame += 1

        if self.state == STATE_GAMEOVER:
            if pyxel.btnp(pyxel.KEY_RETURN):
                self.reset_game()
            return

        if self.state == STATE_SCORE:
            self.score_timer -= 1
            if self.score_timer <= 0:
                if self.round > MAX_ROUNDS:
                    self.state = STATE_GAMEOVER
                else:
                    self.reset_round()
            return

        if self.info_timer > 0:
            self.info_timer -= 1

        if self.state == STATE_AIM:
            team = self.current_team
            keys = SPECIAL_KEYS_P1 if team == 0 else SPECIAL_KEYS_P2
            for i, key in enumerate(keys):
                if pyxel.btnp(key) and not self.specials_used[team][i]:
                    if self.selected_special[team] == i:
                        self.selected_special[team] = None
                        self.info_msg = "Special deaktiviert"
                    else:
                        self.selected_special[team] = i
                        self.info_msg = f"Special: {SPECIAL_NAMES[i]}"
                    self.info_timer = 90

        if   self.state == STATE_AIM:     self._update_aim()
        elif self.state == STATE_POWER:   self._update_power()
        elif self.state == STATE_SLIDING: self._update_sliding()

    def _update_aim(self):
        spd = 0.018
        team = self.current_team
        if team == 0:
            if pyxel.btn(pyxel.KEY_LEFT):  self.aim_angle -= spd
            if pyxel.btn(pyxel.KEY_RIGHT): self.aim_angle += spd
        else:
            if pyxel.btn(pyxel.KEY_A): self.aim_angle -= spd
            if pyxel.btn(pyxel.KEY_D): self.aim_angle += spd
        self.aim_angle = max(-math.pi+0.15, min(-0.15, self.aim_angle))
        if pyxel.btnp(pyxel.KEY_SPACE):
            self.state = STATE_POWER;  self.power = 0;  self.power_dir = 1

    def _update_power(self):
        self.power += self.power_dir * POWER_SPEED
        if self.power >= MAX_POWER:
            self.power = MAX_POWER;  self.power_dir = -1
        elif self.power <= 0:
            self.power = 0;          self.power_dir =  1
        if pyxel.btnp(pyxel.KEY_SPACE):
            self._throw_stone()

    def _throw_stone(self):
        team    = self.current_team
        special = self.active_special
        pmult   = 1.0
        if special == SPECIAL_POWER:
            pmult = 1.7
            self.specials_used[team][SPECIAL_POWER] = True
            self.selected_special[team] = None
        speed = (self.power/MAX_POWER)*8.0*pmult
        self.current_stone.vx = math.cos(self.aim_angle)*speed
        self.current_stone.vy = math.sin(self.aim_angle)*speed
        self.current_stone.active = True
        self.current_stone.placed = False
        self.stones.append(self.current_stone)
        self.stones_thrown[team] += 1
        if special == SPECIAL_DOUBLE:
            ds = Stone(self.current_stone.x+STONE_R*2+2,
                       self.current_stone.y, team, is_double=True)
            ds.vx = self.current_stone.vx
            ds.vy = self.current_stone.vy
            ds.active = True
            self.stones.append(ds)
            self.specials_used[team][SPECIAL_DOUBLE] = True
            self.selected_special[team] = None
        if special == SPECIAL_CURVE:
            self.specials_used[team][SPECIAL_CURVE] = True
        self.current_stone = None
        self.state = STATE_SLIDING

    def _update_sliding(self):
        team  = self.current_team
        steer = SWEEP_STEER_CURVE if self.active_special == SPECIAL_CURVE else SWEEP_STEER
        self.sweep_boost = 0.0
        if team == 0:
            if pyxel.btn(pyxel.KEY_UP):    self.sweep_boost = 1.0
            if pyxel.btn(pyxel.KEY_LEFT):
                for s in self.stones:
                    if s.active: s.vx -= steer
            if pyxel.btn(pyxel.KEY_RIGHT):
                for s in self.stones:
                    if s.active: s.vx += steer
        else:
            if pyxel.btn(pyxel.KEY_W):     self.sweep_boost = 1.0
            if pyxel.btn(pyxel.KEY_A):
                for s in self.stones:
                    if s.active: s.vx -= steer
            if pyxel.btn(pyxel.KEY_D):
                for s in self.stones:
                    if s.active: s.vx += steer

        SUBSTEPS = 4
        for _ in range(SUBSTEPS):
            for s in self.stones:
                if s.vx != 0.0 or s.vy != 0.0:
                    s.x += s.vx/SUBSTEPS
                    s.y += s.vy/SUBSTEPS
            for i in range(len(self.stones)):
                for j in range(i+1, len(self.stones)):
                    collide_stones(self.stones[i], self.stones[j])

        for s in self.stones:
            if s.vx != 0.0 or s.vy != 0.0:
                f = FRICTION - self.sweep_boost*SWEEP_FRICTION_BONUS
                s.vx *= f;  s.vy *= f
                if vlen(s.vx, s.vy) < 0.08:
                    s.vx = s.vy = 0.0
                    s.active = False
                    s.placed = True

        def should_remove(s):
            if s.out_back() or s.out_front(): return True
            if s.active and s.touch_wall():   return True
            if s.behind_hog():                return True
            return False
        self.stones = [s for s in self.stones if not should_remove(s)]

        if not self.stones_in_flight():
            if self.active_special == SPECIAL_CURVE:
                self.selected_special[team] = None
            self.active_special = None
            if self.all_thrown():
                self._end_round()
            else:
                self.current_team = 1-self.current_team
                self._spawn_new_stone()

    def _end_round(self):
        t = [[], []]
        for s in self.stones:
            if s.placed:
                d = dist(s.x, s.y, HOUSE_CX, HOUSE_CY)
                if d <= SCORE_ZONE_R+s.r:
                    t[s.team].append(d)
        t[0].sort(); t[1].sort()
        pts = 0; winner = -1
        if t[0] and t[1]:
            if   t[0][0] < t[1][0]: winner=0; pts=sum(1 for d in t[0] if d < t[1][0])
            elif t[1][0] < t[0][0]: winner=1; pts=sum(1 for d in t[1] if d < t[0][0])
        elif t[0]: winner=0; pts=len(t[0])
        elif t[1]: winner=1; pts=len(t[1])
        idx = self.round-1
        if winner >= 0:
            self.round_scores[winner][idx] = pts
            self.scores[winner] += pts
            self.score_msg = f"Runde {self.round}: {'Rot' if winner==0 else 'Orange'} +{pts} Pkt!"
        else:
            self.score_msg = f"Runde {self.round}: Keine Punkte (blank)"
        self.round += 1
        self.state       = STATE_SCORE
        self.score_timer = 210
        self.selected_special = [None, None]

    # ------------------------------------------------------------------- DRAW
    def draw(self):
        pyxel.cls(COL_BG)
        draw_stands(self.frame)
        self._draw_sheet()
        for s in self.stones:
            s.draw()
        if self.current_stone:
            self.current_stone.draw(
                is_current=(self.state in (STATE_AIM, STATE_POWER)))
        self._draw_ui()
        if self.state == STATE_AIM:    self._draw_aim_arrow()
        if self.state == STATE_POWER:  self._draw_aim_arrow(); self._draw_power_bar()
        if self.state == STATE_SCORE:  self._draw_score_popup()
        if self.state == STATE_GAMEOVER: self._draw_gameover()

    def _draw_sheet(self):
        pyxel.rect(SHEET_X, SHEET_Y, SHEET_W, SHEET_H, COL_ICE)
        pyxel.circb(HOUSE_CX, HOUSE_CY, RING3_R, COL_HOUSE4)
        pyxel.circb(HOUSE_CX, HOUSE_CY, RING2_R, COL_HOUSE3)
        pyxel.circb(HOUSE_CX, HOUSE_CY, RING1_R, COL_HOUSE2)
        pyxel.circb(HOUSE_CX, HOUSE_CY, BUTTON_R, COL_BUTTON)
        pyxel.line(SHEET_X, HOUSE_CY, SHEET_R, HOUSE_CY, COL_GRAY)
        pyxel.line(HOUSE_CX, SHEET_Y, HOUSE_CX, SHEET_Y+SHEET_H, COL_GRAY)
        pyxel.line(SHEET_X, HOG_Y,  SHEET_R, HOG_Y,  COL_P1)
        pyxel.line(SHEET_X, HACK_Y, SHEET_R, HACK_Y, COL_GRAY)
        pyxel.rectb(SHEET_X, SHEET_Y, SHEET_W, SHEET_H, COL_BLACK)

    def _draw_aim_arrow(self):
        if not self.current_stone: return
        cx, cy = int(self.current_stone.x), int(self.current_stone.y)
        ex = cx + int(math.cos(self.aim_angle)*70)
        ey = cy + int(math.sin(self.aim_angle)*70)
        col = COL_P1 if self.current_team==0 else COL_P2
        pyxel.line(cx, cy, ex, ey, col)

    def _draw_power_bar(self):
        bx, by, bw, bh = 8, 160, 16, 180
        pyxel.rect(bx, by, bw, bh, COL_BLACK)
        fill = int((self.power/MAX_POWER)*bh)
        col = 11 if self.power < 60 else (COL_GOLD if self.power < 86 else COL_P1)
        pyxel.rect(bx, by+bh-fill, bw, fill, col)
        pyxel.rectb(bx, by, bw, bh, COL_TEXT)
        pyxel.text(bx-1, by-8, "PWR", COL_TEXT)

    def _draw_ui(self):
        sx, sy = WIDTH-108, 4
        pyxel.rect(sx-2, sy-2, 110, 46, COL_BLACK)
        pyxel.text(sx, sy,    f"ROT:   {self.scores[0]}", COL_P1)
        pyxel.text(sx, sy+10, f"ORANGE:{self.scores[1]}", COL_P2)
        pyxel.text(sx, sy+22, f"Runde: {min(self.round,MAX_ROUNDS)}/{MAX_ROUNDS}", COL_TEXT)

        tx, ty = 28, 390
        pyxel.text(tx, ty, "Steine:", COL_TEXT)
        for i in range(MAX_STONES_PER_TEAM):
            c = COL_P1 if i < MAX_STONES_PER_TEAM-self.stones_thrown[0] else COL_GRAY
            pyxel.circ(tx+i*12, ty+12, 4, c)
        for i in range(MAX_STONES_PER_TEAM):
            c = COL_P2 if i < MAX_STONES_PER_TEAM-self.stones_thrown[1] else COL_GRAY
            pyxel.circ(tx+i*12, ty+24, 4, c)

        tname = "ROT (Pfeile)" if self.current_team==0 else "ORANGE (WASD)"
        tcol  = COL_P1 if self.current_team==0 else COL_P2
        if self.state in (STATE_AIM, STATE_POWER):
            pyxel.text(SHEET_X, HEIGHT-18, f"Dran: {tname}", tcol)
        if   self.state == STATE_AIM:
            pyxel.text(SHEET_X, HEIGHT-8, "Ziel: L/R    SPACE: Power laden", COL_GRAY)
        elif self.state == STATE_POWER:
            pyxel.text(SHEET_X, HEIGHT-8, "SPACE: Abfeuern!", COL_GOLD)
        elif self.state == STATE_SLIDING:
            ctrl = "Auf=Speed  L/R=Kurve" if self.current_team==0 else "W=Speed  A/D=Kurve"
            pyxel.text(SHEET_X, HEIGHT-8, ctrl, COL_GRAY)

        self._draw_specials()

        if self.info_timer > 0:
            pyxel.rect(100, 216, 312, 18, COL_BLACK)
            pyxel.text(104, 221, self.info_msg, COL_GOLD)

    def _draw_specials(self):
        pyxel.text(2, 256, "P1:", COL_P1)
        for i, lbl in enumerate(["R:POWER","T:CURVE","G:DOUBL"]):
            col = COL_GRAY if self.specials_used[0][i] else \
                  (COL_GOLD if self.selected_special[0]==i else COL_TEXT)
            pyxel.text(2, 266+i*12, lbl, col)
        pyxel.text(WIDTH-46, 256, "P2:", COL_P2)
        for i, lbl in enumerate(["U:POWER","I:CURVE","J:DOUBL"]):
            col = COL_GRAY if self.specials_used[1][i] else \
                  (COL_GOLD if self.selected_special[1]==i else COL_TEXT)
            pyxel.text(WIDTH-46, 266+i*12, lbl, col)

    def _draw_score_popup(self):
        bx,by,bw,bh = 80,196,352,80
        pyxel.rect(bx,by,bw,bh,COL_BLACK)
        pyxel.rectb(bx,by,bw,bh,COL_GOLD)
        pyxel.text(bx+12, by+12, self.score_msg, COL_GOLD)
        pyxel.text(bx+12, by+28, "Gesamtstand:", COL_TEXT)
        pyxel.text(bx+12, by+42, f"ROT: {self.scores[0]}    ORANGE: {self.scores[1]}", COL_TEXT)
        if self.round > MAX_ROUNDS:
            pyxel.text(bx+12, by+58, "Letztes Spiel endet gleich...", COL_GRAY)

    def _draw_gameover(self):
        bx,by,bw,bh = 40,130,432,250
        pyxel.rect(bx,by,bw,bh,COL_BLACK)
        pyxel.rectb(bx,by,bw,bh,COL_GOLD)
        pyxel.text(bx+126, by+14, "== SPIEL ENDE ==", COL_GOLD)
        pyxel.text(bx+20,  by+36, f"ROT:    {self.scores[0]} Punkte", COL_P1)
        pyxel.text(bx+20,  by+52, f"ORANGE: {self.scores[1]} Punkte", COL_P2)
        if   self.scores[0] > self.scores[1]: msg,col="ROT GEWINNT!",    COL_P1
        elif self.scores[1] > self.scores[0]: msg,col="ORANGE GEWINNT!", COL_P2
        else:                                  msg,col="UNENTSCHIEDEN!",  COL_GOLD
        pyxel.text(bx+136, by+72, msg, col)
        pyxel.text(bx+20,  by+96,  "    R1  R2  R3  R4  R5  R6", COL_GRAY)
        rr = "ROT:"; ro = "ORA:"
        for i in range(MAX_ROUNDS):
            rr += f"  {self.round_scores[0][i]} "
            ro += f"  {self.round_scores[1][i]} "
        pyxel.text(bx+20, by+112, rr, COL_P1)
        pyxel.text(bx+20, by+128, ro, COL_P2)
        pyxel.text(bx+116, by+200, "ENTER: Neues Spiel", COL_TEXT)


CurlingGame()