import turtle
import random

# Function to print out the pattern at the bottom of the sheet  
def plot_zigzag():
    border_turtle.speed(0)
    border_turtle.penup()
    border_turtle.goto(-270, -240)
    border_turtle.pendown()
    for i in range(18):
        border_turtle.left(60)
        border_turtle.forward(30)
        border_turtle.right(120)
        border_turtle.forward(30)
        border_turtle.left(60)

# Set up the screen
screen = turtle.Screen()
screen.title("Text Adventure Game Character Page")
screen.setup(width=800, height=600)
screen.bgcolor("lightgrey")

# Character Stats with random values
stats = {
    "Strength": random.randint(8, 18),
    "Dexterity": random.randint(8, 18),
    "Constitution": random.randint(8, 18),
    "Intelligence": random.randint(8, 18),
    "Wisdom": random.randint(8, 18),
    "Charisma": random.randint(8, 18)
}

# Create a Turtle instance for drawing
layout_turtle = turtle.Turtle()
layout_turtle.speed(0)

# Draw each stat in a bordered, yellow background rectangle
layout_turtle.penup()
y_position = 130  # Adjusted position for stats to fit below race/class
layout_turtle.pensize(3)
for stat, value in stats.items():
    # Draw grey rectangle with black border
    layout_turtle.goto(80, y_position)
    layout_turtle.color("black", "yellow")  # Border color black, fill color grey
    layout_turtle.pendown()
    layout_turtle.begin_fill()
    for _ in range(2):
        layout_turtle.forward(200)  # Width of the rectangle
        layout_turtle.right(90)
        layout_turtle.forward(50)   # Height of the rectangle
        layout_turtle.right(90)
    layout_turtle.end_fill()
    layout_turtle.penup()
   
    # Write stat name and value in the rectangle
    layout_turtle.goto(110, y_position - 35)
    layout_turtle.color("black")
    layout_turtle.write(f"{stat}: {value}", font=("Arial", 14, "normal"))
    
    y_position -= 55  # Move down for the next stat box


# Draw the border rectangle
layout_turtle.penup()
layout_turtle.goto(-300, 250)
layout_turtle.pendown()
layout_turtle.pensize(5)
layout_turtle.color("black")
for _ in range(2):
    layout_turtle.forward(600)
    layout_turtle.right(90)
    layout_turtle.forward(500)
    layout_turtle.right(90)
layout_turtle.penup()

# Title
layout_turtle.goto(0, 260)
layout_turtle.write("Epic Text Adventure Character Sheet", align="center", font=("Arial", 20, "bold"))

# Draw border with color for Race and Class
border_turtle = turtle.Turtle()
border_turtle.penup()
border_turtle.goto(80, 220)
border_turtle.pendown()
border_turtle.pensize(4)
border_turtle.color("black","lightgreen")
border_turtle.begin_fill()
for _ in range(2):
    border_turtle.forward(200)
    border_turtle.right(90)
    border_turtle.forward(80)
    border_turtle.right(90)
border_turtle.end_fill()
border_turtle.penup()


# Character Information Area (e.g., Race and Class)
layout_turtle.goto(100, 180)
layout_turtle.write("Race: Elf", font=("Arial", 16, "normal"))
layout_turtle.goto(100, 150)
layout_turtle.write("Class: Ranger", font=("Arial", 16, "normal"))

# Draw the character portrait rectangle
layout_turtle.goto(-275, 200)
layout_turtle.pendown()
layout_turtle.color("black")
layout_turtle.begin_fill()
layout_turtle.fillcolor("white")
for _ in range(2):
    layout_turtle.forward(150)
    layout_turtle.right(90)
    layout_turtle.forward(150)
    layout_turtle.right(90)
layout_turtle.end_fill()
layout_turtle.penup()

# Set the Character portrait Name label
layout_turtle.goto(-280, 210)
layout_turtle.color("black")
layout_turtle.write("Arannis the Brave", font=("Arial", 16, "italic"))


# Add the .gif image as a turtle shape for the character portrait
try:
    screen.addshape("character.gif")  # Add the GIF image as a turtle shape
except Exception as e:
    print("Image could not be loaded:", e)

# Character Portrait - Moved further down to avoid overlap with the character name
portrait_turtle = turtle.Turtle()
portrait_turtle.penup()
portrait_turtle.shape("character.gif")  # Set turtle shape to the resized gif image
portrait_turtle.goto(-200, 125)  # Adjusted position for the portrait
portrait_turtle.stamp()  # Stamp the image to keep it on screen

plot_zigzag()

# Hide the turtle
layout_turtle.hideturtle()

# Keep the window open
turtle.done()