Amazing-Python-Scripts
845 строк · 31.2 Кб
1from tkinter import * # Tkinter is used as the GUI.2import random3import tkinter.messagebox4
5root = Tk()6
7root.resizable(width=False, height=False) # The window size of the game.8root.geometry('1000x750')9root.configure(background='lightgreen')10root.title("Ludo Game")11
12# Loading all the image files that are required in the game.
13logo = PhotoImage(file="./Ludo_Game/whitebox.gif")14logo2 = PhotoImage(file="./Ludo_Game/red side.gif")15logo3 = PhotoImage(file="./Ludo_Game/red.gif")16logo4 = PhotoImage(file="./Ludo_Game/blue side.gif")17logo5 = PhotoImage(file="./Ludo_Game/green side.gif")18logo6 = PhotoImage(file="./Ludo_Game/yellow side.gif")19logo7 = PhotoImage(file="./Ludo_Game/center.gif")20logoxx = PhotoImage(file="./Ludo_Game/test.gif")21logog = PhotoImage(file="./Ludo_Game/greenbox.gif")22logogs = PhotoImage(file="./Ludo_Game/greenstop.gif")23logoy = PhotoImage(file="./Ludo_Game/yellowbox.gif")24logoys = PhotoImage(file="./Ludo_Game/yellowstop.gif")25logob = PhotoImage(file="./Ludo_Game/bluebox.gif")26logobs = PhotoImage(file="./Ludo_Game/bluestop.gif")27logor = PhotoImage(file="./Ludo_Game/redbox.gif")28logors = PhotoImage(file="./Ludo_Game/redstop.gif")29logoh = PhotoImage(file="./Ludo_Game/head.gif")30logot = PhotoImage(file="./Ludo_Game/tail.gif")31logoh1 = PhotoImage(file="./Ludo_Game/head1.gif")32logot1 = PhotoImage(file="./Ludo_Game/tail1.gif")33logoh2 = PhotoImage(file="./Ludo_Game/head2.gif")34logot2 = PhotoImage(file="./Ludo_Game/tail2.gif")35logoh3 = PhotoImage(file="./Ludo_Game/head3.gif")36logot3 = PhotoImage(file="./Ludo_Game/tail3.gif")37logoab= PhotoImage(file="./Ludo_Game/blue.gif")38logoay= PhotoImage(file="./Ludo_Game/yellow.gif")39logoag= PhotoImage(file="./Ludo_Game/green.gif")40
41Label(image=logo2, width=298, height=298).place(x=-1, y=-1) #setting up board images42Label(image=logo4, width=300, height=300).place(x=(-2), y=(448))43Label(image=logo5, width=296, height=296).place(x=(450), y=(0))44Label(image=logo6, width=294, height=294).place(x=(450), y=(450))45Label(image=logo7, width=150, height=150).place(x=(298), y=(298))46
47c = 0 #initializing variable and flags that are to be used in the game48lx = 049bb =050nc = 051rollc = 052rolls = []53RED = True54BLUE = False55GREEN = False56YELLOW = False57TURN = True58REDKILL = False59BLUEKILL = False60GREENKILL = False61YELLOWKILL = False62
63
64def board(): #Drawing the board, piece by piece.65
66#Splash Screen.67tkinter.messagebox.showinfo(title=None, message="TO START GAME PRESS OKAY & TO EXIT PRESS CROSS UP IN THE WINDOW")68v = 069z = 070
71while (v != 300): #Drawing White boxes72z = 073while (z != 150):74Label(image=logo, width=46, height=46).place(x=(300 + z), y=(0 + v))75z = z + 5076v = v + 5077
78z = 079v = 080while (v != 300): #Drawing White boxes81z = 082while (z != 150):83Label(image=logo, width=46, height=46).place(x=(0 + v), y=(300 + z))84z = z + 5085v = v + 5086
87#####################88
89v = 090z = 091
92while (v != 300): #Drawing White boxes93z = 094while (z != 150):95Label(image=logo, width=46, height=46).place(x=(300 + z), y=(450 + v))96z = z + 5097v = v + 5098
99z = 0100v = 0101while (v != 300): #Drawing White boxes102z = 0103while (z != 150):104Label(image=logo, width=46, height=46).place(x=(450 + v), y=(300 + z))105z = z + 50106v = v + 50107
108v = 0109while (v != 250): #Drawing Green boxes110Label(image=logog, width=46, height=46).place(x=(350), y=(50 + v))111v = v + 50112
113Label(image=logog, width=46, height=46).place(x=(300), y=(100))114Label(image=logogs, width=46, height=46).place(x=(400), y=(50))115
116v = 0117while (v != 250): #Drawing Yellow boxes118Label(image=logoy, width=46, height=46).place(x=(450 + v), y=(350))119v = v + 50120
121Label(image=logoy, width=46, height=46).place(x=(600), y=(300))122Label(image=logoys, width=46, height=46).place(x=(650), y=(400))123
124v = 0125while (v != 250): #Drawing Red Boxes126Label(image=logor, width=46, height=46).place(x=(50 + v), y=(350))127v = v + 50128
129Label(image=logor, width=46, height=46).place(x=(100), y=(400))130Label(image=logors, width=46, height=46).place(x=(50), y=(300))131
132v = 0133while (v != 250): #Drawing Blue Boxes134Label(image=logob, width=46, height=46).place(x=(350), y=(450 + v))135v = v + 50136
137Label(image=logobs, width=46, height=46).place(x=(300), y=(650))138Label(image=logob, width=46, height=46).place(x=(400), y=(600))139
140Label(image=logoh, width=46, height=46).place(x=250, y=400) #Drawing arrows141Label(image=logot, width=46, height=46).place(x=300, y=450)142Label(image=logoh1, width=46, height=46).place(x=400, y=450)143Label(image=logot1, width=46, height=46).place(x=450, y=400)144Label(image=logoh2, width=46, height=46).place(x=450, y=300)145Label(image=logot2, width=46, height=46).place(x=400, y=250)146Label(image=logoh3, width=46, height=46).place(x=300, y=250)147Label(image=logot3, width=46, height=46).place(x=250, y=300)148
149class YBox: #Class of yellow box150rap = None151
152def __init__(self, num=-1, x=0, y=0, x0=0, y0=0, double=False, ):153self.num = num #no of gamepiece acc to box154self.x = x #initial and final co-ordinates of the boxes155self.y = y156self.x0 = x0157self.y0 = y0158self.rap = Label(image=logoay, width=20, height=20) #image of game piece.159self.double = double #if one game piece on top of another.160
161def swap(self): #Swaps the position of gamepiece according to the number on dice.162self.rap.place(x=self.x0 + 13, y=self.y0 + 14)163
164class GBox: #Class of green box165rap = None166
167def __init__(self, num=-1, x=0, y=0, x0=0, y0=0, double=False, ):168self.num = num169self.x = x170self.y = y171self.x0 = x0172self.y0 = y0173self.rap = Label(image=logoag, width=20, height=20)174self.double = double175
176def swap(self):177self.rap.place(x=self.x0 + 13, y=self.y0 + 14)178
179class BBox: #Class of Blue box180rap = None181
182def __init__(self, num=-1, x=0, y=0, x0=0, y0=0, double=False, ):183self.num = num184self.x = x185self.y = y186self.x0 = x0187self.y0 = y0188self.rap = Label(image=logoab, width=20, height=20)189self.double = double190
191def swap(self):192self.rap.place(x=self.x0 + 13, y=self.y0 + 14)193
194class Box: #class of red box195rap = None196
197def __init__(self, num=-1, x=0, y=0, x0=0, y0=0, double=False, ):198self.num = num199self.x = x200self.y = y201self.x0 = x0202self.y0 = y0203self.rap = Label(image=logo3, width=20, height=20)204self.double = double205
206def swap(self):207self.rap.place(x=self.x0 + 13, y=self.y0 + 14)208
209
210def main(): # Main game function.211
212global box, redbox, bluebox, greenbox, yellowbox, redhome, bluehome, yellowhome, greenhome213global red, blue, yellow, green, rap, RED, BLUE, GREEN, YELLOW, dice, nc, TURN, bb214
215if c == 0: #constructs the game pieces first time the code is ran.216
217board()218
219box = [Box() for i in range(52)]220
221redbox = [Box() for i in range(57)] # list of co-ordinates of all the colored boxes, excluding home and stop.222bluebox = [Box() for i in range(57)]223greenbox = [Box() for i in range(57)]224yellowbox = [Box() for i in range(57)]225
226redhome = [Box() for i in range(4)] # list co-ordinates of all the home positions227bluehome = [Box() for i in range(4)]228greenhome = [Box() for i in range(4)]229yellowhome = [Box() for i in range(4)]230
231red = [Box() for i in range(4)] # list of co-ordinates of all the game pieces in their initial state232blue = [BBox() for i in range(4)] # that is equal to their respective home co-ordinates.233green = [GBox() for i in range(4)]234yellow = [YBox() for i in range(4)]235
236for i in range(2): #Populates list of homeboxes, colored boxes, gamepieces and white boxes237redhome[i].x = (100 + (100 * i))238redhome[i].y = 100239red[i].x0 = redhome[i].x240red[i].y0 = redhome[i].y241red[i].x = (red[i].x0) + 25242red[i].y = (red[i].y0) + 25243
244bluehome[i].x = (100 + (100 * i))245bluehome[i].y = (550)246blue[i].x0 = bluehome[i].x247blue[i].y0 = bluehome[i].y248blue[i].x = (blue[i].x0) + 25249blue[i].y = (blue[i].y0) + 25250
251yellowhome[i].x = (550 + (100 * i))252yellowhome[i].y = (550)253yellow[i].x0 = yellowhome[i].x254yellow[i].y0 = yellowhome[i].y255yellow[i].x = (yellow[i].x0) + 25256yellow[i].y = (yellow[i].y0) + 25257
258greenhome[i].x = (550 + (100 * i))259greenhome[i].y = (100)260green[i].x0 = greenhome[i].x261green[i].y0 = greenhome[i].y262green[i].x = (green[i].x0) + 25263green[i].y = (green[i].y0) + 25264
265for i in range(2, 4):266redhome[i].x = (100 + (100 * (i - 2)))267redhome[i].y = 200268red[i].x0 = redhome[i].x269red[i].y0 = redhome[i].y270red[i].x = (red[i].x0) + 25271red[i].y = (red[i].y0) + 25272
273bluehome[i].x = (100 + (100 * (i - 2)))274bluehome[i].y = (650)275blue[i].x0 = bluehome[i].x276blue[i].y0 = bluehome[i].y277blue[i].x = (blue[i].x0) + 25278blue[i].y = (blue[i].y0) + 25279
280yellowhome[i].x = (550 + (100 * (i - 2)))281yellowhome[i].y = (650)282yellow[i].x0 = yellowhome[i].x283yellow[i].y0 = yellowhome[i].y284yellow[i].x = (yellow[i].x0) + 25285yellow[i].y = (yellow[i].y0) + 25286
287greenhome[i].x = (550 + (100 * (i - 2)))288greenhome[i].y = 200289green[i].x0 = greenhome[i].x290green[i].y0 = greenhome[i].y291green[i].x = (green[i].x0) + 25292green[i].y = (green[i].y0) + 25293
294for i in range(6):295box[i].x = 300296box[i].y = (700 - (50 * i))297
298for i in range(6, 12):299box[i].x = (250 - (50 * (i - 6)))300box[i].y = (400)301
302box[12].x = 0303box[12].y = 350304
305for i in range(13, 19):306box[i].x = (0 + (50 * (i - 13)))307box[i].y = (300)308
309for i in range(19, 25):310box[i].x = (300)311box[i].y = (250 - (50 * (i - 19)))312
313box[25].x = 350314box[25].y = 0315
316for i in range(26, 32):317box[i].x = (400)318box[i].y = (0 + (50 * (i - 26)))319
320for i in range(32, 38):321box[i].x = (450 + (50 * (i - 32)))322box[i].y = (300)323
324box[38].x = 700325box[38].y = 350326
327for i in range(39, 45):328box[i].x = (700 - (50 * (i - 39)))329box[i].y = (400)330
331for i in range(45, 51):332box[i].x = (400)333box[i].y = (450 + (50 * (i - 45)))334
335box[51].x = 350336box[51].y = 700337
338# teshh339lx = 14340for i in range(52):341redbox[i].x = box[lx].x342redbox[i].y = box[lx].y343lx = lx + 1344if lx > 51:345lx = 0346
347lx = 50348for i in range(7):349redbox[lx].x = (0 + (50 * i))350redbox[lx].y = 350351lx = lx + 1352# blue353lx = 1354for i in range(52):355
356bluebox[i].x = box[lx].x357bluebox[i].y = box[lx].y358lx = lx + 1359if lx > 51:360lx = 0361
362lx = 50363for i in range(7):364bluebox[lx].x = 350365bluebox[lx].y = (700 - (50 * i))366lx = lx + 1367# yellow368lx = 40369for i in range(52):370yellowbox[i].x = box[lx].x371yellowbox[i].y = box[lx].y372lx = lx + 1373if lx > 51:374lx = 0375
376lx = 50377for i in range(7):378yellowbox[lx].x = (700 - (50 * i))379yellowbox[lx].y = (350)380lx = lx + 1381
382# green383lx = 27384for i in range(52):385
386greenbox[i].x = box[lx].x387greenbox[i].y = box[lx].y388
389lx = lx + 1390if lx > 51:391lx = 0392
393lx = 50394for i in range(7):395greenbox[lx].x = 350396greenbox[lx].y = (0 + (50 * i))397lx = lx + 1398
399for i in range(4):400red[i].swap()401blue[i].swap()402green[i].swap()403yellow[i].swap()404
405
406else:407
408if c >= 1: #This condition is true when a click is made.409
410if RED == True and TURN == False: #Red players turn411print("Red's Turn")412print("moves available: ", rolls)413la = "RED"414if (movecheck(red, redhome, redbox, la)) == False: #Checks if player can take a turn.415BLUE = True416RED = False417clear() #clears variable, next players turn418
419if RED == True: # searches if click is made on a red game piece.420for i in range(len(red)):421if ((((cx > red[i].x0 + 13) and (cx < red[i].x + 13)) and (422(cy > red[i].y0 + 14) and (cy < red[i].y + 14)))423and (red[i].x0 == redhome[i].x) and (red[i].y0 == redhome[i].y)):424print("Interesting ")425
426if rolls[0 + nc] == 6: #If a six occurs and gamepiece is in home427#Game piece is moved onto the home box428red[i].x0 = redbox[0].x429red[i].y0 = redbox[0].y430red[i].x = redbox[0].x + 25431red[i].y = redbox[0].y + 25432red[i].num = 0433red[i].swap()434nc = nc + 1435
436if nc > len(rolls) - 1: # check if all moves are made. so next players turn.437BLUE = True438RED = False439clear()440break441
442if ((((cx > red[i].x0 + 13) and (cx < red[i].x + 13)) and ( #if gamepiece is outside home443(cy > red[i].y0 + 14) and (cy < red[i].y + 14)))444and ((red[i].x0 > 270) or (red[i].y0 > 270))):445print("Interesting ")446bb = ((red[i].num) + rolls[0 + nc])447# Winning condition448
449if bb > 57: #prevents moves greater than allowed number450break451#bb = ((red[i].num) + rolls[0 + nc]) - 57452
453kill(redbox,blue,yellow,green,bluehome,yellowhome,greenhome) #checks if a kill can be made.454
455red[i].x0 = redbox[bb].x456red[i].y0 = redbox[bb].y457red[i].x = redbox[bb].x + 25458red[i].y = redbox[bb].y + 25459red[i].swap()460red[i].num = bb461doublecheck(red) #checks if the gamepiece can be made as a double.462
463nc = nc + 1464if bb == 57:465# del red[i]466red.remove(red[i]);467
468if nc > len(rolls) - 1:469BLUE = True #next players turn.470RED = False471clear()472break473
474
475
476
477if BLUE == True and TURN == False: #same as REDS CODE478print("Blue's Turn")479print("moves available: ", rolls)480la="BLUE"481if (movecheck(blue, bluehome, bluebox, la)) == False:482print("NO MOVES SIR JEE")483BLUE = False484YELLOW = True485clear()486
487if BLUE == True:488
489for i in range(len(blue)):490if ((((cx > blue[i].x0 + 13) and (cx < blue[i].x + 13)) and (491(cy > blue[i].y0 + 14) and (cy < blue[i].y + 14)))492and (blue[i].x0 == bluehome[i].x) and (blue[i].y0 == bluehome[i].y)):493print("Interesting ")494
495if rolls[0 + nc] == 6:496
497blue[i].x0 = bluebox[0].x498blue[i].y0 = bluebox[0].y499blue[i].x = bluebox[0].x + 25500blue[i].y = bluebox[0].y + 25501blue[i].num = 0502blue[i].swap()503nc = nc + 1504
505if nc > len(rolls) - 1:506YELLOW = True507BLUE = False508clear()509break510
511if ((((cx > blue[i].x0 + 13) and (cx < blue[i].x + 13)) and (512(cy > blue[i].y0 + 14) and (cy < blue[i].y + 14)))513and ((blue[i].x0 > 270) or (blue[i].y0 < 470))):514print("Interesting ")515bb = ((blue[i].num) + rolls[0 + nc])516if bb > 57:517break518# bb= ((blue[i].num) + rolls[0 + nc]) - 52519
520kill(bluebox,red,yellow,green,redhome,yellowhome,greenhome)521
522blue[i].x0 = bluebox[bb].x523blue[i].y0 = bluebox[bb].y524blue[i].x = bluebox[bb].x + 25525blue[i].y = bluebox[bb].y + 25526blue[i].swap()527blue[i].num = bb528doublecheck(blue)529nc = nc + 1530if bb == 57:531# del red[i]532blue.remove(blue[i]);533
534if nc > len(rolls) - 1:535YELLOW = True536BLUE = False537clear()538break539
540
541
542if YELLOW == True and TURN == False: #Same as RED's code543print("Yellows's Turn")544print("moves available: ", rolls)545la="YELLOW"546if (movecheck(yellow, yellowhome, yellowbox,la)) == False:547print("NO MOVES SIR JEE")548YELLOW = False549GREEN = True550clear()551
552if YELLOW == True:553
554for i in range(len(yellow)):555if ((((cx > yellow[i].x0 + 13) and (cx < yellow[i].x + 13)) and (556(cy > yellow[i].y0 + 14) and (cy < yellow[i].y + 14)))557and (yellow[i].x0 == yellowhome[i].x) and (yellow[i].y0 == yellowhome[i].y)):558print("Interesting ")559
560if rolls[0 + nc] == 6:561
562yellow[i].x0 = yellowbox[0].x563yellow[i].y0 = yellowbox[0].y564yellow[i].x = yellowbox[0].x + 25565yellow[i].y = yellowbox[0].y + 25566yellow[i].num = 0567yellow[i].swap()568nc = nc + 1569
570if nc > len(rolls) - 1:571YELLOW = False572GREEN = True573clear()574break575
576if ((((cx > yellow[i].x0 + 13) and (cx < yellow[i].x + 13)) and (577(cy > yellow[i].y0 + 14) and (cy < yellow[i].y + 14)))578and ((yellow[i].x0 < 470) or (yellow[i].y0 < 470))):579print("Interesting ")580bb = ((yellow[i].num) + rolls[0 + nc])581if bb > 57:582break583#bb = ((yellow[i].num) + rolls[0 + nc]) - 52584
585kill(yellowbox,blue,red,green,bluehome,redhome,greenhome)586
587yellow[i].x0 = yellowbox[bb].x588yellow[i].y0 = yellowbox[bb].y589yellow[i].x = yellowbox[bb].x + 25590yellow[i].y = yellowbox[bb].y + 25591yellow[i].swap()592yellow[i].num = bb593doublecheck(yellow)594nc = nc + 1595if bb == 57:596# del red[i]597yellow.remove(yellow[i]);598
599if nc > len(rolls) - 1:600YELLOW = False601GREEN = True602clear()603break604
605
606
607
608if GREEN == True and TURN == False: #Same as RED's code609print("Green's Turn")610print("moves available: ", rolls)611la="GREEN"612if (movecheck(green, greenhome, greenbox,la)) == False:613print("NO MOVES SIR JEE")614GREEN = False615RED = True616clear()617
618if GREEN == True:619
620for i in range(len(green)):621if ((((cx > green[i].x0 + 13) and (cx < green[i].x + 13)) and (622(cy > green[i].y0 + 14) and (cy < green[i].y + 14)))623and (green[i].x0 == greenhome[i].x) and (green[i].y0 == greenhome[i].y)):624print("Interesting ")625
626if rolls[0 + nc] == 6:627
628green[i].x0 = greenbox[0].x629green[i].y0 = greenbox[0].y630green[i].x = greenbox[0].x + 25631green[i].y = greenbox[0].y + 25632green[i].num = 0633green[i].swap()634nc = nc + 1635print("green x.y: ", green[i].x0, green[i].y0)636
637if nc > len(rolls) - 1:638GREEN = False639RED = True640clear()641break642
643if ((((cx > green[i].x0 + 13) and (cx < green[i].x + 13)) and (644(cy > green[i].y0 + 14) and (cy < green[i].y + 14)))645and ((green[i].x0 < 470) or (green[i].y0 < 470))):646print("Interesting ")647bb = ((green[i].num) + rolls[0 + nc])648if bb > 57:649break650# bb = ((green[i].num) + rolls[0 + nc]) - 52651
652kill(greenbox,blue,yellow,red,bluehome,yellowhome,redhome)653
654green[i].x0 = greenbox[bb].x655green[i].y0 = greenbox[bb].y656green[i].x = greenbox[bb].x + 25657green[i].y = greenbox[bb].y + 25658green[i].swap()659green[i].num = bb660nc = nc + 1661doublecheck(green)662if bb == 57:663# del red[i]664green.remove(green[i]);665
666if nc > len(rolls) - 1:667GREEN = False668RED = True669clear()670break671
672
673main() #Main functin is called once when c==0 to intialize all the gamepieces.674
675
676def leftClick(event): # Main play function is called on every left click.677
678global c, cx, cy, RED, YELLOW679c = c + 1680cx = root.winfo_pointerx() - root.winfo_rootx() # This formula returns the x,y co-ordinates of the mouse pointer relative to the board.681cy = root.winfo_pointery() - root.winfo_rooty()682
683print("Click at: ", cx, cy)684
685main() #Main function called on every click to progress the game686
687
688root.bind("<Button-1>", leftClick)689
690
691def turn(): #Prints whoose turn is it692
693if RED == True:694L2 = Label(root, text=" Red's Turn ", fg='Black', background='green', font=("Arial", 24, "bold"))695L2.place(x=770, y=50)696
697if BLUE == True:698L2 = Label(root, text=" Blue's Turn ", fg='Black', background='green', font=("Arial", 24, "bold"))699L2.place(x=770, y=50)700
701if GREEN == True:702L2 = Label(root, text="Green's Turn ", fg='Black', background='green', font=("Arial", 24, "bold"))703L2.place(x=770, y=50)704
705if YELLOW == True:706L2 = Label(root, text="Yellow's Turn", fg='Black', background='green', font=("Arial", 24, "bold"))707L2.place(x=770, y=50)708
709
710def roll(): #Rolling function that rolls a dice, goes again if its a six711global rollc, dice, dice1, dice2, TURN, rolls712
713if TURN == True:714
715rollc = rollc + 1716print("roll: ", rollc)717
718if rollc == 1:719dice = random.randint(1, 6)720L1 = Label(root, text=dice, fg='Black', background='green', font=("Arial", 24, "bold"))721L1.place(x=800, y=200)722print("dice: ", dice)723rolls.append(dice)724if dice != 6:725rollc = 0726TURN = False727
728if rollc == 2:729if dice == 6:730dice1 = random.randint(1, 6)731L3 = Label(root, text=dice1, fg='Black', background='green', font=("Arial", 24, "bold"))732L3.place(x=800, y=250)733rolls.append(dice1)734if dice1 != 6:735rollc = 0736TURN = False737
738if rollc == 3:739if dice1 == 6:740dice2 = random.randint(1, 6)741L4 = Label(root, text=dice2, fg='Black', background='green', font=("Arial", 24, "bold"))742L4.place(x=800, y=300)743rolls.append(dice2)744rollc = 0745TURN = False746
747
748def clear(): #clears all the variable prior to next player's turn749global nc, rolls, TURN, L1, L3, L4750nc = 0751del rolls[:]752TURN = True753L1 = Label(root, text=" ", fg='Black', background='green', font=("Arial", 24, "bold"))754L1.place(x=800, y=200)755L3 = Label(root, text=" ", fg='Black', background='green', font=("Arial", 24, "bold"))756L3.place(x=800, y=250)757L4 = Label(root, text=" ", fg='Black', background='green', font=("Arial", 24, "bold"))758L4.place(x=800, y=300)759print("cleared")760turn()761
762
763def movecheck(r, rh, rb, la): #Check if the player can make a move764
765if (dice == 6 and dice1 == 6 and dice2 == 6):766return False767
768win=True #Checking if the game is won or the player can make any moves.769for j in range(4):770if (r[j].x0 != rb[56].x) and (r[j].y0 != rb[56].y):771win=False772
773if win == True: #If all gamepieces home, prints that the player has won774print("YOU HAVE WON")775L2 = Label(root, text=(la + "Wins"), fg='Black', background='green', font=("Arial", 24, "bold"))776L2.place(x=770, y=500)777return False778
779if win == False and dice != 6: #if its not a 6 and all game pieces inside home, then next players turn780for i in range(len(r)):781if(r[i].num != -1):782(print("Move Ahead"))783return True784print("All Cleared")785return False786
787def kill(a,b,c,d,bh,ch,dh): #function that determines if a gamepiece can be killed788
789#if the game piece is not on a stop790if ((a[bb].x0 != box[1].x and a[bb].y0 != box[1].y) and (a[bb].x0 != box[14].x and a[bb].y0 != box[14].y) and791(a[bb].x0 != box[9].x and a[bb].y0 != box[9].y) and (a[bb].x0 != box[22].x and a[bb].y0 != box[22].y) and792(a[bb].x0 != box[27].x and a[bb].y0 != box[27].y) and (a[bb].x0 != box[35].x and a[bb].y0 != box[35].y) and793(a[bb].x0 != box[40].x and a[bb].y0 != box[40].y) and (a[bb].x0 != box[48].x and a[bb].y0 != box[48].y)):794
795
796#if the game piece of another color and its on the same block and it is not a double, a kill is made797for i in range (len(b)):798if (b[i].x0 == a[bb].x and b[i].y0 == a[bb].y and (b[i].double == False)):799b[i].x0 = bh[i].x800b[i].y0 = bh[i].y801b[i].x = bh[i].x + 25802b[i].y = bh[i].y + 25803b[i].num=-1804b[i].swap()805break806
807for i in range (len(c)):808if (c[i].x0 == a[bb].x and c[i].y0 == a[bb].y and (c[i].double == False)):809c[i].x0 = ch[i].x810c[i].y0 = ch[i].y811c[i].x = ch[i].x + 25812c[i].y = ch[i].y + 25813c[i].num=-1814c[i].swap()815break816
817for i in range (len(d)):818if (d[i].x0 == a[bb].x and d[i].y0 == a[bb].y and (d[i].double == False)):819d[i].x0 = dh[i].x820d[i].y0 = dh[i].y821d[i].x = dh[i].x + 25822d[i].y = dh[i].y + 25823d[i].num=-1824d[i].swap()825break826
827def doublecheck(a):828
829for k in range (len(a)):830a[k].double = False831
832for i in range (len(a)):833for j in range (len(a)):834if (a[i].num == a[j].num) and (i != j):835a[j].double = True836a[i].double = True837
838
839turn() #prints the "red player's turn" initially840
841button = Button(root, text=" ROLL ", relief="raised", font=("Arial", 20),842command=roll) # call roll function evertime this button is clicked843button.place(x=805, y=120)844
845root.mainloop()846