Finished making the board now starting on the checker pieces

something im wondering about is how can I shorten my code
This commit is contained in:
tsmith37
2025-09-24 23:52:16 -04:00
parent 0619ab9f76
commit 2b48b85065

View File

@@ -7,12 +7,6 @@
from turtle import *
def square(size):
"Draws a square of side length `size`"
for side in range(4):
forward(size)
right(90)
def board(side_length):
"Out line of the board"
sides = [side_length, side_length, side_length, side_length]
@@ -21,12 +15,24 @@ def board(side_length):
forward(sides)
right(90)
def blue_coin(size):
begin_fill()
fillcolor('blue')
circle(size)
end_fill()
penup()
goto(-300, 200)
pendown()
board(400)
def black_row(side_length):
"first row"
def black_row(size):
"black tile first"
repeat = [1, 2, 3, 4]
for repeat in repeat:
forward(50)
forward(size)
right(90)
sizes = [50,50,50,50]
@@ -38,16 +44,140 @@ for size in sizes:
penup()
forward(size * 2)
pendown()
right(90)
forward(50)
right(90)
forward(400)
left(180)
square(50)
forward(50)
black_row(50)
"second row - white tile first"
sizes = [50,50,50,50]
for size in sizes:
begin_fill()
fillcolor('black')
black_row(size)
end_fill()
penup()
forward(size * 2)
right(90)
forward(50)
right(90)
forward(50)
pendown()
forward(400)
left(180)
"third row - black tile first"
sizes = [50,50,50,50]
for size in sizes:
begin_fill()
fillcolor('black')
black_row(size)
end_fill()
penup()
forward(size * 2)
pendown()
right(90)
forward(50)
right(90)
forward(400)
left(180)
forward(50)
"fourth row - white tile first"
sizes = [50,50,50,50]
for size in sizes:
begin_fill()
fillcolor('black')
black_row(size)
end_fill()
penup()
forward(size * 2)
right(90)
forward(50)
right(90)
forward(50)
pendown()
forward(400)
left(180)
"five row - black tile first"
sizes = [50,50,50,50]
for size in sizes:
begin_fill()
fillcolor('black')
black_row(size)
end_fill()
penup()
forward(size * 2)
pendown()
right(90)
forward(50)
right(90)
forward(400)
left(180)
forward(50)
"six row - white tile first"
sizes = [50,50,50,50]
for size in sizes:
begin_fill()
fillcolor('black')
black_row(size)
end_fill()
penup()
forward(size * 2)
right(90)
forward(50)
right(90)
forward(50)
pendown()
forward(400)
left(180)
"seven row - black tile first"
sizes = [50,50,50,50]
for size in sizes:
begin_fill()
fillcolor('black')
black_row(size)
end_fill()
penup()
forward(size * 2)
pendown()
right(90)
forward(50)
right(90)
forward(400)
left(180)
forward(50)
"eight row - white tile first"
sizes = [50,50,50,50]
for size in sizes:
begin_fill()
fillcolor('black')
black_row(size)
end_fill()
penup()
forward(size * 2)
right(90)
forward(50)
right(90)
forward(50)
pendown()
forward(400)
left(180)
forward(75)
blue_coin(25)
input()