Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Basic Python connect 4, details in the document

1 answer below »
Basic Python connect 4, details in the document
Answered Same Day Jul 25, 2021


Roshan answered on Jul 26 2021
123 Votes
"""CS 108 prototype
A connect 4 game
@author: Adrian Poh ajp62
@date: Summer, 2020
# importing all objects in tkinte
from tkinter import *
import winsound
winsound.PlaySound('', winsound.SND_ALIAS | winsound.SND_ASYNC) # i'll add the sound late
class Piece:
def __init__(self, x, y, circlepiece, color="black"):
"""Function that creates the circle piece"""
self.circlepiece = circlepiece
self.x = x
self.y = y
self.color = colo
self.Piece = self.circlepiece.create_oval(self.x + 10, self.y + 10, self.x + 60, self.y + 60, fill=color)
def change_color(self, color):
"""Function that allows the piece to switch color"""
self.circlepiece.itemconfigure(self.Piece, fill=color)
self.color = colo
class App(Canvas):
# this code was taken from https:
def __init__(self, Master): # Using master=none by default as this class is a subclass to tk.Frame
"""Constructor for the main window of the program"""
#Configure function is used to set width, height and background of main window
self.configure(width=500, height=400, background="Blue")
self.player = 1
self.color = "yellow"
self.empty_list = [] = True
self.terminate = False
for i in range(0, 340, 67): # Setting of board size
range_list = []
for h in range(0, 440, 72):
range_list.append(Piece(h, i, self))
self.bind("", self.switching_colors)
def switching_colors(self, event):
"""Function to switch color after every click"""
columnn = int(event.x / 72)
stack = 0 # put yellow or red circle to start from below of window
while stack < len(self.empty_list):
if self.empty_list[0][columnn].color == "red" or self.empty_list[0][0].color == "yellow":

if self.empty_list[stack][columnn].color == "red" or self.empty_list[stack][columnn].color == "yellow":
self.empty_list[stack - 1][columnn].change_color(
self.color) # Allowing each piece to stack above another...

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here