├── Browng.gif ├── Instructions.docx ├── Ludo Board.gif ├── Ludo Board.jpg ├── Ludo-game.py ├── Ludo.py ├── README.md ├── blue side.gif ├── blue.gif ├── bluebox.gif ├── bluestop.gif ├── bod.gif ├── center.gif ├── green side.gif ├── green.gif ├── greenbox.gif ├── greenstop.gif ├── head.gif ├── head1.gif ├── head2.gif ├── head3.gif ├── ludo_full_big.jpg ├── red side.gif ├── red.gif ├── redbox.gif ├── redstop.gif ├── tail.gif ├── tail1.gif ├── tail2.gif ├── tail3.gif ├── test.gif ├── whitebox.gif ├── yellow side.gif ├── yellow.gif ├── yellowbox.gif └── yellowstop.gif /Browng.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/Browng.gif -------------------------------------------------------------------------------- /Instructions.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/Instructions.docx -------------------------------------------------------------------------------- /Ludo Board.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/Ludo Board.gif -------------------------------------------------------------------------------- /Ludo Board.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/Ludo Board.jpg -------------------------------------------------------------------------------- /Ludo-game.py: -------------------------------------------------------------------------------- 1 | from tkinter import * # Tkinter is used as the GUI. 2 | from tkinter import messagebox 3 | import sys 4 | import os 5 | import random 6 | import tkinter.messagebox 7 | 8 | root = Tk() 9 | 10 | root.resizable(width=False, height=False) # The window size of the game. 11 | root.geometry('1000x750') 12 | root.configure(background='green') 13 | root.title("Checkers") 14 | 15 | logo = PhotoImage(file="whitebox.gif") # Loading all the image files that are required in the game. 16 | logo2 = PhotoImage(file="red side.gif") # Loading all the image files that are required in the game. 17 | logo3 = PhotoImage(file="red.gif") # Loading all the image files that are required in the game. 18 | logo4 = PhotoImage(file="blue side.gif") 19 | logo5 = PhotoImage(file="green side.gif") 20 | logo6 = PhotoImage(file="yellow side.gif") 21 | logo7 = PhotoImage(file="center.gif") 22 | logoxx = PhotoImage(file="test.gif") 23 | logog = PhotoImage(file="greenbox.gif") 24 | logogs = PhotoImage(file="greenstop.gif") 25 | logoy = PhotoImage(file="yellowbox.gif") 26 | logoys = PhotoImage(file="yellowstop.gif") 27 | logob = PhotoImage(file="bluebox.gif") 28 | logobs = PhotoImage(file="bluestop.gif") 29 | logor = PhotoImage(file="redbox.gif") 30 | logors = PhotoImage(file="redstop.gif") 31 | logoh = PhotoImage(file="head.gif") 32 | logot = PhotoImage(file="tail.gif") 33 | logoh1 = PhotoImage(file="head1.gif") 34 | logot1 = PhotoImage(file="tail1.gif") 35 | logoh2 = PhotoImage(file="head2.gif") 36 | logot2 = PhotoImage(file="tail2.gif") 37 | logoh3 = PhotoImage(file="head3.gif") 38 | logot3 = PhotoImage(file="tail3.gif") 39 | logoab= PhotoImage(file="blue.gif") 40 | logoay= PhotoImage(file="yellow.gif") 41 | logoag= PhotoImage(file="green.gif") 42 | 43 | Label(image=logo2, width=298, height=298).place(x=-1, y=-1) #setting up board images 44 | Label(image=logo4, width=300, height=300).place(x=(-2), y=(448)) 45 | Label(image=logo5, width=296, height=296).place(x=(450), y=(0)) 46 | Label(image=logo6, width=294, height=294).place(x=(450), y=(450)) 47 | Label(image=logo7, width=150, height=150).place(x=(298), y=(298)) 48 | 49 | c = 0 #initializing variable and flags that are to be used in the game 50 | lx = 0 51 | bb =0 52 | nc = 0 53 | rollc = 0 54 | rolls = [] 55 | RED = True 56 | BLUE = False 57 | GREEN = False 58 | YELLOW = False 59 | TURN = True 60 | REDKILL = False 61 | BLUEKILL = False 62 | GREENKILL = False 63 | YELLOWKILL = False 64 | 65 | 66 | def board(): #Drawing the board, piece by piece. 67 | 68 | #Splash Screen. 69 | tkinter.messagebox.showinfo(title=None, message="TO START GAME PRESS OKAY & TO EXIT PRESS CROSS UP IN THE WINDOW") 70 | v = 0 71 | z = 0 72 | 73 | while (v != 300): #Drawing White boxes 74 | z = 0 75 | while (z != 150): 76 | Label(image=logo, width=46, height=46).place(x=(300 + z), y=(0 + v)) 77 | z = z + 50 78 | v = v + 50 79 | 80 | z = 0 81 | v = 0 82 | while (v != 300): #Drawing White boxes 83 | z = 0 84 | while (z != 150): 85 | Label(image=logo, width=46, height=46).place(x=(0 + v), y=(300 + z)) 86 | z = z + 50 87 | v = v + 50 88 | 89 | ##################### 90 | 91 | v = 0 92 | z = 0 93 | 94 | while (v != 300): #Drawing White boxes 95 | z = 0 96 | while (z != 150): 97 | Label(image=logo, width=46, height=46).place(x=(300 + z), y=(450 + v)) 98 | z = z + 50 99 | v = v + 50 100 | 101 | z = 0 102 | v = 0 103 | while (v != 300): #Drawing White boxes 104 | z = 0 105 | while (z != 150): 106 | Label(image=logo, width=46, height=46).place(x=(450 + v), y=(300 + z)) 107 | z = z + 50 108 | v = v + 50 109 | 110 | v = 0 111 | while (v != 250): #Drawing Green boxes 112 | Label(image=logog, width=46, height=46).place(x=(350), y=(50 + v)) 113 | v = v + 50 114 | 115 | Label(image=logog, width=46, height=46).place(x=(300), y=(100)) 116 | Label(image=logogs, width=46, height=46).place(x=(400), y=(50)) 117 | 118 | v = 0 119 | while (v != 250): #Drawing Yellow boxes 120 | Label(image=logoy, width=46, height=46).place(x=(450 + v), y=(350)) 121 | v = v + 50 122 | 123 | Label(image=logoy, width=46, height=46).place(x=(600), y=(300)) 124 | Label(image=logoys, width=46, height=46).place(x=(650), y=(400)) 125 | 126 | v = 0 127 | while (v != 250): #Drawing Red Boxes 128 | Label(image=logor, width=46, height=46).place(x=(50 + v), y=(350)) 129 | v = v + 50 130 | 131 | Label(image=logor, width=46, height=46).place(x=(100), y=(400)) 132 | Label(image=logors, width=46, height=46).place(x=(50), y=(300)) 133 | 134 | v = 0 135 | while (v != 250): #Drawing Blue Boxes 136 | Label(image=logob, width=46, height=46).place(x=(350), y=(450 + v)) 137 | v = v + 50 138 | 139 | Label(image=logobs, width=46, height=46).place(x=(300), y=(650)) 140 | Label(image=logob, width=46, height=46).place(x=(400), y=(600)) 141 | 142 | Label(image=logoh, width=46, height=46).place(x=250, y=400) #Drawing arrows 143 | Label(image=logot, width=46, height=46).place(x=300, y=450) 144 | Label(image=logoh1, width=46, height=46).place(x=400, y=450) 145 | Label(image=logot1, width=46, height=46).place(x=450, y=400) 146 | Label(image=logoh2, width=46, height=46).place(x=450, y=300) 147 | Label(image=logot2, width=46, height=46).place(x=400, y=250) 148 | Label(image=logoh3, width=46, height=46).place(x=300, y=250) 149 | Label(image=logot3, width=46, height=46).place(x=250, y=300) 150 | 151 | class YBox: #Class of yellow box 152 | rap = None 153 | 154 | def __init__(self, num=-1, x=0, y=0, x0=0, y0=0, double=False, ): 155 | self.num = num #no of gamepiece acc to box 156 | self.x = x #initial and final co-ordinates of the boxes 157 | self.y = y 158 | self.x0 = x0 159 | self.y0 = y0 160 | self.rap = Label(image=logoay, width=20, height=20) #image of game piece. 161 | self.double = double #if one game piece on top of another. 162 | 163 | def swap(self): #Swaps the position of gamepiece according to the number on dice. 164 | self.rap.place(x=self.x0 + 13, y=self.y0 + 14) 165 | 166 | class GBox: #Class of green box 167 | rap = None 168 | 169 | def __init__(self, num=-1, x=0, y=0, x0=0, y0=0, double=False, ): 170 | self.num = num 171 | self.x = x 172 | self.y = y 173 | self.x0 = x0 174 | self.y0 = y0 175 | self.rap = Label(image=logoag, width=20, height=20) 176 | self.double = double 177 | 178 | def swap(self): 179 | self.rap.place(x=self.x0 + 13, y=self.y0 + 14) 180 | 181 | class BBox: #Class of Blue box 182 | rap = None 183 | 184 | def __init__(self, num=-1, x=0, y=0, x0=0, y0=0, double=False, ): 185 | self.num = num 186 | self.x = x 187 | self.y = y 188 | self.x0 = x0 189 | self.y0 = y0 190 | self.rap = Label(image=logoab, width=20, height=20) 191 | self.double = double 192 | 193 | def swap(self): 194 | self.rap.place(x=self.x0 + 13, y=self.y0 + 14) 195 | 196 | class Box: #class of red box 197 | rap = None 198 | 199 | def __init__(self, num=-1, x=0, y=0, x0=0, y0=0, double=False, ): 200 | self.num = num 201 | self.x = x 202 | self.y = y 203 | self.x0 = x0 204 | self.y0 = y0 205 | self.rap = Label(image=logo3, width=20, height=20) 206 | self.double = double 207 | 208 | def swap(self): 209 | self.rap.place(x=self.x0 + 13, y=self.y0 + 14) 210 | 211 | 212 | def main(): # Main game function. 213 | 214 | global box, redbox, bluebox, greenbox, yellowbox, redhome, bluehome, yellowhome, greenhome 215 | global red, blue, yellow, green, rap, RED, BLUE, GREEN, YELLOW, dice, nc, TURN, bb 216 | 217 | if c == 0: #constructs the game pieces first time the code is ran. 218 | 219 | board() 220 | 221 | box = [Box() for i in range(52)] # list of co-ordinates of all the outer boxes 222 | 223 | redbox = [Box() for i in range(57)] # list of co-ordinates of all the colored boxes, excluding home and stop. 224 | bluebox = [Box() for i in range(57)] 225 | greenbox = [Box() for i in range(57)] 226 | yellowbox = [Box() for i in range(57)] 227 | 228 | redhome = [Box() for i in range(4)] # list co-ordinates of all the home positions 229 | bluehome = [Box() for i in range(4)] 230 | greenhome = [Box() for i in range(4)] 231 | yellowhome = [Box() for i in range(4)] 232 | 233 | red = [Box() for i in range(4)] # list of co-ordinates of all the game pieces in their initial state 234 | blue = [BBox() for i in range(4)] # that is equal to their respective home co-ordinates. 235 | green = [GBox() for i in range(4)] 236 | yellow = [YBox() for i in range(4)] 237 | 238 | for i in range(2): #Populates list of homeboxes, colored boxes, gamepieces and white boxes 239 | redhome[i].x = (100 + (100 * i)) 240 | redhome[i].y = 100 241 | red[i].x0 = redhome[i].x 242 | red[i].y0 = redhome[i].y 243 | red[i].x = (red[i].x0) + 25 244 | red[i].y = (red[i].y0) + 25 245 | 246 | bluehome[i].x = (100 + (100 * i)) 247 | bluehome[i].y = (550) 248 | blue[i].x0 = bluehome[i].x 249 | blue[i].y0 = bluehome[i].y 250 | blue[i].x = (blue[i].x0) + 25 251 | blue[i].y = (blue[i].y0) + 25 252 | 253 | yellowhome[i].x = (550 + (100 * i)) 254 | yellowhome[i].y = (550) 255 | yellow[i].x0 = yellowhome[i].x 256 | yellow[i].y0 = yellowhome[i].y 257 | yellow[i].x = (yellow[i].x0) + 25 258 | yellow[i].y = (yellow[i].y0) + 25 259 | 260 | greenhome[i].x = (550 + (100 * i)) 261 | greenhome[i].y = (100) 262 | green[i].x0 = greenhome[i].x 263 | green[i].y0 = greenhome[i].y 264 | green[i].x = (green[i].x0) + 25 265 | green[i].y = (green[i].y0) + 25 266 | 267 | for i in range(2, 4): 268 | redhome[i].x = (100 + (100 * (i - 2))) 269 | redhome[i].y = 200 270 | red[i].x0 = redhome[i].x 271 | red[i].y0 = redhome[i].y 272 | red[i].x = (red[i].x0) + 25 273 | red[i].y = (red[i].y0) + 25 274 | 275 | bluehome[i].x = (100 + (100 * (i - 2))) 276 | bluehome[i].y = (650) 277 | blue[i].x0 = bluehome[i].x 278 | blue[i].y0 = bluehome[i].y 279 | blue[i].x = (blue[i].x0) + 25 280 | blue[i].y = (blue[i].y0) + 25 281 | 282 | yellowhome[i].x = (550 + (100 * (i - 2))) 283 | yellowhome[i].y = (650) 284 | yellow[i].x0 = yellowhome[i].x 285 | yellow[i].y0 = yellowhome[i].y 286 | yellow[i].x = (yellow[i].x0) + 25 287 | yellow[i].y = (yellow[i].y0) + 25 288 | 289 | greenhome[i].x = (550 + (100 * (i - 2))) 290 | greenhome[i].y = 200 291 | green[i].x0 = greenhome[i].x 292 | green[i].y0 = greenhome[i].y 293 | green[i].x = (green[i].x0) + 25 294 | green[i].y = (green[i].y0) + 25 295 | 296 | for i in range(6): 297 | box[i].x = 300 298 | box[i].y = (700 - (50 * i)) 299 | 300 | for i in range(6, 12): 301 | box[i].x = (250 - (50 * (i - 6))) 302 | box[i].y = (400) 303 | 304 | box[12].x = 0 305 | box[12].y = 350 306 | 307 | for i in range(13, 19): 308 | box[i].x = (0 + (50 * (i - 13))) 309 | box[i].y = (300) 310 | 311 | for i in range(19, 25): 312 | box[i].x = (300) 313 | box[i].y = (250 - (50 * (i - 19))) 314 | 315 | box[25].x = 350 316 | box[25].y = 0 317 | 318 | for i in range(26, 32): 319 | box[i].x = (400) 320 | box[i].y = (0 + (50 * (i - 26))) 321 | 322 | for i in range(32, 38): 323 | box[i].x = (450 + (50 * (i - 32))) 324 | box[i].y = (300) 325 | 326 | box[38].x = 700 327 | box[38].y = 350 328 | 329 | for i in range(39, 45): 330 | box[i].x = (700 - (50 * (i - 39))) 331 | box[i].y = (400) 332 | 333 | for i in range(45, 51): 334 | box[i].x = (400) 335 | box[i].y = (450 + (50 * (i - 45))) 336 | 337 | box[51].x = 350 338 | box[51].y = 700 339 | 340 | # teshh 341 | lx = 14 342 | for i in range(52): 343 | redbox[i].x = box[lx].x 344 | redbox[i].y = box[lx].y 345 | lx = lx + 1 346 | if lx > 51: 347 | lx = 0 348 | 349 | lx = 50 350 | for i in range(7): 351 | redbox[lx].x = (0 + (50 * i)) 352 | redbox[lx].y = 350 353 | lx = lx + 1 354 | # blue 355 | lx = 1 356 | for i in range(52): 357 | 358 | bluebox[i].x = box[lx].x 359 | bluebox[i].y = box[lx].y 360 | lx = lx + 1 361 | if lx > 51: 362 | lx = 0 363 | 364 | lx = 50 365 | for i in range(7): 366 | bluebox[lx].x = 350 367 | bluebox[lx].y = (700 - (50 * i)) 368 | lx = lx + 1 369 | # yellow 370 | lx = 40 371 | for i in range(52): 372 | yellowbox[i].x = box[lx].x 373 | yellowbox[i].y = box[lx].y 374 | lx = lx + 1 375 | if lx > 51: 376 | lx = 0 377 | 378 | lx = 50 379 | for i in range(7): 380 | yellowbox[lx].x = (700 - (50 * i)) 381 | yellowbox[lx].y = (350) 382 | lx = lx + 1 383 | 384 | # green 385 | lx = 27 386 | for i in range(52): 387 | 388 | greenbox[i].x = box[lx].x 389 | greenbox[i].y = box[lx].y 390 | 391 | lx = lx + 1 392 | if lx > 51: 393 | lx = 0 394 | 395 | lx = 50 396 | for i in range(7): 397 | greenbox[lx].x = 350 398 | greenbox[lx].y = (0 + (50 * i)) 399 | lx = lx + 1 400 | 401 | for i in range(4): 402 | red[i].swap() 403 | blue[i].swap() 404 | green[i].swap() 405 | yellow[i].swap() #Population of all list is completed. Now game can begin 406 | 407 | 408 | else: # HERE ALL THE GAME OCCURS ... IF WAGHAIRA, MOVEMENT IDHAR HOGI !!! 409 | 410 | if c >= 1: #This condition is true when a click is made. 411 | 412 | if RED == True and TURN == False: #Red players turn 413 | print("Red's Turn") 414 | print("moves available: ", rolls) 415 | la = "RED" 416 | if (movecheck(red, redhome, redbox, la)) == False: #Checks if player can take a turn. 417 | BLUE = True 418 | RED = False 419 | clear() #clears variable, next players turn 420 | 421 | if RED == True: # searches if click is made on a red game piece. 422 | for i in range(len(red)): 423 | if ((((cx > red[i].x0 + 13) and (cx < red[i].x + 13)) and ( 424 | (cy > red[i].y0 + 14) and (cy < red[i].y + 14))) 425 | and (red[i].x0 == redhome[i].x) and (red[i].y0 == redhome[i].y)): 426 | print("woila ") 427 | 428 | if rolls[0 + nc] == 6: #If a six occurs and gamepiece is in home 429 | #Game piece is moved onto the home box 430 | red[i].x0 = redbox[0].x 431 | red[i].y0 = redbox[0].y 432 | red[i].x = redbox[0].x + 25 433 | red[i].y = redbox[0].y + 25 434 | red[i].num = 0 435 | red[i].swap() 436 | nc = nc + 1 437 | 438 | if nc > len(rolls) - 1: # check if all moves are made. so next players turn. 439 | BLUE = True 440 | RED = False 441 | clear() 442 | break 443 | 444 | if ((((cx > red[i].x0 + 13) and (cx < red[i].x + 13)) and ( #if gamepiece is outside home 445 | (cy > red[i].y0 + 14) and (cy < red[i].y + 14))) 446 | and ((red[i].x0 > 270) or (red[i].y0 > 270))): 447 | print("woila ") 448 | bb = ((red[i].num) + rolls[0 + nc]) 449 | # Winning condition 450 | 451 | if bb > 57: #prevents moves greater than allowed number 452 | break 453 | #bb = ((red[i].num) + rolls[0 + nc]) - 57 454 | 455 | kill(redbox,blue,yellow,green,bluehome,yellowhome,greenhome) #checks if a kill can be made. 456 | 457 | red[i].x0 = redbox[bb].x 458 | red[i].y0 = redbox[bb].y 459 | red[i].x = redbox[bb].x + 25 460 | red[i].y = redbox[bb].y + 25 461 | red[i].swap() 462 | red[i].num = bb 463 | doublecheck(red) #checks if the gamepiece can be made as a double. 464 | 465 | nc = nc + 1 466 | if bb == 57: #checks if game has traversed all the blocks 467 | # del red[i] 468 | red.remove(red[i]); 469 | 470 | if nc > len(rolls) - 1: 471 | BLUE = True #next players turn. 472 | RED = False 473 | clear() 474 | break 475 | 476 | 477 | # BLUES TURN!!!!!!!!!!!!!!!!!!!! 478 | 479 | if BLUE == True and TURN == False: #same as REDS CODE 480 | print("Blue's Turn") 481 | print("moves available: ", rolls) 482 | la="BLUE" 483 | if (movecheck(blue, bluehome, bluebox, la)) == False: 484 | print("NO MOVES SIR JEE") 485 | BLUE = False 486 | YELLOW = True 487 | clear() 488 | 489 | if BLUE == True: 490 | 491 | for i in range(len(blue)): 492 | if ((((cx > blue[i].x0 + 13) and (cx < blue[i].x + 13)) and ( 493 | (cy > blue[i].y0 + 14) and (cy < blue[i].y + 14))) 494 | and (blue[i].x0 == bluehome[i].x) and (blue[i].y0 == bluehome[i].y)): 495 | print("woila ") 496 | 497 | if rolls[0 + nc] == 6: 498 | 499 | blue[i].x0 = bluebox[0].x 500 | blue[i].y0 = bluebox[0].y 501 | blue[i].x = bluebox[0].x + 25 502 | blue[i].y = bluebox[0].y + 25 503 | blue[i].num = 0 504 | blue[i].swap() 505 | nc = nc + 1 506 | 507 | if nc > len(rolls) - 1: 508 | YELLOW = True 509 | BLUE = False 510 | clear() 511 | break 512 | 513 | if ((((cx > blue[i].x0 + 13) and (cx < blue[i].x + 13)) and ( 514 | (cy > blue[i].y0 + 14) and (cy < blue[i].y + 14))) 515 | and ((blue[i].x0 > 270) or (blue[i].y0 < 470))): 516 | print("woila ") 517 | bb = ((blue[i].num) + rolls[0 + nc]) 518 | if bb > 57: 519 | break 520 | # bb= ((blue[i].num) + rolls[0 + nc]) - 52 521 | 522 | kill(bluebox,red,yellow,green,redhome,yellowhome,greenhome) 523 | 524 | blue[i].x0 = bluebox[bb].x 525 | blue[i].y0 = bluebox[bb].y 526 | blue[i].x = bluebox[bb].x + 25 527 | blue[i].y = bluebox[bb].y + 25 528 | blue[i].swap() 529 | blue[i].num = bb 530 | doublecheck(blue) 531 | nc = nc + 1 532 | if bb == 57: 533 | # del red[i] 534 | blue.remove(blue[i]); 535 | 536 | if nc > len(rolls) - 1: 537 | YELLOW = True 538 | BLUE = False 539 | clear() 540 | break 541 | 542 | # YELLOWS TURN!!!!!!!!!!!!!!!!!!!! 543 | 544 | if YELLOW == True and TURN == False: #Same as RED's code 545 | print("Yellows's Turn") 546 | print("moves available: ", rolls) 547 | la="YELLOW" 548 | if (movecheck(yellow, yellowhome, yellowbox,la)) == False: 549 | print("NO MOVES SIR JEE") 550 | YELLOW = False 551 | GREEN = True 552 | clear() 553 | 554 | if YELLOW == True: 555 | 556 | for i in range(len(yellow)): 557 | if ((((cx > yellow[i].x0 + 13) and (cx < yellow[i].x + 13)) and ( 558 | (cy > yellow[i].y0 + 14) and (cy < yellow[i].y + 14))) 559 | and (yellow[i].x0 == yellowhome[i].x) and (yellow[i].y0 == yellowhome[i].y)): 560 | print("woila ") 561 | 562 | if rolls[0 + nc] == 6: 563 | 564 | yellow[i].x0 = yellowbox[0].x 565 | yellow[i].y0 = yellowbox[0].y 566 | yellow[i].x = yellowbox[0].x + 25 567 | yellow[i].y = yellowbox[0].y + 25 568 | yellow[i].num = 0 569 | yellow[i].swap() 570 | nc = nc + 1 571 | 572 | if nc > len(rolls) - 1: 573 | YELLOW = False 574 | GREEN = True 575 | clear() 576 | break 577 | 578 | if ((((cx > yellow[i].x0 + 13) and (cx < yellow[i].x + 13)) and ( 579 | (cy > yellow[i].y0 + 14) and (cy < yellow[i].y + 14))) 580 | and ((yellow[i].x0 < 470) or (yellow[i].y0 < 470))): 581 | print("woila ") 582 | bb = ((yellow[i].num) + rolls[0 + nc]) 583 | if bb > 57: 584 | break 585 | #bb = ((yellow[i].num) + rolls[0 + nc]) - 52 586 | 587 | kill(yellowbox,blue,red,green,bluehome,redhome,greenhome) 588 | 589 | yellow[i].x0 = yellowbox[bb].x 590 | yellow[i].y0 = yellowbox[bb].y 591 | yellow[i].x = yellowbox[bb].x + 25 592 | yellow[i].y = yellowbox[bb].y + 25 593 | yellow[i].swap() 594 | yellow[i].num = bb 595 | doublecheck(yellow) 596 | nc = nc + 1 597 | if bb == 57: 598 | # del red[i] 599 | yellow.remove(yellow[i]); 600 | 601 | if nc > len(rolls) - 1: 602 | YELLOW = False 603 | GREEN = True 604 | clear() 605 | break 606 | 607 | 608 | # GREENS TURN!!!!!!!!!!!!!!!!!!!! 609 | 610 | if GREEN == True and TURN == False: #Same as RED's code 611 | print("Green's Turn") 612 | print("moves available: ", rolls) 613 | la="GREEN" 614 | if (movecheck(green, greenhome, greenbox,la)) == False: 615 | print("NO MOVES SIR JEE") 616 | GREEN = False 617 | RED = True 618 | clear() 619 | 620 | if GREEN == True: 621 | 622 | for i in range(len(green)): 623 | if ((((cx > green[i].x0 + 13) and (cx < green[i].x + 13)) and ( 624 | (cy > green[i].y0 + 14) and (cy < green[i].y + 14))) 625 | and (green[i].x0 == greenhome[i].x) and (green[i].y0 == greenhome[i].y)): 626 | print("woila ") 627 | 628 | if rolls[0 + nc] == 6: 629 | 630 | green[i].x0 = greenbox[0].x 631 | green[i].y0 = greenbox[0].y 632 | green[i].x = greenbox[0].x + 25 633 | green[i].y = greenbox[0].y + 25 634 | green[i].num = 0 635 | green[i].swap() 636 | nc = nc + 1 637 | print("green x.y: ", green[i].x0, green[i].y0) 638 | 639 | if nc > len(rolls) - 1: 640 | GREEN = False 641 | RED = True 642 | clear() 643 | break 644 | 645 | if ((((cx > green[i].x0 + 13) and (cx < green[i].x + 13)) and ( 646 | (cy > green[i].y0 + 14) and (cy < green[i].y + 14))) 647 | and ((green[i].x0 < 470) or (green[i].y0 < 470))): 648 | print("woila ") 649 | bb = ((green[i].num) + rolls[0 + nc]) 650 | if bb > 57: 651 | break 652 | # bb = ((green[i].num) + rolls[0 + nc]) - 52 653 | 654 | kill(greenbox,blue,yellow,red,bluehome,yellowhome,redhome) 655 | 656 | green[i].x0 = greenbox[bb].x 657 | green[i].y0 = greenbox[bb].y 658 | green[i].x = greenbox[bb].x + 25 659 | green[i].y = greenbox[bb].y + 25 660 | green[i].swap() 661 | green[i].num = bb 662 | nc = nc + 1 663 | doublecheck(green) 664 | if bb == 57: 665 | # del red[i] 666 | green.remove(green[i]); 667 | 668 | if nc > len(rolls) - 1: 669 | GREEN = False 670 | RED = True 671 | clear() 672 | break 673 | 674 | 675 | main() #Main functin is called once when c==0 to intialize all the gamepieces. 676 | 677 | 678 | def leftClick(event): # Main play function is called on every left click. 679 | 680 | global c, cx, cy, RED, YELLOW 681 | c = c + 1 682 | cx = root.winfo_pointerx() - root.winfo_rootx() # This formula returns the x,y co-ordinates of the mouse pointer relative to the board. 683 | cy = root.winfo_pointery() - root.winfo_rooty() 684 | 685 | print("Click at: ", cx, cy) 686 | 687 | main() #Main function called on every click to progress the game 688 | 689 | 690 | root.bind("", leftClick) 691 | 692 | 693 | def turn(): #Prints whoose turn is it 694 | 695 | if RED == True: 696 | L2 = Label(root, text=" Red's Turn ", fg='Black', background='green', font=("Arial", 24, "bold")) 697 | L2.place(x=770, y=50) 698 | 699 | if BLUE == True: 700 | L2 = Label(root, text=" Blue's Turn ", fg='Black', background='green', font=("Arial", 24, "bold")) 701 | L2.place(x=770, y=50) 702 | 703 | if GREEN == True: 704 | L2 = Label(root, text="Green's Turn ", fg='Black', background='green', font=("Arial", 24, "bold")) 705 | L2.place(x=770, y=50) 706 | 707 | if YELLOW == True: 708 | L2 = Label(root, text="Yellow's Turn", fg='Black', background='green', font=("Arial", 24, "bold")) 709 | L2.place(x=770, y=50) 710 | 711 | 712 | def roll(): #Rolling function that rolls a dice, goes again if its a six 713 | global rollc, dice, dice1, dice2, TURN, rolls 714 | 715 | if TURN == True: 716 | 717 | rollc = rollc + 1 718 | print("roll: ", rollc) 719 | 720 | if rollc == 1: 721 | dice = random.randint(1, 6) 722 | L1 = Label(root, text=dice, fg='Black', background='green', font=("Arial", 24, "bold")) 723 | L1.place(x=800, y=200) 724 | print("dice: ", dice) 725 | rolls.append(dice) 726 | if dice != 6: 727 | rollc = 0 728 | TURN = False 729 | 730 | if rollc == 2: 731 | if dice == 6: 732 | dice1 = random.randint(1, 6) 733 | L3 = Label(root, text=dice1, fg='Black', background='green', font=("Arial", 24, "bold")) 734 | L3.place(x=800, y=250) 735 | rolls.append(dice1) 736 | if dice1 != 6: 737 | rollc = 0 738 | TURN = False 739 | 740 | if rollc == 3: 741 | if dice1 == 6: 742 | dice2 = random.randint(1, 6) 743 | L4 = Label(root, text=dice2, fg='Black', background='green', font=("Arial", 24, "bold")) 744 | L4.place(x=800, y=300) 745 | rolls.append(dice2) 746 | rollc = 0 747 | TURN = False 748 | 749 | 750 | def clear(): #clears all the variable prior to next player's turn 751 | global nc, rolls, TURN, L1, L3, L4 752 | nc = 0 753 | del rolls[:] 754 | TURN = True 755 | L1 = Label(root, text=" ", fg='Black', background='green', font=("Arial", 24, "bold")) 756 | L1.place(x=800, y=200) 757 | L3 = Label(root, text=" ", fg='Black', background='green', font=("Arial", 24, "bold")) 758 | L3.place(x=800, y=250) 759 | L4 = Label(root, text=" ", fg='Black', background='green', font=("Arial", 24, "bold")) 760 | L4.place(x=800, y=300) 761 | print("cleared") 762 | turn() 763 | 764 | 765 | def movecheck(r, rh, rb, la): #Check if the player can make a move 766 | 767 | if (dice == 6 and dice1 == 6 and dice2 == 6): 768 | return False 769 | 770 | win=True #Checking if the game is won or the player can make any moves. 771 | for j in range(4): 772 | if (r[j].x0 != rb[56].x) and (r[j].y0 != rb[56].y): 773 | win=False 774 | 775 | if win == True: #If all gamepieces home, prints that the player has won 776 | print("YOU HAVE WON") 777 | L2 = Label(root, text=(la + "Wins"), fg='Black', background='green', font=("Arial", 24, "bold")) 778 | L2.place(x=770, y=500) 779 | return False 780 | 781 | if win == False and dice != 6: #if its not a 6 and all game pieces inside home, then next players turn 782 | for i in range(len(r)): 783 | if(r[i].num != -1): 784 | (print("good hai")) 785 | return True 786 | print("jani all in") 787 | return False 788 | 789 | def kill(a,b,c,d,bh,ch,dh): #function that determines if a gamepiece can be killed 790 | 791 | #if the game piece is not on a stop 792 | if ((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) and 793 | (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) and 794 | (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) and 795 | (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)): 796 | 797 | 798 | #if the game piece of another color and its on the same block and it is not a double, a kill is made 799 | for i in range (len(b)): 800 | if (b[i].x0 == a[bb].x and b[i].y0 == a[bb].y and (b[i].double == False)): 801 | b[i].x0 = bh[i].x 802 | b[i].y0 = bh[i].y 803 | b[i].x = bh[i].x + 25 804 | b[i].y = bh[i].y + 25 805 | b[i].num=-1 806 | b[i].swap() 807 | break 808 | 809 | for i in range (len(c)): 810 | if (c[i].x0 == a[bb].x and c[i].y0 == a[bb].y and (c[i].double == False)): 811 | c[i].x0 = ch[i].x 812 | c[i].y0 = ch[i].y 813 | c[i].x = ch[i].x + 25 814 | c[i].y = ch[i].y + 25 815 | c[i].num=-1 816 | c[i].swap() 817 | break 818 | 819 | for i in range (len(d)): 820 | if (d[i].x0 == a[bb].x and d[i].y0 == a[bb].y and (d[i].double == False)): 821 | d[i].x0 = dh[i].x 822 | d[i].y0 = dh[i].y 823 | d[i].x = dh[i].x + 25 824 | d[i].y = dh[i].y + 25 825 | d[i].num=-1 826 | d[i].swap() 827 | break 828 | 829 | def doublecheck(a): #makes a double is two or more gamepieces on top of another. 830 | 831 | for k in range (len(a)): 832 | a[k].double = False 833 | 834 | for i in range (len(a)): 835 | for j in range (len(a)): 836 | if (a[i].num == a[j].num) and (i != j): 837 | a[j].double = True 838 | a[i].double = True 839 | 840 | 841 | turn() #prints the "red player's turn" initially 842 | 843 | button = Button(root, text=" ROLL ", relief="raised", font=("Arial", 20), 844 | command=roll) # call roll function evertime this button is clicked 845 | button.place(x=805, y=120) 846 | 847 | root.mainloop() 848 | -------------------------------------------------------------------------------- /Ludo.py: -------------------------------------------------------------------------------- 1 | from tkinter import * #Tkinter is used as the GUI. 2 | import random 3 | root= Tk() 4 | 5 | #root.geometry('1000x1000') 6 | 7 | #base= PhotoImage(file= "ludo board.gif") 8 | 9 | #Label(root, image=base).pack(side="left") 10 | 11 | canvas = Canvas(width = 1000, height = 800, bg = 'yellow') 12 | root.resizable(width=False, height=False) 13 | 14 | canvas.pack(expand = YES, fill = BOTH) 15 | 16 | gif1 = PhotoImage(file = 'ludo board.gif') 17 | canvas.create_image(50, 10, image = gif1, anchor = NW) 18 | 19 | 20 | g3 = canvas.create_oval(50,290,80,320, outline="green", fill="green", tags="oval") 21 | #40, 380, 90, 430 22 | g4 = canvas.create_oval(50,390,80,420, outline="green", fill="green", tags="oval") 23 | 24 | drag_data = {"x": 0, "y": 0, "item": None} 25 | init_data = {"x": 0, "y": 0, "item": None} 26 | final_coordinate = [0, 0] 27 | 28 | 29 | def OnTokenButtonPress(event): 30 | # record the item and its location 31 | drag_data["item"] = canvas.find_closest(event.x, event.y)[0] 32 | drag_data["x"] = event.x 33 | drag_data["y"] = event.y 34 | 35 | init_data["item"] = drag_data["item"] # defining new destination 36 | init_data["x"] = drag_data["x"] 37 | init_data["y"] = drag_data["y"] 38 | 39 | item_below = canvas.find_overlapping(event.x, event.y, event.x, event.y)[0] 40 | 41 | 42 | 43 | 44 | # when the button is released 45 | # kindof a Destructor 46 | def OnTokenButtonRelease(event): 47 | # reset the drag information 48 | drag_data["item"] = None 49 | drag_data["x"] = 0 50 | drag_data["y"] = 0 51 | 52 | 53 | def OnTokenMotion(event): 54 | # compute how much this object has moved 55 | moved_x = event.x - drag_data["x"] 56 | moved_y = event.y - drag_data["y"] 57 | # new location of the dragged item 58 | 59 | 60 | # move the object the appropriate amount 61 | canvas.move(drag_data["item"], moved_x, moved_y) 62 | # record the new position 63 | drag_data["x"] = event.x 64 | drag_data["y"] = event.y 65 | if drag_data["x"]>=444 and drag_data["x"]<=582 and drag_data["y"]>=330 and drag_data["y"]<462: 66 | print ('pug gayi') 67 | 68 | # put gif image on canvas 69 | # pic's upper left corner (NW) on the canvas is at x=50 y=10 70 | #canvas.create_image(50, 10, image = gif1, anchor = NW) 71 | 72 | canvas.tag_bind("oval", "", OnTokenButtonPress) 73 | canvas.tag_bind("oval", "", OnTokenMotion) 74 | class RollTheDice: 75 | def __init__(self, parent): 76 | self.dieParent = parent 77 | self.dieContainer = Frame(parent).pack() 78 | 79 | self.dieLabel = Label(self.dieContainer, text="Number of Dice you will be rolling:") 80 | self.dieLabel.pack(side=TOP) 81 | 82 | self.dieEntry = Entry(self.dieContainer) 83 | self.dieEntry.pack(side=TOP) 84 | 85 | self.sideLabel = Label(self.dieContainer, text="Number of Sides per Die:") 86 | self.sideLabel.pack(side=TOP) 87 | 88 | self.sideEntry = Entry(self.dieContainer) 89 | self.sideEntry.pack(side=TOP) 90 | 91 | 92 | 93 | global rolldisp 94 | rolldisp = StringVar() 95 | self.rollResult = Label(self.dieContainer, textvariable=rolldisp) 96 | self.rollResult.pack(side=TOP) 97 | 98 | self.diceButton = Button(self.dieContainer) 99 | self.diceButton.configure(text="Roll the Dice!", background="orangered1") 100 | self.diceButton.pack(side=LEFT) 101 | self.diceButton.bind("", self.diceButtonClick) 102 | self.diceButton.bind("", self.diceButtonClick) 103 | 104 | self.quitButton = Button(self.dieContainer) 105 | self.quitButton.configure(text="Quit", background="blue") 106 | self.quitButton.pack(side=RIGHT) 107 | self.quitButton.bind("", self.quitButtonClick) 108 | self.quitButton.bind("", self.quitButtonClick) 109 | 110 | def diceButtonClick(self, event): 111 | die = int(self.dieEntry.get()) 112 | side = int(self.sideEntry.get()) 113 | DieRoll(die, side) 114 | 115 | def quitButtonClick(self, event): 116 | self.dieParent.destroy() 117 | 118 | def DieRoll(dice, sides): 119 | import random 120 | rollnumber = 1 121 | runningtotal = 0 122 | endresult = "" 123 | while rollnumber <= dice: 124 | roll = random.randint(1, sides) 125 | endresult += "Roll #" 126 | endresult += str(rollnumber) 127 | endresult += ": " 128 | endresult += str(roll) 129 | endresult += "\n" 130 | runningtotal += roll 131 | rollnumber += 1 132 | finalresult = "Your Roll:\n" 133 | finalresult += endresult 134 | rolldisp.set(finalresult) 135 | 136 | def leftClick(event): #Main play function is called on every left click. 137 | x = root.winfo_pointerx() #- root.winfo_rootx() # This formula returns the x,y co-ordinates of the mouse pointer relative to the board. 138 | y = root.winfo_pointery() # root.winfo_rooty() 139 | 140 | print("Click at: ",x,y) 141 | 142 | root.bind("", leftClick) 143 | 144 | root = Tk() 145 | root.title("Die Roller") 146 | myapp = RollTheDice(root) 147 | root.mainloop() -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ludo-Python-game- 2 | Ludo is a strategy board game for two to four[a] players, in which the players race their four tokens from start to finish according to rolls of a single die. 3 | 4 | I created this game back in 2016 during my third semester for my Computational Thinking 2 course. I created the game in Python using it's tkinter graphics library. 5 | 6 | Compile the Ludo-game.py file to play. 7 | 8 | INSTRUCTIONS 9 | 10 | • Unless you get a '6' when rolling the dice, your planes can't take off 11 | • Press the ROLL button to roll the dice. 12 | • If it is a 6, then you can take another turn. So press ROLL again. 13 | • Click the plane which you want to move the first ROLL. The plane will move itself according to the number of the dice. 14 | • If the plane lands on stop, it cannot be killed. 15 | • To kill another color’s plane, you have to make your plane land on that box where other colored plane is. 16 | • If there are two planes of the same color on top of each other than that plane cannot be killed. 17 | • To win the game, your planes have to traverse around the board and come into the home lane. 18 | • If a player gets 3 six’s in a row, than his/her turn is void and next players plays. 19 | • 20 | -------------------------------------------------------------------------------- /blue side.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/blue side.gif -------------------------------------------------------------------------------- /blue.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/blue.gif -------------------------------------------------------------------------------- /bluebox.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/bluebox.gif -------------------------------------------------------------------------------- /bluestop.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/bluestop.gif -------------------------------------------------------------------------------- /bod.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/bod.gif -------------------------------------------------------------------------------- /center.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/center.gif -------------------------------------------------------------------------------- /green side.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/green side.gif -------------------------------------------------------------------------------- /green.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/green.gif -------------------------------------------------------------------------------- /greenbox.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/greenbox.gif -------------------------------------------------------------------------------- /greenstop.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/greenstop.gif -------------------------------------------------------------------------------- /head.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/head.gif -------------------------------------------------------------------------------- /head1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/head1.gif -------------------------------------------------------------------------------- /head2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/head2.gif -------------------------------------------------------------------------------- /head3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/head3.gif -------------------------------------------------------------------------------- /ludo_full_big.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/ludo_full_big.jpg -------------------------------------------------------------------------------- /red side.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/red side.gif -------------------------------------------------------------------------------- /red.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/red.gif -------------------------------------------------------------------------------- /redbox.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/redbox.gif -------------------------------------------------------------------------------- /redstop.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/redstop.gif -------------------------------------------------------------------------------- /tail.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/tail.gif -------------------------------------------------------------------------------- /tail1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/tail1.gif -------------------------------------------------------------------------------- /tail2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/tail2.gif -------------------------------------------------------------------------------- /tail3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/tail3.gif -------------------------------------------------------------------------------- /test.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/test.gif -------------------------------------------------------------------------------- /whitebox.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/whitebox.gif -------------------------------------------------------------------------------- /yellow side.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/yellow side.gif -------------------------------------------------------------------------------- /yellow.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/yellow.gif -------------------------------------------------------------------------------- /yellowbox.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/yellowbox.gif -------------------------------------------------------------------------------- /yellowstop.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talalz94/Ludo-Python-game-/0293addda2e0ac3222f6a835557fe042cbc045d6/yellowstop.gif --------------------------------------------------------------------------------