-
Notifications
You must be signed in to change notification settings - Fork 5
/
Ludo_game_with_Sam.py
1153 lines (958 loc) · 66.2 KB
/
Ludo_game_with_Sam.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Ludo game with Sam #
from tkinter import *
from tkinter import messagebox
from PIL import Image,ImageTk
import time
from random import randint
class Ludo:
def __init__(self, root,six_side_block,five_side_block,four_side_block,three_side_block,two_side_block,one_side_block):
self.window = root
# Make canvas
self.make_canvas = Canvas(self.window, bg="#4d4dff", width=800, height=630)
self.make_canvas.pack(fill=BOTH,expand=1)
# Make some containers to store data
self.made_red_coin = []
self.made_green_coin = []
self.made_yellow_coin = []
self.made_sky_blue_coin = []
self.red_number_label = []
self.green_number_label = []
self.yellow_number_label = []
self.sky_blue_number_label = []
self.block_value_predict = []
self.total_people_play = []
# Ludo block all side image store
self.block_number_side = [one_side_block, two_side_block, three_side_block, four_side_block, five_side_block, six_side_block]
# Use for store specific position of all coins
self.red_coord_store = [-1, -1, -1, -1]
self.green_coord_store = [-1, -1, -1, -1]
self.yellow_coord_store = [-1, -1, -1, -1]
self.sky_blue_coord_store = [-1, -1, -1, -1]
self.red_coin_position = [0, 1, 2, 3]
self.green_coin_position = [0, 1, 2, 3]
self.yellow_coin_position = [0, 1, 2, 3]
self.sky_blue_coin_position = [0, 1, 2, 3]
for index in range(len(self.red_coin_position)):# Specific coin position set to -1 by default
self.red_coin_position[index] = -1
self.green_coin_position[index] = -1
self.yellow_coin_position[index] = -1
self.sky_blue_coin_position[index] = -1
# Number to room to be traverse by specific color coin, store in that variable
self.move_red_counter = 0
self.move_green_counter = 0
self.move_yellow_counter = 0
self.move_sky_blue_counter = 0
self.take_permission = 0
self.six_with_overlap = 0
self.red_store_active = 0
self.sky_blue_store_active = 0
self.yellow_store_active = 0
self.green_store_active = 0
self.six_counter = 0
self.time_for = -1
# Some variables initializes with None
self.right_star = None
self.down_star = None
self.left_star = None
self.up_star = None
# By default some function call
self.board_set_up()
self.instruction_btn_red()
self.instruction_btn_sky_blue()
self.instruction_btn_yellow()
self.instruction_btn_green()
self.take_initial_control()
def board_set_up(self):
# Cover Box made
self.make_canvas.create_rectangle(100, 15, 100 + (40 * 15), 15 + (40 * 15), width=6, fill="white")
# Square box
self.make_canvas.create_rectangle(100, 15, 100+240, 15+240, width=3, fill="red")# left up large square
self.make_canvas.create_rectangle(100, (15+240)+(40*3), 100+240, (15+240)+(40*3)+(40*6), width=3, fill="#04d9ff")# left down large square
self.make_canvas.create_rectangle(340+(40*3), 15, 340+(40*3)+(40*6), 15+240, width=3, fill="#00FF00")# right up large square
self.make_canvas.create_rectangle(340+(40*3), (15+240)+(40*3), 340+(40*3)+(40*6), (15+240)+(40*3)+(40*6), width=3, fill="yellow")# right down large square
# Left 3 box(In white region)
self.make_canvas.create_rectangle(100, (15+240), 100+240, (15+240)+40, width=3)
self.make_canvas.create_rectangle(100+40, (15 + 240)+40, 100 + 240, (15 + 240) + 40+40, width=3, fill="#F00000")
self.make_canvas.create_rectangle(100, (15 + 240)+80, 100 + 240, (15 + 240) + 80+40, width=3)
# right 3 box(In white region)
self.make_canvas.create_rectangle(100+240, 15, 100 + 240+40, 15 + (40*6), width=3)
self.make_canvas.create_rectangle(100+240+40, 15+40, 100+240+80, 15 + (40*6), width=3, fill="#00FF00")
self.make_canvas.create_rectangle(100+240+80, 15, 100 + 240+80+40, 15 + (40*6), width=3)
# up 3 box(In white region)
self.make_canvas.create_rectangle(340+(40*3), 15+240, 340+(40*3)+(40*6), 15+240+40, width=3)
self.make_canvas.create_rectangle(340+(40*3), 15+240+40, 340+(40*3)+(40*6)-40, 15+240+80, width=3, fill="yellow")
self.make_canvas.create_rectangle(340+(40*3), 15+240+80, 340+(40*3)+(40*6), 15+240+120, width=3)
# down 3 box(In white region)
self.make_canvas.create_rectangle(100, (15 + 240)+(40*3), 100 + 240+40, (15 + 240)+(40*3)+(40*6), width=3)
self.make_canvas.create_rectangle(100+240+40, (15 + 240)+(40*3), 100 + 240+40+40, (15 + 240)+(40*3)+(40*6)-40, width=3, fill="#04d9ff")
self.make_canvas.create_rectangle(100 + 240+40+40, (15 + 240)+(40*3), 100 + 240+40+40+40, (15 + 240)+(40*3)+(40*6), width=3)
# All left separation line
start_x = 100 + 40
start_y = 15 + 240
end_x = 100 + 40
end_y = 15 + 240 + (40 * 3)
for _ in range(5):
self.make_canvas.create_line(start_x, start_y, end_x, end_y, width=3)
start_x+=40
end_x+= 40
# All right separation line
start_x = 100+240+(40*3)+40
start_y = 15 + 240
end_x = 100+240+(40*3)+40
end_y = 15 + 240 + (40 * 3)
for _ in range(5):
self.make_canvas.create_line(start_x, start_y, end_x, end_y, width=3)
start_x += 40
end_x += 40
# All up separation done
start_x = 100+240
start_y = 15+40
end_x = 100+240+(40*3)
end_y = 15+40
for _ in range(5):
self.make_canvas.create_line(start_x, start_y, end_x, end_y, width=3)
start_y += 40
end_y += 40
# All down separation done
start_x = 100 + 240
start_y = 15 + (40*6)+(40*3)+40
end_x = 100 + 240 + (40 * 3)
end_y = 15 + (40*6)+(40*3)+40
for _ in range(5):
self.make_canvas.create_line(start_x, start_y, end_x, end_y, width=3)
start_y += 40
end_y += 40
# Square box(Coins containers) white region make
self.make_canvas.create_rectangle(100+20, 15+40-20, 100 + 40 + 60 + 40 +60+20, 15+40+40+40+100-20, width=3, fill="white")
self.make_canvas.create_rectangle(340+(40*3)+40 - 20, 15 + 40-20, 340+(40*3)+40 + 60 + 40 + 40+20+20, 15+40+40+40+100-20, width=3, fill="white")
self.make_canvas.create_rectangle(100+20, 340+80-20+15, 100 + 40 + 60 + 40 +60+20, 340+80+60+40+40+20+15, width=3, fill="white")
self.make_canvas.create_rectangle(340+(40*3)+40 - 20, 340 + 80 - 20+15, 340+(40*3)+40 + 60 + 40 + 40+20+20, 340 + 80 + 60 + 40 + 40 + 20+15, width=3, fill="white")
# Left up square inside box made
self.make_canvas.create_rectangle(100+40, 15+40, 100+40+40, 15+40+40, width=3, fill="red")
self.make_canvas.create_rectangle(100+40+60+60, 15 + 40, 100+40+60+40+60, 15 + 40 + 40, width=3, fill="red")
self.make_canvas.create_rectangle(100 + 40, 15 + 40+100, 100 + 40 + 40, 15 + 40 + 40+100, width=3, fill="red")
self.make_canvas.create_rectangle(100 + 40 + 60 + 60, 15 + 40+100, 100 + 40 + 60 + 40 +60, 15 + 40 + 40+100, width=3, fill="red")
# Right up square inside box made
self.make_canvas.create_rectangle(340+(40*3)+40, 15 + 40, 340+(40*3)+40 + 40, 15 + 40 + 40, width=3, fill="#00FF00")
self.make_canvas.create_rectangle(340+(40*3)+40+ 60 + 40+20, 15 + 40, 340+(40*3)+40 + 60 + 40 + 40+20, 15 + 40 + 40, width=3, fill="#00FF00")
self.make_canvas.create_rectangle(340+(40*3)+40, 15 + 40 + 100, 340+(40*3)+40 + 40, 15 + 40 + 40 + 100, width=3, fill="#00FF00")
self.make_canvas.create_rectangle(340+(40*3)+40+ 60 + 40+20, 15 + 40 + 100, 340+(40*3)+40 + 60 + 40 + 40+20, 15 + 40 + 40 + 100, width=3, fill="#00FF00")
# Left down square inside box made
self.make_canvas.create_rectangle(100 + 40, 340+80+15, 100 + 40 + 40, 340+80+40+15, width=3, fill="#04d9ff")
self.make_canvas.create_rectangle(100 + 40 + 60 + 40+20, 340+80+15, 100 + 40 + 60 + 40 + 40+20, 340+80+40+15, width=3, fill="#04d9ff")
self.make_canvas.create_rectangle(100 + 40, 340+80+60+40+15, 100 + 40 + 40, 340+80+60+40+40+15, width=3, fill="#04d9ff")
self.make_canvas.create_rectangle(100 + 40 + 60 + 40+20, 340+80+60+40+15, 100 + 40 + 60 + 40 + 40+20, 340+80+60+40+40+15, width=3, fill="#04d9ff")
# Right down square inside box made
self.make_canvas.create_rectangle(340 + (40 * 3) + 40, 340+80+15, 340 + (40 * 3) + 40 + 40, 340+80+40+15, width=3, fill="yellow")
self.make_canvas.create_rectangle(340 + (40 * 3) + 40 + 60 + 40+20, 340+80+15, 340 + (40 * 3) + 40 + 60 + 40 + 40+20, 340+80+40+15, width=3, fill="yellow")
self.make_canvas.create_rectangle(340 + (40 * 3) + 40, 340+80+60+40+15, 340 + (40 * 3) + 40 + 40,340+80+60+40+40+15, width=3, fill="yellow")
self.make_canvas.create_rectangle(340 + (40 * 3) + 40 + 60 + 40+20, 340+80+60+40+15,340 + (40 * 3) + 40 + 60 + 40 + 40+20, 340+80+60+40+40+15, width=3, fill="yellow")
# sky_blue start position
self.make_canvas.create_rectangle(100+240,340+(40*5)-5,100+240+40,340+(40*6)-5,fill="#04d9ff",width=3)
# Red start position
self.make_canvas.create_rectangle(100 + 40, 15+(40*6), 100 +40 + 40, 15+(40*6)+40, fill="red", width=3)
# Green start position
self.make_canvas.create_rectangle(100 + (40*8), 15 + 40, 100 +(40*9), 15 + 40+ 40, fill="#00FF00", width=3)
# Yellow start position
self.make_canvas.create_rectangle(100 + (40 * 6)+(40*3)+(40*4), 15 + (40*8), 100 + (40 * 6)+(40*3)+(40*5), 15 + (40*9), fill="yellow", width=3)
# Traingle in middle
self.make_canvas.create_polygon(100+240, 15+240, 100+240+60, 15+240+60, 100+240, 15+240+(40*3), width=3,fill="red",outline="black")
self.make_canvas.create_polygon(100 + 240+(40*3), 15 + 240, 100 + 240 + 60, 15 + 240 + 60, 100 + 240+(40*3), 15 + 240 + (40 * 3), width=3, fill="yellow",outline="black")
self.make_canvas.create_polygon(100 + 240, 15 + 240, 100 + 240 + 60, 15 + 240 + 60, 100 + 240 + (40 * 3), 15 + 240, width=3, fill="#00FF00",outline="black")
self.make_canvas.create_polygon(100 + 240, 15 + 240+(40*3), 100 + 240 + 60, 15 + 240 + 60, 100 + 240 + (40 * 3), 15 + 240+(40*3), width=3, fill="#04d9ff",outline="black")
# Make coin for red left up block
red_1_coin = self.make_canvas.create_oval(100+40, 15+40, 100+40+40, 15+40+40, width=3, fill="red", outline="black")
red_2_coin = self.make_canvas.create_oval(100+40+60+60, 15 + 40, 100+40+60+60+40, 15 + 40 + 40, width=3, fill="red", outline="black")
red_3_coin = self.make_canvas.create_oval(100 + 40 + 60 + 60, 15 + 40 + 100, 100 + 40 + 60 + 60 + 40, 15 + 40 + 40 + 100, width=3, fill="red", outline="black")
red_4_coin = self.make_canvas.create_oval(100 + 40, 15 + 40+100, 100 + 40 + 40, 15 + 40 + 40+100, width=3,fill="red", outline="black")
self.made_red_coin.append(red_1_coin)
self.made_red_coin.append(red_2_coin)
self.made_red_coin.append(red_3_coin)
self.made_red_coin.append(red_4_coin)
# Make coin under number label for red left up block
red_1_label = Label(self.make_canvas, text="1", font=("Arial", 15, "bold"), bg="red", fg="black")
red_1_label.place(x=100 + 40 + 10, y=15 + 40 + 5)
red_2_label = Label(self.make_canvas, text="2", font=("Arial", 15, "bold"), bg="red", fg="black")
red_2_label.place(x=100 + 40 + 60 + 60 + 10, y=15 + 40 + 5)
red_3_label = Label(self.make_canvas, text="3", font=("Arial", 15, "bold"), bg="red", fg="black")
red_3_label.place(x=100 + 40 + 60 + 60 + 10, y=15 + 40 + 100 + 5)
red_4_label = Label(self.make_canvas, text="4", font=("Arial", 15, "bold"), bg="red", fg="black")
red_4_label.place(x=100 + 40 + 10, y=15 + 40 + 100 + 5)
self.red_number_label.append(red_1_label)
self.red_number_label.append(red_2_label)
self.red_number_label.append(red_3_label)
self.red_number_label.append(red_4_label)
# Make coin for green right up block
green_1_coin = self.make_canvas.create_oval(340+(40*3)+40, 15 + 40, 340+(40*3)+40 + 40, 15 + 40 + 40, width=3, fill="#00FF00", outline="black")
green_2_coin = self.make_canvas.create_oval(340+(40*3)+40+ 60 + 40+20, 15 + 40, 340+(40*3)+40 + 60 + 40 + 40+20, 15 + 40 + 40, width=3, fill="#00FF00", outline="black")
green_3_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40 + 60 + 40 + 20, 15 + 40 + 100, 340 + (40 * 3) + 40 + 60 + 40 + 40 + 20, 15 + 40 + 40 + 100, width=3, fill="#00FF00", outline="black")
green_4_coin = self.make_canvas.create_oval(340+(40*3)+40, 15 + 40 + 100, 340+(40*3)+40 + 40, 15 + 40 + 40 + 100, width=3, fill="#00FF00", outline="black")
self.made_green_coin.append(green_1_coin)
self.made_green_coin.append(green_2_coin)
self.made_green_coin.append(green_3_coin)
self.made_green_coin.append(green_4_coin)
# Make coin under number label for green right up block
green_1_label = Label(self.make_canvas, text="1", font=("Arial", 15, "bold"), bg="#00FF00", fg="black")
green_1_label.place(x=340 + (40 * 3) + 40 + 10, y=15 + 40 + 5)
green_2_label = Label(self.make_canvas, text="2", font=("Arial", 15, "bold"), bg="#00FF00", fg="black")
green_2_label.place(x=340 + (40 * 3) + 40 + 40 + 60 + 30, y=15 + 40 + 5)
green_3_label = Label(self.make_canvas, text="3", font=("Arial", 15, "bold"), bg="#00FF00", fg="black")
green_3_label.place(x=340 + (40 * 3) + 40 + 40 + 60 + 30, y=15 + 40 + 100 + 5)
green_4_label = Label(self.make_canvas, text="4", font=("Arial", 15, "bold"), bg="#00FF00", fg="black")
green_4_label.place(x=340 + (40 * 3) + 40 + 10, y=15 + 40 + 100 + 5)
self.green_number_label.append(green_1_label)
self.green_number_label.append(green_2_label)
self.green_number_label.append(green_3_label)
self.green_number_label.append(green_4_label)
# Make coin for sky_blue left down block
sky_blue_1_coin = self.make_canvas.create_oval(100 + 40, 340+80+15, 100 + 40 + 40, 340+80+40+15, width=3, fill="#04d9ff", outline="black")
sky_blue_2_coin = self.make_canvas.create_oval(100 + 40 + 60 + 40+20, 340+80+15, 100 + 40 + 60 + 40 + 40+20, 340+80+40+15, width=3, fill="#04d9ff", outline="black")
sky_blue_3_coin = self.make_canvas.create_oval(100 + 40 + 60 + 40 + 20, 340 + 80 + 60 + 40 + 15, 100 + 40 + 60 + 40 + 40 + 20, 340 + 80 + 60 + 40 + 40 + 15, width=3, fill="#04d9ff", outline="black")
sky_blue_4_coin = self.make_canvas.create_oval( 100 + 40, 340+80+60+40+15, 100 + 40 + 40, 340+80+60+40+40+15, width=3, fill="#04d9ff", outline="black")
self.made_sky_blue_coin.append(sky_blue_1_coin)
self.made_sky_blue_coin.append(sky_blue_2_coin)
self.made_sky_blue_coin.append(sky_blue_3_coin)
self.made_sky_blue_coin.append(sky_blue_4_coin)
# Make coin under number label for sky_blue left down block
sky_blue_1_label = Label(self.make_canvas, text="1", font=("Arial", 15, "bold"), bg="#04d9ff", fg="black")
sky_blue_1_label.place(x=100 + 40 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 10)
sky_blue_2_label = Label(self.make_canvas, text="2", font=("Arial", 15, "bold"), bg="#04d9ff", fg="black")
sky_blue_2_label.place(x=100 + 40 + 60 + 60 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 10)
sky_blue_3_label = Label(self.make_canvas, text="3", font=("Arial", 15, "bold"), bg="#04d9ff", fg="black")
sky_blue_3_label.place(x=100 + 40 + 60 + 60 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 60 + 40 + 10)
sky_blue_4_label = Label(self.make_canvas, text="4", font=("Arial", 15, "bold"), bg="#04d9ff", fg="black")
sky_blue_4_label.place(x=100 + 40 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 60 + 40 + 10)
self.sky_blue_number_label.append(sky_blue_1_label)
self.sky_blue_number_label.append(sky_blue_2_label)
self.sky_blue_number_label.append(sky_blue_3_label)
self.sky_blue_number_label.append(sky_blue_4_label)
# Make coin for yellow right down block
yellow_1_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40, 340+80+15, 340 + (40 * 3) + 40 + 40, 340+80+40+15, width=3, fill="yellow", outline="black")
yellow_2_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40 + 60 + 40 + 20, 340+80+15, 340 + (40 * 3) + 40 + 60 + 40 + 40+20, 340+80+40+15, width=3, fill="yellow", outline="black")
yellow_3_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40 + 60 + 40 + 20, 340 + 80 + 60 + 40 + 15, 340 + (40 * 3) + 40 + 60 + 40 + 40 + 20, 340 + 80 + 60 + 40 + 40 + 15, width=3, fill="yellow", outline="black")
yellow_4_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40, 340+80+60+40+15, 340 + (40 * 3) + 40 + 40,340+80+60+40+40+15, width=3, fill="yellow", outline="black")
self.made_yellow_coin.append(yellow_1_coin)
self.made_yellow_coin.append(yellow_2_coin)
self.made_yellow_coin.append(yellow_3_coin)
self.made_yellow_coin.append(yellow_4_coin)
# Make coin under number label for yellow right down block
yellow_1_label = Label(self.make_canvas, text="1", font=("Arial", 15, "bold"), bg="yellow", fg="black")
yellow_1_label.place(x=340 + (40 * 3) + 40 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 10)
yellow_2_label = Label(self.make_canvas, text="2", font=("Arial", 15, "bold"), bg="yellow", fg="black")
yellow_2_label.place(x=340 + (40 * 3) + 40 + 40 + 60 + 30, y=30 + (40 * 6) + (40 * 3) + 40 + 10)
yellow_3_label = Label(self.make_canvas, text="3", font=("Arial", 15, "bold"), bg="yellow", fg="black")
yellow_3_label.place(x=340 + (40 * 3) + 40 + 40 + 60 + 30, y=30 + (40 * 6) + (40 * 3) + 40 + 100 + 10)
yellow_4_label = Label(self.make_canvas, text="4", font=("Arial", 15, "bold"), bg="yellow", fg="black")
yellow_4_label.place(x=340 + (40 * 3) + 40 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 100 + 10)
self.yellow_number_label.append(yellow_1_label)
self.yellow_number_label.append(yellow_2_label)
self.yellow_number_label.append(yellow_3_label)
self.yellow_number_label.append(yellow_4_label)
# Make star safe zone
"""
A
L * B
K * * * * * * C
* *
J * * D
* *
I* * * * * * E
H * F
G
"""
# Right star
common_x = 340+(40*6)+20
common_y = 15+240+2
# A B C D E F G H I J K L
coord = [common_x,common_y, common_x+5,common_y+15, common_x+15,common_y+15, common_x+8,common_y+20, common_x+15,common_y+25, common_x+5,common_y+25, common_x,common_y+25+10, common_x-5,common_y+25, common_x-16,common_y+25, common_x-8,common_y+15+5, common_x-15,common_y+15, common_x-5,common_y+15]
self.make_canvas.create_polygon(coord,width=3,fill="blue")
# Up star
common_x = 100+240+2+18
common_y = 15 + (40*2) + 2
# A B C D E F G H I J K L
coord = [common_x, common_y, common_x + 5, common_y + 15, common_x + 15, common_y + 15, common_x + 8, common_y + 20, common_x + 15, common_y + 25, common_x + 5, common_y + 25, common_x, common_y + 25 + 10, common_x - 5, common_y + 25, common_x - 16, common_y + 25, common_x - 8,common_y + 15 + 5, common_x - 15,common_y + 15, common_x - 5,common_y + 15]
self.make_canvas.create_polygon(coord, width=3, fill="blue")
# Left star
common_x = 100 + (40*2) + 2 +18
common_y = 15 + 240+(40*2) + 2
# A B C D E F G H I J K L
coord = [common_x, common_y, common_x + 5, common_y + 15, common_x + 15, common_y + 15, common_x + 8,common_y + 20, common_x + 15, common_y + 25, common_x + 5, common_y + 25, common_x, common_y + 25 + 10, common_x - 5, common_y + 25, common_x - 16, common_y + 25, common_x - 8, common_y + 15 + 5, common_x - 15, common_y + 15, common_x - 5, common_y + 15]
self.make_canvas.create_polygon(coord, width=3, fill="blue")
# Down star
common_x = 100 + 240 + (40*2) + 2 + 18
common_y = 15 + (40 * 6) + (40*3)+(40*3)+2
# A B C D E F G H I J K L
coord = [common_x, common_y, common_x + 5, common_y + 15, common_x + 15, common_y + 15, common_x + 8, common_y + 20, common_x + 15, common_y + 25, common_x + 5, common_y + 25, common_x, common_y + 25 + 10, common_x - 5, common_y + 25, common_x - 16, common_y + 25, common_x - 8, common_y + 15 + 5, common_x - 15, common_y + 15, common_x - 5, common_y + 15]
self.make_canvas.create_polygon(coord, width=3, fill="blue")
# Total number of players: Control take at first
def take_initial_control(self):
for i in range(4):
self.block_value_predict[i][1]['state'] = DISABLED
# Make other window to control take
top = Toplevel()
top.geometry("600x150")
top.maxsize(600,150)
top.minsize(600,150)
top.config(bg="orange")
top.iconbitmap("Images/ludo_icon.ico")
head = Label(top,text="-:Total number of players:- ",font=("Arial",25,"bold","italic"),bg="orange",fg="chocolate")
head.place(x=70,y=30)
take_entry = Entry(top,font=("Arial",18,"bold","italic"),relief=SUNKEN,bd=7,width=12)
take_entry.place(x=150,y=80)
take_entry.focus()
def filtering():# Total player input value filtering
response_take = self.input_filtering(take_entry.get())
if response_take is True and int(take_entry.get())>1:
for player_index in range(int(take_entry.get())):
self.total_people_play.append(player_index)
print(self.total_people_play)
self.make_command()
top.destroy()
else:
messagebox.showerror("Input Error", "Please input number of players between 2 and 4")
submit_btn = Button(top,text="Submit",bg="black",fg="#00FF00",font=("Arial",13,"bold"),relief=RAISED,bd=8,command=filtering)
submit_btn.place(x=350,y=80)
top.mainloop()
# Get block value after prediction based on probability
def make_prediction(self,color_indicator):
try:
if color_indicator == "red":
block_value_predict = self.block_value_predict[0]
permanent_block_number = self.move_red_counter = randint(1, 6)
elif color_indicator == "sky_blue":
block_value_predict = self.block_value_predict[1]
permanent_block_number = self.move_sky_blue_counter = randint(1, 6)
elif color_indicator == "yellow":
block_value_predict = self.block_value_predict[2]
permanent_block_number = self.move_yellow_counter = randint(1, 6)
else:
block_value_predict = self.block_value_predict[3]
permanent_block_number = self.move_green_counter = randint(1, 6)
block_value_predict[1]['state'] = DISABLED
# Illusion of coin floating
temp_counter = 15
while temp_counter>0:
move_temp_counter = randint(1, 6)
block_value_predict[0]['image'] = self.block_number_side[move_temp_counter - 1]
self.window.update()
time.sleep(0.1)
temp_counter-=1
print("Prediction result: ", permanent_block_number)
# Permanent predicted value containing image set
block_value_predict[0]['image'] = self.block_number_side[permanent_block_number-1]
self.instructional_btn_customization_based_on_current_situation(color_indicator,permanent_block_number,block_value_predict)
except:
print("Force stop error")
def instructional_btn_customization_based_on_current_situation(self,color_indicator,permanent_block_number,block_value_predict):
if color_indicator == "red":
temp_coin_position = self.red_coin_position
elif color_indicator == "green":
temp_coin_position = self.green_coin_position
elif color_indicator == "yellow":
temp_coin_position = self.yellow_coin_position
else:
temp_coin_position = self.sky_blue_coin_position
all_in = 1
for i in range(4):
if temp_coin_position[i] == -1:
all_in = 1
else:
all_in = 0
break
if permanent_block_number == 6:
self.six_counter += 1
else:
self.six_counter = 0
if ((all_in == 1 and permanent_block_number == 6) or (all_in==0)) and self.six_counter<3:
permission = 1
if color_indicator == "red":
temp = self.red_coord_store
elif color_indicator == "green":
temp = self.green_coord_store
elif color_indicator == "yellow":
temp = self.yellow_coord_store
else:
temp = self.sky_blue_coord_store
if permanent_block_number<6:
if self.six_with_overlap == 1:
self.time_for-=1
self.six_with_overlap=0
for i in range(4):
if temp[i] == -1:
permission=0
elif temp[i]>100:
if temp[i]+permanent_block_number<=106:
permission=1
break
else:
permission=0
else:
permission=1
break
else:
for i in range(4):
if temp[i]>100:
if temp[i] + permanent_block_number <= 106:
permission = 1
break
else:
permission = 0
else:
permission = 1
break
if permission == 0:
self.make_command()
else:
block_value_predict[3]['state'] = NORMAL# Give btn activation
block_value_predict[1]['state'] = DISABLED# Predict btn deactivation
else:
block_value_predict[1]['state'] = NORMAL# Predict btn activation
if self.six_with_overlap == 1:
self.time_for -= 1
self.six_with_overlap = 0
self.make_command()
if permanent_block_number == 6 and self.six_counter<3 and block_value_predict[3]['state'] == NORMAL:
self.time_for-=1
else:
self.six_counter=0
# Player Scope controller
def make_command(self):
if self.time_for == -1:
pass
else:
self.block_value_predict[self.total_people_play[self.time_for]][1]['state'] = DISABLED
if self.time_for == len(self.total_people_play)-1:
self.time_for = -1
self.time_for+=1
self.block_value_predict[self.total_people_play[self.time_for]][1]['state'] = NORMAL
def instruction_btn_red(self):
block_predict_red = Label(self.make_canvas,image=self.block_number_side[0])
block_predict_red.place(x=45,y=15)
predict_red = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Predict", font=("Arial", 8, "bold"), command=lambda: self.make_prediction("red"))
predict_red.place(x=37, y=15 + 40)
entry_take_red = Entry(self.make_canvas,bg="white",fg="blue",font=("Arial",25,"bold","italic"),width=2,relief=SUNKEN,bd=5)
entry_take_red.place(x=40,y=15+80)
final_move = Button(self.make_canvas,bg="black",fg="#00FF00",relief=RAISED,bd=5,text="Give",font=("Arial",8,"bold"),command=lambda: self.main_controller("red",entry_take_red.get()),state=DISABLED)
final_move.place(x=42,y=15+140)
Label(self.make_canvas,text="Player 1",bg="#4d4dff",fg="gold",font=("Arial",15,"bold")).place(x=15,y=15+140+40)
self.store_instructional_btn(block_predict_red,predict_red,entry_take_red,final_move)
def instruction_btn_sky_blue(self):
block_predict_sky_blue = Label(self.make_canvas, image=self.block_number_side[0])
block_predict_sky_blue.place(x=45, y=15+(40*6+40*3)+10)
predict_sky_blue = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Predict",font=("Arial", 8, "bold"), command=lambda: self.make_prediction("sky_blue"))
predict_sky_blue.place(x=37, y=15+(40*6+40*3)+40 + 10)
entry_take_sky_blue = Entry(self.make_canvas, bg="white", fg="blue", font=("Arial", 25, "bold", "italic"), width=2,relief=SUNKEN, bd=5)
entry_take_sky_blue.place(x=40, y=15+(40*6+40*3)+40 + 50)
final_move = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Give", font=("Arial", 8, "bold"),command=lambda: self.main_controller("sky_blue",entry_take_sky_blue.get()),state=DISABLED)
final_move.place(x=42, y=15+(40*6+40*3)+40 + 110)
Label(self.make_canvas, text="Player 2", bg="#4d4dff", fg="gold", font=("Arial", 15, "bold")).place(x=15,y=15+(40*6+40*3)+40 + 110+ 40)
self.store_instructional_btn(block_predict_sky_blue, predict_sky_blue, entry_take_sky_blue, final_move)
def instruction_btn_yellow(self):
block_predict_yellow = Label(self.make_canvas, image=self.block_number_side[0])
block_predict_yellow.place(x=100 + (40 * 6 + 40 * 3 + 40 * 6 + 10)+10, y=15 + (40 * 6 + 40 * 3) + 10)
predict_yellow = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Predict",font=("Arial", 8, "bold"), command=lambda: self.make_prediction("yellow"))
predict_yellow.place(x=100 + (40 * 6 + 40 * 3 + 40 * 6 + 2)+10, y=15 + (40 * 6 + 40 * 3) + 40 + 10)
entry_take_yellow = Entry(self.make_canvas, bg="white", fg="blue", font=("Arial", 25, "bold", "italic"),width=2, relief=SUNKEN, bd=5)
entry_take_yellow.place(x=100 + (40 * 6 + 40 * 3 + 40 * 6 + 2)+13, y=15 + (40 * 6 + 40 * 3) + 40 + 50)
final_move = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Give",font=("Arial", 8, "bold"),command=lambda: self.main_controller("yellow",entry_take_yellow.get()),state=DISABLED)
final_move.place(x=100 + (40 * 6 + 40 * 3 + 40 * 6 + 2)+17, y=15 + (40 * 6 + 40 * 3) + 40 + 110)
Label(self.make_canvas, text="Player 3", bg="#4d4dff", fg="gold", font=("Arial", 15, "bold")).place(x=100 + (40 * 6 + 40 * 3 + 40 * 6 + 3),y=15 + (40 * 6 + 40 * 3) + 40 + 110 + 40)
self.store_instructional_btn(block_predict_yellow, predict_yellow, entry_take_yellow, final_move)
def instruction_btn_green(self):
block_predict_green = Label(self.make_canvas, image=self.block_number_side[0])
block_predict_green.place(x=100+(40*6+40*3+40*6+10)+10, y=15)
predict_green = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Predict", font=("Arial", 8, "bold"), command=lambda: self.make_prediction("green"))
predict_green.place(x=100+(40*6+40*3+40*6+2)+10, y=15 + 40)
entry_take_green = Entry(self.make_canvas, bg="white", fg="blue", font=("Arial", 25, "bold", "italic"), width=2, relief=SUNKEN, bd=5)
entry_take_green.place(x=100+(40*6+40*3+40*6+2)+13, y=15 + 80)
final_move = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Give",font=("Arial", 8, "bold"),command=lambda: self.main_controller("green",entry_take_green.get()),state=DISABLED)
final_move.place(x=100+(40*6+40*3+40*6+2)+17, y=15 + 140)
Label(self.make_canvas, text="Player 4", bg="#4d4dff", fg="gold", font=("Arial", 15, "bold")).place(x=100+(40*6+40*3+40*6+3), y=15 + 140+40)
self.store_instructional_btn(block_predict_green, predict_green, entry_take_green, final_move)
def store_instructional_btn(self, block_indicator, predictor, entry_controller, give_finally):
temp = []
temp.append(block_indicator)
temp.append(predictor)
temp.append(entry_controller)
temp.append(give_finally)
self.block_value_predict.append(temp)
# self.block_value_predict[0] = red instruction information
# self.block_value_predict[1] = sky_blue instruction information
# self.block_value_predict[2] = yellow instruction information
# self.block_value_predict[3] = green instruction information
# self.block_value_predict[something][1] = Predict btn
# self.block_value_predict[something][3] = Give btn
def red_circle_start_position(self, coin_number):
self.make_canvas.delete(self.made_red_coin[int(coin_number)-1])
self.made_red_coin[int(coin_number)-1] = self.make_canvas.create_oval(100 + 40, 15+(40*6), 100 +40 + 40, 15+(40*6)+40, fill="red", width=3, outline="black")
self.red_number_label[int(coin_number)-1].place_forget()
red_start_label_x = 100 + 40 + 10
red_start_label_y = 15 + (40 * 6) + 5
self.red_number_label[int(coin_number)-1].place(x=red_start_label_x, y=red_start_label_y)
self.red_coin_position[int(coin_number)-1] = 1
self.window.update()
time.sleep(0.2)
def green_circle_start_position(self,coin_number):
self.make_canvas.delete(self.made_green_coin[int(coin_number)-1])
self.made_green_coin[int(coin_number)-1] = self.make_canvas.create_oval(100 + (40*8), 15 + 40, 100 +(40*9), 15 + 40+ 40, fill="#00FF00", width=3)
self.green_number_label[int(coin_number)-1].place_forget()
green_start_label_x = 100 + (40*8) + 10
green_start_label_y = 15 + 40 + 5
self.green_number_label[int(coin_number)-1].place(x=green_start_label_x, y=green_start_label_y)
self.green_coin_position[int(coin_number)-1] = 14
self.window.update()
time.sleep(0.2)
def yellow_circle_start_position(self,coin_number):
self.make_canvas.delete(self.made_yellow_coin[int(coin_number)-1])
self.made_yellow_coin[int(coin_number)-1] = self.make_canvas.create_oval(100 + (40 * 6)+(40*3)+(40*4), 15 + (40*8), 100 + (40 * 6)+(40*3)+(40*5), 15 + (40*9), fill="yellow", width=3)
self.yellow_number_label[int(coin_number)-1].place_forget()
yellow_start_label_x = 100 + (40 * 6)+(40*3)+(40*4) + 10
yellow_start_label_y = 15 + (40*8) + 5
self.yellow_number_label[int(coin_number) - 1].place(x=yellow_start_label_x, y=yellow_start_label_y)
self.yellow_coin_position[int(coin_number) - 1] = 27
self.window.update()
time.sleep(0.2)
def sky_blue_circle_start_position(self,coin_number):
self.make_canvas.delete(self.made_sky_blue_coin[int(coin_number)-1])
self.made_sky_blue_coin[int(coin_number)-1] = self.make_canvas.create_oval(100+240,340+(40*5)-5,100+240+40,340+(40*6)-5,fill="#04d9ff",width=3)
self.sky_blue_number_label[int(coin_number)-1].place_forget()
sky_blue_start_label_x = 100+240 + 10
sky_blue_start_label_y = 340+(40*5)-5 + 5
self.sky_blue_number_label[int(coin_number) - 1].place(x=sky_blue_start_label_x, y=sky_blue_start_label_y)
self.sky_blue_coin_position[int(coin_number) - 1] = 40
self.window.update()
time.sleep(0.2)
def main_controller(self, color_coin, coin_number):
processing_result = self.input_filtering(coin_number)# Value filtering
if processing_result is True:
pass
else:
messagebox.showerror("Wrong input number","Please input the coin number between 1 to 4")
return
if color_coin == "red":
self.block_value_predict[0][3]['state'] = DISABLED
if self.move_red_counter == 106:
messagebox.showwarning("Destination reached","Reached at the destination")
elif self.red_coin_position[int(coin_number)-1] == -1 and self.move_red_counter == 6:
self.red_circle_start_position(coin_number)
self.red_coord_store[int(coin_number) - 1] = 1
elif self.red_coin_position[int(coin_number)-1] > -1:
take_coord = self.make_canvas.coords(self.made_red_coin[int(coin_number)-1])
red_start_label_x = take_coord[0] + 10
red_start_label_y = take_coord[1] + 5
self.red_number_label[int(coin_number) - 1].place(x=red_start_label_x, y=red_start_label_y)
if self.red_coin_position[int(coin_number)-1]+self.move_red_counter<=106:
self.red_coin_position[int(coin_number)-1] = self.motion_of_coin(self.red_coin_position[int(coin_number) - 1],self.made_red_coin[int(coin_number)-1],self.red_number_label[int(coin_number)-1],red_start_label_x,red_start_label_y,"red",self.move_red_counter)
else:
messagebox.showerror("Not possible","Sorry, not permitted")
self.block_value_predict[0][3]['state'] = NORMAL
return
if self.red_coin_position[int(coin_number)-1]==22 or self.red_coin_position[int(coin_number)-1]==9 or self.red_coin_position[int(coin_number)-1]==48 or self.red_coin_position[int(coin_number)-1]==35 or self.red_coin_position[int(coin_number)-1]==14 or self.red_coin_position[int(coin_number)-1]==27 or self.red_coin_position[int(coin_number)-1]==40:
pass
else:
if self.red_coin_position[int(coin_number) - 1] < 100:
self.coord_overlap(self.red_coin_position[int(coin_number)-1],color_coin, self.move_red_counter)
self.red_coord_store[int(coin_number)-1] = self.red_coin_position[int(coin_number)-1]
else:
messagebox.showerror("Wrong choice","Sorry, Your coin in not permitted to travel")
self.block_value_predict[0][3]['state'] = NORMAL
return
self.block_value_predict[0][1]['state'] = NORMAL
elif color_coin == "green":
self.block_value_predict[3][3]['state'] = DISABLED
if self.move_green_counter == 106:
messagebox.showwarning("Destination reached","Reached at the destination")
elif self.green_coin_position[int(coin_number) - 1] == -1 and self.move_green_counter == 6:
self.green_circle_start_position(coin_number)
self.green_coord_store[int(coin_number) - 1] = 14
elif self.green_coin_position[int(coin_number) - 1] > -1:
take_coord = self.make_canvas.coords(self.made_green_coin[int(coin_number) - 1])
green_start_label_x = take_coord[0] + 10
green_start_label_y = take_coord[1] + 5
self.green_number_label[int(coin_number) - 1].place(x=green_start_label_x, y=green_start_label_y)
if self.green_coin_position[int(coin_number) - 1] + self.move_green_counter <= 106:
self.green_coin_position[int(coin_number) - 1] = self.motion_of_coin(self.green_coin_position[int(coin_number) - 1], self.made_green_coin[int(coin_number) - 1], self.green_number_label[int(coin_number) - 1], green_start_label_x, green_start_label_y, "green", self.move_green_counter)
else:
messagebox.showerror("Not possible","No path available")
self.block_value_predict[3][3]['state'] = NORMAL
return
if self.green_coin_position[int(coin_number)-1]==22 or self.green_coin_position[int(coin_number)-1]==9 or self.green_coin_position[int(coin_number)-1]==48 or self.green_coin_position[int(coin_number)-1]==35 or self.green_coin_position[int(coin_number)-1]==1 or self.green_coin_position[int(coin_number)-1]==27 or self.green_coin_position[int(coin_number)-1]==40:
pass
else:
if self.green_coin_position[int(coin_number) - 1] < 100:
self.coord_overlap(self.green_coin_position[int(coin_number) - 1],color_coin, self.move_green_counter)
self.green_coord_store[int(coin_number) - 1] = self.green_coin_position[int(coin_number) - 1]
else:
messagebox.showerror("Wrong choice", "Sorry, Your coin in not permitted to travel")
self.block_value_predict[3][3]['state'] = NORMAL
return
self.block_value_predict[3][1]['state'] = NORMAL
elif color_coin == "yellow":
self.block_value_predict[2][3]['state'] = DISABLED
if self.move_yellow_counter == 106:
messagebox.showwarning("Destination reached","Reached at the destination")
elif self.yellow_coin_position[int(coin_number) - 1] == -1 and self.move_yellow_counter == 6:
self.yellow_circle_start_position(coin_number)
self.yellow_coord_store[int(coin_number) - 1] = 27
elif self.yellow_coin_position[int(coin_number) - 1] > -1:
take_coord = self.make_canvas.coords(self.made_yellow_coin[int(coin_number) - 1])
yellow_start_label_x = take_coord[0] + 10
yellow_start_label_y = take_coord[1] + 5
self.yellow_number_label[int(coin_number) - 1].place(x=yellow_start_label_x, y=yellow_start_label_y)
if self.yellow_coin_position[int(coin_number) - 1] + self.move_yellow_counter <= 106:
self.yellow_coin_position[int(coin_number) - 1] = self.motion_of_coin(self.yellow_coin_position[int(coin_number) - 1], self.made_yellow_coin[int(coin_number) - 1], self.yellow_number_label[int(coin_number) - 1], yellow_start_label_x, yellow_start_label_y, "yellow", self.move_yellow_counter)
else:
messagebox.showerror("Not possible","No path available")
self.block_value_predict[2][3]['state'] = NORMAL
return
if self.yellow_coin_position[int(coin_number)-1]==22 or self.yellow_coin_position[int(coin_number)-1]==9 or self.yellow_coin_position[int(coin_number)-1]==48 or self.yellow_coin_position[int(coin_number)-1]==35 or self.yellow_coin_position[int(coin_number)-1]==1 or self.yellow_coin_position[int(coin_number)-1]==14 or self.yellow_coin_position[int(coin_number)-1]==40:
pass
else:
if self.yellow_coin_position[int(coin_number) - 1] < 100:
self.coord_overlap(self.yellow_coin_position[int(coin_number) - 1],color_coin, self.move_yellow_counter)
self.yellow_coord_store[int(coin_number) - 1] = self.yellow_coin_position[int(coin_number) - 1]
else:
messagebox.showerror("Wrong choice", "Sorry, Your coin in not permitted to travel")
self.block_value_predict[2][3]['state'] = NORMAL
return
self.block_value_predict[2][1]['state'] = NORMAL
elif color_coin == "sky_blue":
self.block_value_predict[1][3]['state'] = DISABLED
if self.move_red_counter == 106:
messagebox.showwarning("Destination reached","Reached at the destination")
elif self.sky_blue_coin_position[int(coin_number) - 1] == -1 and self.move_sky_blue_counter == 6:
self.sky_blue_circle_start_position(coin_number)
self.sky_blue_coord_store[int(coin_number) - 1] = 40
elif self.sky_blue_coin_position[int(coin_number) - 1] > -1:
take_coord = self.make_canvas.coords(self.made_sky_blue_coin[int(coin_number) - 1])
sky_blue_start_label_x = take_coord[0] + 10
sky_blue_start_label_y = take_coord[1] + 5
self.sky_blue_number_label[int(coin_number) - 1].place(x=sky_blue_start_label_x, y=sky_blue_start_label_y)
if self.sky_blue_coin_position[int(coin_number) - 1] + self.move_sky_blue_counter <= 106:
self.sky_blue_coin_position[int(coin_number) - 1] = self.motion_of_coin(self.sky_blue_coin_position[int(coin_number) - 1], self.made_sky_blue_coin[int(coin_number) - 1], self.sky_blue_number_label[int(coin_number) - 1], sky_blue_start_label_x, sky_blue_start_label_y, "sky_blue", self.move_sky_blue_counter)
else:
messagebox.showerror("Not possible","No path available")
self.block_value_predict[1][3]['state'] = NORMAL
return
if self.sky_blue_coin_position[int(coin_number)-1]==22 or self.sky_blue_coin_position[int(coin_number)-1]==9 or self.sky_blue_coin_position[int(coin_number)-1]==48 or self.sky_blue_coin_position[int(coin_number)-1]==35 or self.sky_blue_coin_position[int(coin_number)-1]==1 or self.sky_blue_coin_position[int(coin_number)-1]==14 or self.sky_blue_coin_position[int(coin_number)-1]==27:
pass
else:
if self.sky_blue_coin_position[int(coin_number) - 1] < 100:
self.coord_overlap(self.sky_blue_coin_position[int(coin_number) - 1],color_coin, self.move_sky_blue_counter)
self.sky_blue_coord_store[int(coin_number) - 1] = self.sky_blue_coin_position[int(coin_number) - 1]
else:
messagebox.showerror("Wrong choice", "Sorry, Your coin in not permitted to travel")
self.block_value_predict[1][3]['state'] = NORMAL
return
self.block_value_predict[1][1]['state'] = NORMAL
print(self.red_coord_store)
print(self.green_coord_store)
print(self.yellow_coord_store)
print(self.sky_blue_coord_store)
permission_granted_to_proceed = True
if color_coin == "red" and self.red_coin_position[int(coin_number)-1] == 106:
permission_granted_to_proceed = self.check_winner_and_runner(color_coin)
elif color_coin == "green" and self.green_coin_position[int(coin_number)-1] == 106:
permission_granted_to_proceed = self.check_winner_and_runner(color_coin)
elif color_coin == "yellow" and self.yellow_coin_position[int(coin_number)-1] == 106:
permission_granted_to_proceed = self.check_winner_and_runner(color_coin)
elif color_coin == "sky_blue" and self.sky_blue_coin_position[int(coin_number)-1] == 106:
permission_granted_to_proceed = self.check_winner_and_runner(color_coin)
if permission_granted_to_proceed:# if that is False, Game is over and not proceed more
self.make_command()
def motion_of_coin(self,counter_coin,specific_coin,number_label,number_label_x ,number_label_y,color_coin,path_counter):
number_label.place(x=number_label_x,y=number_label_y)
while True:
if path_counter == 0:
break
elif (counter_coin == 51 and color_coin == "red") or (counter_coin==12 and color_coin == "green") or (counter_coin == 25 and color_coin == "yellow") or (counter_coin == 38 and color_coin == "sky_blue") or counter_coin>=100:
if counter_coin<100:
counter_coin=100
counter_coin = self.under_room_traversal_control(specific_coin, number_label, number_label_x, number_label_y, path_counter, counter_coin, color_coin)
if counter_coin == 106:
messagebox.showinfo("Destination reached","Congrats! You now at the destination")
if path_counter == 6:
self.six_with_overlap = 1
else:
self.time_for -= 1
break
counter_coin += 1
path_counter -=1
number_label.place_forget()
print(counter_coin)
if counter_coin<=5:
self.make_canvas.move(specific_coin, 40, 0)
number_label_x+=40
elif counter_coin == 6:
self.make_canvas.move(specific_coin, 40, -40)
number_label_x += 40
number_label_y-=40
elif 6< counter_coin <=11:
self.make_canvas.move(specific_coin, 0, -40)
number_label_y -= 40
elif counter_coin <=13:
self.make_canvas.move(specific_coin, 40, 0)
number_label_x += 40
elif counter_coin <=18:
self.make_canvas.move(specific_coin, 0, 40)
number_label_y += 40
elif counter_coin == 19:
self.make_canvas.move(specific_coin, 40, 40)
number_label_x += 40
number_label_y += 40
elif counter_coin <=24:
self.make_canvas.move(specific_coin, 40, 0)
number_label_x += 40
elif counter_coin <=26:
self.make_canvas.move(specific_coin, 0, 40)
number_label_y += 40
elif counter_coin <=31:
self.make_canvas.move(specific_coin, -40, 0)
number_label_x -= 40
elif counter_coin == 32:
self.make_canvas.move(specific_coin, -40, 40)
number_label_x -= 40
number_label_y += 40
elif counter_coin <= 37:
self.make_canvas.move(specific_coin, 0, 40)
number_label_y += 40
elif counter_coin <= 39:
self.make_canvas.move(specific_coin, -40, 0)
number_label_x -= 40
elif counter_coin <= 44:
self.make_canvas.move(specific_coin, 0, -40)
number_label_y -= 40
elif counter_coin == 45:
self.make_canvas.move(specific_coin, -40, -40)
number_label_x -= 40
number_label_y -= 40
elif counter_coin <= 50:
self.make_canvas.move(specific_coin, -40, 0)
number_label_x -= 40
elif 50< counter_coin <=52:
self.make_canvas.move(specific_coin, 0, -40)
number_label_y -= 40
elif counter_coin == 53:
self.make_canvas.move(specific_coin, 40, 0)
number_label_x += 40
counter_coin = 1
number_label.place_forget()
number_label.place(x=number_label_x, y=number_label_y)
self.window.update()
time.sleep(0.2)
return counter_coin
# For same position, previous coin deleted and set to the room
def coord_overlap(self, counter_coin, color_coin, path_to_traverse_before_overlap):
if color_coin!="red":
for take_coin_number in range(len(self.red_coord_store)):
if self.red_coord_store[take_coin_number] == counter_coin:
if path_to_traverse_before_overlap == 6:
self.six_with_overlap=1
else:
self.time_for-=1
self.make_canvas.delete(self.made_red_coin[take_coin_number])
self.red_number_label[take_coin_number].place_forget()
self.red_coin_position[take_coin_number] = -1
self.red_coord_store[take_coin_number] = -1
if take_coin_number == 0:
remade_coin = self.make_canvas.create_oval(100+40, 15+40, 100+40+40, 15+40+40, width=3, fill="red", outline="black")
self.red_number_label[take_coin_number].place(x=100 + 40 + 10, y=15 + 40 + 5)
elif take_coin_number == 1:
remade_coin = self.make_canvas.create_oval(100+40+60+60, 15 + 40, 100+40+60+60+40, 15 + 40 + 40, width=3, fill="red", outline="black")
self.red_number_label[take_coin_number].place(x=100 + 40 + 60 +60 + 10, y=15 + 40 + 5)
elif take_coin_number == 2:
remade_coin = self.make_canvas.create_oval(100 + 40 + 60 + 60, 15 + 40 + 100, 100 + 40 + 60 + 60 + 40, 15 + 40 + 40 + 100, width=3, fill="red", outline="black")
self.red_number_label[take_coin_number].place(x=100 + 40 + 60 + 60 + 10, y=15 + 40 + 100 + 5)
else:
remade_coin = self.make_canvas.create_oval(100 + 40, 15 + 40+100, 100 + 40 + 40, 15 + 40 + 40+100, width=3,fill="red", outline="black")
self.red_number_label[take_coin_number].place(x=100 + 40 + 10, y=15 + 40 + 100 + 5)
self.made_red_coin[take_coin_number]=remade_coin
if color_coin != "green":
for take_coin_number in range(len(self.green_coord_store)):
if self.green_coord_store[take_coin_number] == counter_coin:
if path_to_traverse_before_overlap == 6:
self.six_with_overlap = 1
else:
self.time_for-=1
self.make_canvas.delete(self.made_green_coin[take_coin_number])
self.green_number_label[take_coin_number].place_forget()
self.green_coin_position[take_coin_number] = -1
self.green_coord_store[take_coin_number] = -1
if take_coin_number == 0:
remade_coin = self.make_canvas.create_oval(340+(40*3)+40, 15 + 40, 340+(40*3)+40 + 40, 15 + 40 + 40, width=3, fill="#00FF00", outline="black")
self.green_number_label[take_coin_number].place(x=340 + (40 * 3) + 40 + 10, y=15 + 40 + 5)
elif take_coin_number == 1:
remade_coin = self.make_canvas.create_oval(340+(40*3)+40+ 60 + 40+20, 15 + 40, 340+(40*3)+40 + 60 + 40 + 40+20, 15 + 40 + 40, width=3, fill="#00FF00", outline="black")
self.green_number_label[take_coin_number].place(x=340 + (40 * 3) + 40 + 40 + 60 + 30, y=15 + 40 + 5)
elif take_coin_number == 2:
remade_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40 + 60 + 40 + 20, 15 + 40 + 100, 340 + (40 * 3) + 40 + 60 + 40 + 40 + 20, 15 + 40 + 40 + 100, width=3, fill="#00FF00", outline="black")
self.green_number_label[take_coin_number].place(x=340 + (40 * 3) + 40 + 40 + 60 + 30, y=15 + 40 + 100 + 5)
else:
remade_coin = self.make_canvas.create_oval(340+(40*3)+40, 15 + 40 + 100, 340+(40*3)+40 + 40, 15 + 40 + 40 + 100, width=3, fill="#00FF00", outline="black")
self.green_number_label[take_coin_number].place(x=340+(40*3) + 40 + 10, y=15 + 40 + 100 + 5)
self.made_green_coin[take_coin_number] = remade_coin
if color_coin != "yellow":
for take_coin_number in range(len(self.yellow_coord_store)):
if self.yellow_coord_store[take_coin_number] == counter_coin:
if path_to_traverse_before_overlap == 6:
self.six_with_overlap = 1
else:
self.time_for -= 1
self.make_canvas.delete(self.made_yellow_coin[take_coin_number])
self.yellow_number_label[take_coin_number].place_forget()
self.yellow_coin_position[take_coin_number] = -1
self.yellow_coord_store[take_coin_number] = -1
if take_coin_number == 0:
remade_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40, 340+80+15, 340 + (40 * 3) + 40 + 40, 340+80+40+15, width=3, fill="yellow", outline="black")
self.yellow_number_label[take_coin_number].place(x=340+(40*3) + 40 + 10, y=30 + (40*6)+(40*3)+40+10)
elif take_coin_number == 1:
remade_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40 + 60 + 40 + 20, 340+80+15, 340 + (40 * 3) + 40 + 60 + 40 + 40+20, 340+80+40+15, width=3, fill="yellow", outline="black")
self.yellow_number_label[take_coin_number].place(x=340+(40*3)+ 40 + 40+ 60 + 30, y=30 + (40*6)+(40*3)+40+10)
elif take_coin_number == 2:
remade_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40 + 60 + 40 + 20, 340 + 80 + 60 + 40 + 15, 340 + (40 * 3) + 40 + 60 + 40 + 40 + 20, 340 + 80 + 60 + 40 + 40 + 15, width=3, fill="yellow", outline="black")
self.yellow_number_label[take_coin_number].place(x=340+(40*3)+ 40 + 40+ 60 + 30, y=30 + (40*6)+(40*3)+40+100+10)
else:
remade_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40, 340+80+60+40+15, 340 + (40 * 3) + 40 + 40,340+80+60+40+40+15, width=3, fill="yellow", outline="black")
self.yellow_number_label[take_coin_number].place(x=340 + (40 * 3) + 40 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 100 + 10)
self.made_yellow_coin[take_coin_number] = remade_coin
if color_coin != "sky_blue":
for take_coin_number in range(len(self.sky_blue_coord_store)):
if self.sky_blue_coord_store[take_coin_number] == counter_coin:
if path_to_traverse_before_overlap == 6:
self.six_with_overlap = 1
else:
self.time_for -= 1
self.make_canvas.delete(self.made_sky_blue_coin[take_coin_number])
self.sky_blue_number_label[take_coin_number].place_forget()
self.sky_blue_coin_position[take_coin_number] = -1
self.sky_blue_coord_store[take_coin_number]=-1