#!/bin/python3 import turtle import time circles = [] circles_per_row = 7 game_won = False player_number = 1 player_colour = 'red' 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() # 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) # Check if the game has been won # Change players if (player_number == 1): player_number = 2 player_colour = 'blue' else: player_number = 1 player_colour = 'red'