This repository has been archived by the owner on Dec 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
game.py
917 lines (734 loc) · 33.7 KB
/
game.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 Mark König ([email protected])
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import os
import random
from random import randint
import time
import threading
import string
import sys
import json
import xbmc
import xbmcvfs
import xbmcaddon
import xbmcgui
addon = xbmcaddon.Addon()
ADDON_NAME = addon.getAddonInfo('name')
ADDON_PATH = addon.getAddonInfo('path')
MEDIA_PATH = os.path.join(
xbmcvfs.translatePath(ADDON_PATH),
'resources',
'skins',
'default',
'media'
)
LIB_PATH = os.path.join(
xbmcvfs.translatePath(ADDON_PATH),
'resources',
'lib'
)
# score table
scores = {"scorePlayer": [220, 215, 210, 205, 200],
"namePlayer": ["Logan", "Mark", "Olivia", "Mike", "Ronny"],
"scoreCPU": [220, 215, 210, 205, 200]}
# path to profile
PROFILE_Path = xbmcvfs.translatePath(addon.getAddonInfo('profile'))
scoreFile = os.path.join(PROFILE_Path, "score.json")
if not xbmcvfs.exists(scoreFile):
# init scores
with open(scoreFile, "w") as write_file:
json.dump(scores, write_file)
SPEED = addon.getSetting('speed')
NOTIFY = addon.getSetting('notify') == "true"
libs = xbmcvfs.translatePath(os.path.join(ADDON_PATH, 'resources', 'lib'))
sys.path.append(libs)
import yahtzee_points
import yahtzee_logic
ACTION_PREVIOUS_MENU = 10
ACTION_NAV_BACK = 92
class Game(xbmcgui.WindowXML):
pointsP1 = []
pointsP2 = []
pointsP3 = []
pointsP4 = []
hold = []
dice = []
soundOn = True
game_round = 0
actualTry = 0
actualPlayer = 0
player = 1
computer = 1
gameOn = False
showHigh = False
diceOn = False
diceCnt = 0
diceFinished = 0
delayComputer = 0
stop_thread = False
#set values for game play speed
time = 300
delay = 5
if (SPEED == '1'):
time = 500
delay = 10
if (SPEED == '2'):
time = 800
delay = 15
# ----------------------------------------------------------------------------------------------------
def onInit(self):
self.p0x = self.getControl(6200)
self.p0x.setLabel(self.GetPlayerName(1, False))
self.p0x = self.getControl(6201)
self.p0x.setLabel(self.GetPlayerName(2, False))
self.p0x = self.getControl(6202)
self.p0x.setLabel(self.GetPlayerName(3, False))
self.p0x = self.getControl(6203)
self.p0x.setLabel(self.GetPlayerName(4, False))
# init vars
result = yahtzee_logic.ReadRestgewinn()
# init points
for i in range(15):
self.pointsP1.append(-1)
self.pointsP2.append(-1)
self.pointsP3.append(-1)
self.pointsP4.append(-1)
for i in range(5):
self.hold.append(False)
self.dice.append(6)
# set points
self.updatePoints()
# get controls
# init the grid
# start the timer thread
self.stop_thread = False
threading.Thread(target=self.timer_thread).start()
# start the game
self.updateToggleButtons(0)
# focus the dice button
self.setFocusId(5008)
if not result:
self.close()
def onAction(self, action):
action_id = action.getId()
focus_id = self.getFocusId()
if action_id == ACTION_PREVIOUS_MENU:
self.closeApp()
if action_id == ACTION_NAV_BACK:
self.closeApp()
def closeApp(self):
# do you really ...
dialog = xbmcgui.Dialog()
confirmed = dialog.yesno(addon.getLocalizedString(31025),
addon.getLocalizedString(31045) + '\n' +
addon.getLocalizedString(31046)
)
if confirmed:
self.stop_thread = True
self.close()
def onFocus(self, control_id):
self.updateToggleButtons(control_id)
def onClick(self, control_id):
# set points from player
if(self.actualPlayer <= self.player):
if(control_id >= 5299) and (control_id < 5320):
btn = control_id - 5300 + 1
if(self.gameOn and not self.diceOn and (self.actualTry > 0)):
points = self.GetValuePlayer(self.actualPlayer)
if(points[btn-1] == -1):
value = yahtzee_points.GetCalc(btn, self.dice)
if(value == 0):
dialog = xbmcgui.Dialog()
confirmed = dialog.yesno(addon.getLocalizedString(31042),
addon.getLocalizedString(31043) + '\n' +
addon.getLocalizedString(31044) + '\n' +
addon.getLocalizedString(31012 + btn)
)
if confirmed:
self.SetValuePlayer(self.actualPlayer, btn-1, 0)
self.updatePoints()
self.NextPlayer()
else:
self.SetValuePlayer(self.actualPlayer, btn-1, value)
self.updatePoints()
self.NextPlayer()
# new game
if(control_id == 5002):
if(self.gameOn):
# do you really ?
dialog = xbmcgui.Dialog()
confirmed = dialog.yesno(addon.getLocalizedString(31034),
addon.getLocalizedString(31035) + '\n' +
addon.getLocalizedString(31036)
)
if confirmed:
self.NewGame()
else:
self.NewGame()
# set how many player
if(control_id == 5003):
if(not self.gameOn):
if(self.player < 4):
self.player = self.player + 1
else:
self.player = 1
#self.player = 0 # for test computer vs computer
if(self.player + self.computer) > 4:
self.computer = 4 - self.player
self.updateToggleButtons(0)
# set how many computer
if(control_id == 5004):
if(not self.gameOn):
if self.computer < (4 - self.player):
# not implemeneted yet
self.computer = self.computer + 1
pass
else:
self.computer = 0
self.updateToggleButtons(0)
# sound on/off
if(control_id == 5005):
self.soundOn = not self.soundOn
self.updateToggleButtons(control_id)
# dice player
if(control_id == 5008):
if(not self.gameOn):
if((self.player + self.computer) > 0):
# if not in game then start the game
self.NewGame()
self.gameOn = True
self.actualPlayer = 1
self.actualTry = 1
if(self.soundOn):
xbmc.playSFX(MEDIA_PATH + '\\dice.wav')
self.diceOn = True
self.diceFinished = False
self.updateToggleButtons(control_id)
#if(NOTIFY):
# xbmcgui.Dialog().notification(ADDON_NAME,
# self.GetPlayerName(self.actualPlayer, False) + '\n1. ' + addon.getLocalizedString(3007),
# time= self.time)
else:
if not self.diceOn:
if(self.actualPlayer <= self.player):
# do we have still one open
if(self.actualTry < 3):
self.actualTry = self.actualTry + 1
self.diceOn = True
self.diceFinished = False
if(self.soundOn):
xbmc.playSFX(MEDIA_PATH + '\\dice.wav')
self.updateToggleButtons(control_id);
#if(NOTIFY):
# xbmcgui.Dialog().notification(ADDON_NAME,
# self.GetPlayerName(self.actualPlayer, False) + '\n' +str(self.actualTry) + '. ' + addon.getLocalizedString(3007),
# time= self.time)
else:
# last try reached, now set a field
dialog = xbmcgui.Dialog()
confirmed = dialog.ok(addon.getLocalizedString(31025),
addon.getLocalizedString(31029)
)
# give me a tip
if(control_id == 5009):
if(self.actualPlayer <= self.player):
if(self.gameOn and not self.diceOn and (self.actualTry > 0)):
testTry = self.actualTry
value = self.GetYahzeeMove(testTry)
# we can already sign a value
if(value > 9999):
testTry = 3
value = self.GetYahzeeMove(testTry)
txt = '...'
if(testTry == 1):
if(value != 0):
txt = addon.getLocalizedString(31012) + ' : ' + str(value)
else:
txt = addon.getLocalizedString(31009)
if(testTry == 2):
if(value != 0):
txt = addon.getLocalizedString(31012) + ' : ' + str(value)
else:
txt = addon.getLocalizedString(31009)
if(testTry == 3):
x = value
if(x > 5):
x = x + 1
points = yahtzee_points.GetCalc(x + 1 , self.dice)
if(points > 0):
txt = addon.getLocalizedString(31040) + ' : ' + addon.getLocalizedString(31013 + x)
else:
txt = addon.getLocalizedString(31042) + ' : ' + addon.getLocalizedString(31013 + x)
dialog = xbmcgui.Dialog()
confirmed = dialog.ok(addon.getLocalizedString(31010),
txt)
# what's this?
if(control_id == 5010):
dialog = xbmcgui.Dialog()
confirmed = dialog.ok(addon.getLocalizedString(31025),
addon.getLocalizedString(31050)
)
# toggle hold button for the player
if(self.actualPlayer <= self.player):
if(self.actualTry > 0) and self.gameOn and not self.diceOn and self.diceFinished:
if(control_id == 5200):
self.hold[0] = not self.hold[0]
self.updateToggleButtons(control_id)
if(control_id == 5201):
self.hold[1] = not self.hold[1]
self.updateToggleButtons(control_id)
if(control_id == 5202):
self.hold[2] = not self.hold[2]
self.updateToggleButtons(control_id)
if(control_id == 5203):
self.hold[3] = not self.hold[3]
self.updateToggleButtons(control_id)
if(control_id == 5204):
self.hold[4] = not self.hold[4]
self.updateToggleButtons(control_id)
# highscores
if(control_id == 5011):
self.showHighscores()
def timer_thread(self):
while not xbmc.Monitor().abortRequested() and not self.stop_thread:
if(self.diceOn):
self.delayComputer = 0
self.diceCnt = self.diceCnt +1
if(self.diceCnt < 10):
for w in range(5):
if (self.hold[w] == False):
try:
x = randint(1, 6)
self.dice[w] = x
self.wx = self.getControl(5100 + w)
self.wx.setImage('w%s.png' % x)
except:
pass
else:
self.diceOn = False
self.diceFinished = True
else:
self.diceCnt = 0
self.delayComputer = self.delayComputer + 1
if(self.delayComputer > self.delay):
self.delayComputer = 0
if(self.gameOn):
# computer dice
if(self.actualPlayer > self.player):
if(not self.diceOn):
if(self.actualTry == 0):
self.actualTry = self.actualTry + 1
self.updateTry()
# computer first dice
#if(NOTIFY):
# xbmcgui.Dialog().notification(ADDON_NAME,
# self.GetPlayerName(self.actualPlayer, True) + '\n1. ' + addon.getLocalizedString(3007),
# time= self.time)
self.diceOn = True
self.diceFinished = False
self.diceCnt = 0
if(self.soundOn):
xbmc.playSFX(MEDIA_PATH + '\\dice.wav')
elif((self.actualTry > 0) and (self.actualTry < 3)):
testTry = self.actualTry
value = self.GetYahzeeMove(testTry)
if(value < 9999):
# reset hold
self.hold[0] = False;
self.hold[1] = False;
self.hold[2] = False;
self.hold[3] = False;
self.hold[4] = False;
# decode value
a = int(value / 10000)
value = value - (a * 10000)
b = int(value / 1000)
value = value - (b * 1000)
c = int(value / 100)
value = value - (c * 100)
d = int(value / 10)
value = value - (d * 10)
e = int(value)
#check first digit
if(a > 0):
for x in range(0,5):
if(self.hold[x] == False):
if(self.dice[x] == a):
self.hold[x] = True
break
#check second digit
if(b > 0):
for x in range(0,5):
if(self.hold[x] == False):
if(self.dice[x] == b):
self.hold[x] = True
break
#check third digit
if(c > 0):
for x in range(0,5):
if(self.hold[x] == False):
if(self.dice[x] == c):
self.hold[x] = True
break
#check fourth digit
if(d > 0):
for x in range(0,5):
if(self.hold[x] == False):
if(self.dice[x] == d):
self.hold[x] = True
break
#check fivth digit
if(e > 0):
for x in range(0,5):
if(self.hold[x] == False):
if(self.dice[x] == e):
self.hold[x] = True
break
self.updateToggleButtons(5200)
self.updateToggleButtons(5201)
self.updateToggleButtons(5202)
self.updateToggleButtons(5203)
self.updateToggleButtons(5204)
# focus the dice button
self.setFocusId(5008)
self.actualTry = self.actualTry + 1
self.updateTry()
# player x (actual) dice
#if(NOTIFY):
# xbmcgui.Dialog().notification(ADDON_NAME,
# self.GetPlayerName(self.actualPlayer, True) + '\n' + str(self.actualTry) + '. ' + addon.getLocalizedString(3007),
# time= self.time)
self.diceOn = True
self.diceFinished = False
self.diceCnt = 0
if(self.soundOn):
xbmc.playSFX(MEDIA_PATH + '\\dice.wav')
else:
# we can already set a position on the table
sel = self.GetYahzeeMove(3)
btn = sel + 1
# because we have one field space (6)
if(btn > 6):
btn = btn + 1
# player x set field y
if(NOTIFY):
xbmcgui.Dialog().notification(ADDON_NAME,
self.GetPlayerName(self.actualPlayer, True) + '\n' + addon.getLocalizedString(31012 + btn),
time= self.time)
# get value
value = yahtzee_points.GetCalc(btn, self.dice)
self.SetValuePlayer(self.actualPlayer, btn-1, value)
self.updatePoints()
# we will wait 3s here, so we can display next player
period = 3.0
time_before = time.time()
while (time.time() - time_before) < period:
time.sleep(0.001) # precision here
self.NextPlayer()
elif (self.actualTry == 3):
# last try now set a position on the table
sel = self.GetYahzeeMove(self.actualTry)
btn = sel + 1
# because we have one field space (6)
if(btn > 6):
btn = btn + 1
# get value
value = yahtzee_points.GetCalc(btn, self.dice)
# notify what
if(NOTIFY):
if(value > 0):
# we have a value
xbmcgui.Dialog().notification(ADDON_NAME,
self.GetPlayerName(self.actualPlayer, True) + '\n' + addon.getLocalizedString(31012 + btn),
time= self.time)
else:
# we discard a field
xbmcgui.Dialog().notification(ADDON_NAME,
self.GetPlayerName(self.actualPlayer, True) + '\n' +
addon.getLocalizedString(31042) + ': ' + addon.getLocalizedString(31012 + btn),
time= self.time)
# player x set field y
self.SetValuePlayer(self.actualPlayer, btn-1, value)
self.updatePoints()
# we will wait 3s here, so we can display next player
period = 3.0
time_before = time.time()
while (time.time() - time_before) < period:
time.sleep(0.001) # precision here
self.NextPlayer()
xbmc.sleep(200)
def GetPlayerName(self, playerNo, comp):
if(comp):
if(playerNo == 1):
return addon.getSetting('ply1') + ' (comp)'
elif(playerNo == 2):
return addon.getSetting('ply2') + ' (comp)'
elif(playerNo == 3):
return addon.getSetting('ply3') + ' (comp)'
elif(playerNo == 4):
return addon.getSetting('ply4') + ' (comp)'
else:
if(playerNo == 1):
return addon.getSetting('ply1')
elif(playerNo == 2):
return addon.getSetting('ply2')
elif(playerNo == 3):
return addon.getSetting('ply3')
elif(playerNo == 4):
return addon.getSetting('ply4')
return ""
def GetValuePlayer(self, playerNo):
if(playerNo == 1):
return self.pointsP1
if(playerNo == 2):
return self.pointsP2
if(playerNo == 3):
return self.pointsP3
if(playerNo == 4):
return self.pointsP4
def SetValuePlayer(self, playerNo, field, value):
points = self.GetValuePlayer(playerNo)
points[field] = value
top = 0
for i in range(6):
if(points[i] > 0):
top = top + points[i]
# bonus rule top area
if(top > 62):
top = top + 35
# bonus rule additional Yahtzee
if(points[12] == 50): # do we have already a Yahtzee ?
for i in range(6): # check 1 to 6
if(points[i] == ((i+1) * 5)): # do we have an additional Yahtzee's
top = top + 50 # add x Yahtzee / 50 points
bottom = 0
for i in range(7,14):
if(points[i] > 0):
bottom = bottom + points[i]
points[6] = top
points[14] = top + bottom
def NewGame(self):
self.game_round = 1
# we dont't start yet, so we can change player / computer
self.gameOn = False
self.diceOn = False
self.diceFinished = False
self.actualPlayer = 1
self.actualTry = 0
for i in range(15):
self.pointsP1[i] = -1
self.pointsP2[i] = -1
self.pointsP3[i] = -1
self.pointsP4[i] = -1
# reset hold
for i in range(5):
self.hold[i] = False
self.updateToggleButtons(0)
self.updatePoints()
# focus the dice button
self.setFocusId(5008)
def NextPlayer(self):
self.actualTry = 0
self.updateTry()
self.actualPlayer = self.actualPlayer + 1
#reset hold
for i in range(5):
self.hold[i] = False
if (self.actualPlayer > (self.player + self.computer)):
self.actualPlayer = 1
self.game_round = self.game_round + 1
if (self.game_round == 14):
self.gameOn = False # game over
showHigh = False
if(self.soundOn):
xbmc.playSFX(MEDIA_PATH + '\\applaus.wav')
maxPoints = 0
maxPlayer = 0
mode = 'win'
for n in range(1,5):
points = self.GetValuePlayer(n)
x = points[14]
if((x == maxPoints) and (x > 0)):
mode = 'draw'
if(x > maxPoints):
maxPoints = x
maxPlayer = n
mode = 'win'
if(mode == 'win'):
dialog = xbmcgui.Dialog()
confirmed = dialog.ok(ADDON_NAME,
addon.getLocalizedString(31051) + '\n' +
self.GetPlayerName(maxPlayer,False) + ": " + str(maxPoints))
else:
# draw
dialog = xbmcgui.Dialog()
confirmed = dialog.ok(ADDON_NAME,
addon.getLocalizedString(31052) + '\n' +
addon.getLocalizedString(31027) + ": " + str(maxPoints))
# for all players
for n in range(1,5):
points = self.GetValuePlayer(n)
# total points player n
x = points[14]
if(n <= self.player):
# loop through player highscores
for y in range(5):
s = scores["scorePlayer"][y]
if(x > s):
showHigh = True
dialog.ok(ADDON_NAME,
"Neuer Highscore" + '\n' +
"Spieler " + self.GetPlayerName(n, False) + '\n' +
"Platz " + str(y+1) + " mit " + str(x))
for z in range(3, y-1 ,-1):
scores["scorePlayer"][z+1] = scores["scorePlayer"][z]
scores["namePlayer"][z+1] = scores["namePlayer"][z]
scores["scorePlayer"][y] = x
scores["namePlayer"][y] = self.GetPlayerName(n, False)
break
else:
# loop through cpu highscores
for y in range(5):
s = scores["scoreCPU"][y]
if(x > s):
showHigh = True
dialog.ok(ADDON_NAME,
"Neuer Highscore CPU" + '\n' +
"Platz " + str(y+1) + " mit " + str(x))
for z in range(3, y-1 ,-1):
scores["scoreCPU"][z+1] = scores["scoreCPU"][z]
scores["scoreCPU"][y] = x
break
# save scores
with open(scoreFile, "w") as write_file:
json.dump(scores, write_file)
if(showHigh):
self.showHighscores()
self.updateToggleButtons(0);
# focus the dice button
self.setFocusId(5008)
self.delayComputer = 0
#if(self.actualPlayer <= self.player):
if(self.gameOn):
# first player x first dice
if(NOTIFY):
xbmcgui.Dialog().notification(ADDON_NAME,
self.GetPlayerName(self.actualPlayer, False),
time= self.time)
def showHighscores(self):
# show highscores
msg = '[B]Player highscores[/B]\n'
for t in range(5):
msg = msg + str(t + 1) + ". " + str(scores["scorePlayer"][t]) + " - " + str(scores["namePlayer"][t]) + "\n"
msg = msg + '[B]Top computer scores[/B]\n'
for t in range(5):
msg = msg + str(t + 1) + ". " + str(scores["scoreCPU"][t]) + "\n"
xbmcgui.Dialog().ok(ADDON_NAME, msg)
def updateToggleButtons(self, control_id):
# update player settings
self.p0x = self.getControl(5003)
self.p0x.setLabel(addon.getLocalizedString(31002) + str(self.player))
self.p0x = self.getControl(5004)
self.p0x.setLabel(addon.getLocalizedString(31003) + str(self.computer))
# update actual player
self.p0x = self.getControl(5006)
if(self.gameOn):
self.p0x.setLabel(addon.getLocalizedString(31006) + ' ' + str(self.actualPlayer))
else:
self.p0x.setLabel(addon.getLocalizedString(31005))
# protect for startup
self.p0x = self.getControl(5007)
self.p0x.setLabel(addon.getLocalizedString(31007) + ' ' + str(self.actualTry) + ' ' +
addon.getLocalizedString(31008) + ' 3')
if len(self.hold) < 4:
return
# set fcous / set for the hold button
for i in range(5):
self.p0x = self.getControl(5900 + i)
if(self.hold[i] == False):
self.p0x.setImage('t_button.png')
else:
self.p0x.setImage('t_button_sel.png')
if(control_id == (5200 + i)):
if(self.hold[i] == False):
self.p0x.setImage('t_button_active.png')
else:
self.p0x.setImage('t_button_active_sel.png')
# set fcous / set for the sound button
self.p0x = self.getControl(6005)
if(self.soundOn == False):
self.p0x.setImage('t_button.png')
else:
self.p0x.setImage('t_button_sel.png')
if(control_id == (5005)):
if(self.soundOn == False):
self.p0x.setImage('t_button_active.png')
else:
self.p0x.setImage('t_button_active_sel.png')
def updatePoints(self):
for i in range(15):
self.p0x = self.getControl(5400 + i)
if(self.pointsP1[i] >= 0):
self.p0x.setLabel(str(self.pointsP1[i]))
else:
self.p0x.setLabel('..')
self.p0x = self.getControl(5500 + i)
if(self.pointsP2[i] >= 0):
self.p0x.setLabel(str(self.pointsP2[i]))
else:
self.p0x.setLabel('..')
self.p0x = self.getControl(5600 + i)
if(self.pointsP3[i] >= 0):
self.p0x.setLabel(str(self.pointsP3[i]))
else:
self.p0x.setLabel('..')
self.p0x = self.getControl(5700 + i)
if(self.pointsP4[i] >= 0):
self.p0x.setLabel(str(self.pointsP4[i]))
else:
self.p0x.setLabel('..')
def updateTry(self):
self.p0x = self.getControl(5007)
self.p0x.setLabel(addon.getLocalizedString(31007) + ' ' + str(self.actualTry) + ' ' +
addon.getLocalizedString(31008) + ' 3')
def GetYahzeeMove(self, actTry):
data = []
for i in range(15):
data.append(0)
for i in range (6):
data[i] = self.GetValuePlayer(self.actualPlayer)[i]
for i in range (6,13):
data[i] = self.GetValuePlayer(self.actualPlayer)[i + 1]
data[13] = actTry
data[14] = (self.dice[0] * 10000) + (self.dice[1] * 1000) + (self.dice[2] * 100) + (self.dice[3] * 10) + (self.dice[4] * 1)
return yahtzee_logic.EinzelAbfrage(data)
def log(self, msg):
xbmc.log('[ADDON][%s] %s' % ('TEST', msg),
level=xbmc.LOGDEBUG)
# ----------------------------------------------------------------------------------------------------
if __name__ == '__main__':
game = Game(
'script-%s-main.xml' % ADDON_NAME,
ADDON_PATH,
'default',
'720p'
)
game.doModal()
del game
sys.modules.clear()