Skip to content

Instantly share code, notes, and snippets.

@albionbrown
Last active March 9, 2022 18:03
Show Gist options
  • Save albionbrown/95107a6d5f0b5269248421c2f1aa92e5 to your computer and use it in GitHub Desktop.
Save albionbrown/95107a6d5f0b5269248421c2f1aa92e5 to your computer and use it in GitHub Desktop.
#!/bin/python3
import turtle
import time
circles = []
circles_per_row = 7
player_number = 1
player_colour = 'red'
game_won = False
def make_grid():
startx = -150
starty = 150
distance_between_circles = 40
circle_counter = 0
for i in range(1, 43):
new_circle = turtle.Turtle()
new_circle.shape('circle')
new_circle.speed('fastest')
new_circle.hideturtle()
new_circle.penup()
if circle_counter >= circles_per_row:
starty = starty - 40
startx = -150
circle_counter = 0
new_circle.setx(startx)
new_circle.sety(starty)
startx = startx + distance_between_circles
circles.append(new_circle)
circle_counter = circle_counter + 1
# end of make_grid function
def make_case():
case = turtle.Turtle()
case.color('black')
case.speed('fastest')
case.penup()
case.setx(-170)
case.sety(170)
case.pendown()
for i in range(0, 2):
case.forward(280)
case.right(90)
case.forward(250)
case.right(90)
for i in range(0, 6):
case.forward(40)
case.right(90)
case.forward(250)
case.penup()
case.back(250)
case.left(90)
case.pendown()
case.forward(40)
case.right(90)
for i in range(0, 5):
case.forward(41)
case.right(90)
case.forward(280)
case.back(280)
case.left(90)
# end of make_case function
def put_chip_in_slot(slot):
print("Putting chip in slot: "+str(slot))
row = 0
another_row = True
while (another_row):
circle_number = (row*circles_per_row) + slot
circle = circles[circle_number]
# Is the slot taken?
if (circle.isvisible()):
another_row = False
return
# Is there another row and is the slot taken?
else:
if (((circle_number + circles_per_row) <= len(circles)) and not circles[circle_number + circles_per_row].isvisible()):
row = row + 1
else:
another_row = False
circle.color(player_colour)
circle.showturtle()
# end of put_chip_in_slot function
# Game code
make_grid()
make_case()
print("The game is ready to play!")
while (not game_won):
print("Player "+str(player_number)+" to play")
print("Enter a slot between 0-6")
slot = int(input())
put_chip_in_slot(slot)
if (player_number == 1):
player_number = 2
player_colour = 'green'
else:
player_number = 1
player_colour = 'red'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment