-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameplay.py
920 lines (691 loc) · 24.5 KB
/
gameplay.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
#!/usr/bin/env python
#default libs
import sys
import os
import math
import copy
import time
import pickle
import random
#gl stuff
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
#wx stuff
import wx
from wx import glcanvas
#cogslots libs
import cfg
import commongui
from Settings import Settings
import SlotReels
from CogSub import Subject
import subjectinfo
def fitScreen():
#get viewport origin and extent
global xpos, inset, radius, quad_width, theta, payline1, payline2, crossBox, sideBox, boxwidth
viewport = glGetIntegerv(GL_VIEWPORT)
#get modelview & projection matrix information
modelview = glGetDoublev(GL_MODELVIEW_MATRIX)
projection = glGetDoublev(GL_PROJECTION_MATRIX)
reels = len(allstops)
winY = windowSize[1] / 2
payline_size = windowSize[0] / 15
boxwidth = payline_size / 2
quad_width = (windowSize[0]-payline_size) / reels
count = 0
#coords = []
xpos = []
#quad_width = 20
for r in range(reels):
xpos.append([quad_width * (count + 1) + boxwidth, quad_width * count + boxwidth, quad_width * count + boxwidth, quad_width * (count + 1) + boxwidth])
count+=1
faces = len(allstops[0])
theta = (2 * math.pi) / faces
radius = quad_width / math.sin(theta/2) / 2
z = radius + 2
payline1 = [[0, winY - payline_size/2, z], [payline_size, winY, z], [0, winY + payline_size/2, z]]
payline2 = [[windowSize[0], winY - payline_size/2, z], [windowSize[0]-payline_size, winY, z], [windowSize[0], winY + payline_size/2, z]]
sideBox = [[0, 0, z], [0, windowSize[1], z], [boxwidth, windowSize[1], z], [boxwidth, 0, z]]
crossBox = [[0, 0, z], [0, boxwidth, z], [windowSize[0], boxwidth, z], [windowSize[0], 0, z]]
inset = 0
def LoadTextures():
global textures
global allstops
global images
count = 0
stops = []
for s in allstops:
stops = stops + s
images = list(set(stops))
print images
textures = glGenTextures(len(images))
for i in images:
imgpath = os.path.join(os.getcwd(), "images", i)
image = wx.Image(imgpath)
ix = image.GetSize()[0]
iy = image.GetSize()[1]
image = image.GetData()
# Create Texture
glBindTexture(GL_TEXTURE_2D, int(textures[count])) # 2d texture (x and y size)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGB, GL_UNSIGNED_BYTE, image)
count += 1
# A general OpenGL initialization function. Sets all of the initial parameters.
def InitGL(Width, Height): # We call this right after our OpenGL window is created.
LoadTextures()
glEnable(GL_TEXTURE_2D)
glClearColor(0.0, 0.0, 0.0, 1.0) # This Will Clear The Background Color To Black
glClearDepth(1.0) # Enables Clearing Of The Depth Buffer
glDepthFunc(GL_LESS) # The Type Of Depth Test To Do
glEnable(GL_DEPTH_TEST) # Enables Depth Testing
glShadeModel(GL_SMOOTH) # Enables Smooth Color Shading
glViewport(0, 0, Width, Height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity() # Reset The Projection Matrix
glOrtho(0, Width, 0, Height, -100000, 0)
glMatrixMode(GL_MODELVIEW)
fitScreen()
def drawCylinder(reelStops = [], xpos=[], xrot=0, stopAt=0):
faces = len(reelStops)
#quad_width = (2 * radius * math.sin(theta/2)) / 2
stopAngle = theta * stopAt# - (theta/2)
a = 0
b = 0
lastz = a + radius
lasty = b
#glTranslate(0.0, windowSize[0]/2, 0.0)
glRotatef(xrot,1.0,0.0,0.0)
for f in range(1, faces+1):
face = reelStops[f-1]
texture_num = images.index(face)
angle = theta * f
z = a + (radius * math.cos(angle))
y = b + (radius * math.sin(angle))
#print face, texture_num, textures
glBindTexture(GL_TEXTURE_2D, int(textures[texture_num]))
glBegin(GL_QUADS)
glColor3f(1.0,1.0,1.0)
glTexCoord2f(1.0, 1.0); glVertex3f(xpos[0], lasty, lastz)
glTexCoord2f(0.0, 1.0); glVertex3f(xpos[1], lasty, lastz)
glTexCoord2f(0.0, 0.0); glVertex3f(xpos[2], y, z)
glTexCoord2f(1.0, 0.0); glVertex3f(xpos[3], y, z)
lastz = z
lasty = y
glEnd() #done drawing the tile
glRotatef(-xrot,1.0,0.0,0.0)
deg = math.degrees(stopAngle)
if deg < 0:
return 360 - abs(deg)
else:
return deg
def drawPayline():
glColor3f(1.0,0.0,0.0)
z = payline1[0][2]
glBegin(GL_TRIANGLES)
#triangle 1
glVertex3f(payline1[0][0], payline1[0][1], payline1[0][2])
glColor3f(0.9, 0.8, 0.0)
glVertex3f(payline1[1][0], payline1[1][1], payline1[1][2])
glColor3f(1.0,0.0,0.0)
glVertex3f(payline1[2][0], payline1[2][1], payline1[2][2])
#triangle 2
glVertex3f(payline2[0][0], payline2[0][1], payline2[0][2])
glColor3f(0.9, 0.8, 0.0)
glVertex3f(payline2[1][0], payline2[1][1], payline2[1][2])
glColor3f(1.0,0.0,0.0)
glVertex3f(payline2[2][0], payline2[2][1], payline2[2][2])
glEnd() #done drawing the payline
#draw payline outline
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
glLineWidth(3)
glColor3f(0.5, 0.0, 0.0)
glBegin(GL_TRIANGLES)
#triangle 1
glVertex3f(payline1[0][0], payline1[0][1], payline1[0][2])
glVertex3f(payline1[1][0], payline1[1][1], payline1[1][2])
glVertex3f(payline1[2][0], payline1[2][1], payline1[2][2])
#triangle 2
glVertex3f(payline2[0][0], payline2[0][1], payline2[0][2])
glVertex3f(payline2[1][0], payline2[1][1], payline2[1][2])
glVertex3f(payline2[2][0], payline2[2][1], payline2[2][2])
glEnd() #done drawing the payline
glColor3f(0.0, 0.0, 0.0)
glBegin(GL_QUADS)
glVertex3f(0, 0, z)
glVertex3f(0, windowSize[1], z)
glVertex3f(windowSize[0], windowSize[1], z)
glVertex3f(windowSize[0], 0, z)
glVertex3f(boxwidth, boxwidth, z)
glVertex3f(boxwidth, windowSize[1] - boxwidth, z)
glVertex3f(windowSize[0] - boxwidth, windowSize[1] - boxwidth, z)
glVertex3f(windowSize[0] - boxwidth, boxwidth, z)
glEnd()
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
glColor3f(0.2, 0.2, 0.2)
drawBox(crossBox)
drawBox(sideBox)
glTranslatef(windowSize[0] - boxwidth, 0, 0)
drawBox(sideBox)
glLoadIdentity()
glTranslatef(0, windowSize[1] - boxwidth, 0)
drawBox(crossBox)
glLoadIdentity()
def drawBox(verts):
glBegin(GL_QUADS)
for v in verts:
glVertex3f(v[0],v[1], v[2])
glEnd()
class GamePlayGUI(wx.Frame):
""" The main gameplay GUI class """
def __init__(self, parent, settings="", subject="", *args, **kwargs):
# create the parent class
wx.Frame.__init__(self, parent, *args, **kwargs)
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
#self.SetSize((800, 600))
#bmp = wx.Bitmap('images/background.png')
#self.background = wx.StaticBitmap(self, -1, bmp, (0,0))
#initialize the game settings
if settings:
self.settings = settings
else:
dlg = wx.FileDialog(self, "Choose a settings file", os.path.join(os.getcwd(), "settings"), "", "*.set", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
f = open(path, "r")
self.settings = pickle.load(f)
f.close()
dlg.Destroy()
if subject:
self.subject = subject
else:
d = self.settings.subInfo
getinfo = False
for k in d.keys():
if d[k] == True:
getinfo = True
if getinfo:
infodialog = subjectinfo.SubjectInfoDialog(self, "Subject Info")
infodialog.enable_control("Name", d["Name"])
infodialog.enable_control("Age", d["Age"])
infodialog.enable_control("Sex", d["Sex"])
infodialog.enable_control("Handedness", d["Handedness"])
ans2 = infodialog.ShowModal()
if ans2 == wx.ID_SAVE:
#infodialog.save_info()
infodialog.save_info()
infodialog.cogsub.expname = self.settings.saveAs
infodialog.cogsub.session = self.settings.session
self.subject = infodialog.cogsub
else:
self.subject= Subject()
self.subject.expname = self.settings.saveAs
self.subject.session = self.settings.session
fname = "%s_%s_%s_%s" % (self.subject.expname, self.subject.s_id, self.subject.session, self.subject.date)
dlg = wx.FileDialog(self, "Choose a location to save subject data file", os.getcwd(), fname, "*.csv", wx.SAVE)
if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
self.subject.fpath = path
dlg.Destroy()
#create a Slots object
self.slots = self.settings.slots
self.round = 1
self.balance = self.settings.seed
# the pretty background - not working properly yet
self.SetOwnBackgroundColour(cfg.STEEL_BLUE)
#print self.settings.combos
# get the user params from the database
self.get_user_params()
# create the sizer that everything fits into
self.sizer = wx.FlexGridSizer(4, 1, 5, 5)
# populate the payout sizer with values from the database
if self.settings.showPayouts:
self.payoutpanel = commongui.PayoutTable(self, self.settings, cfg.LIGHT_GREY)
else:
self.payoutpanel = wx.Panel(self, wx.ID_ANY)
#self.payoutpanel.Bind(wx.EVT_PAINT, self.on_paint)
self.payoutpanel.SetBackgroundColour(cfg.STEEL_BLUE)
self.payoutpanel.SetForegroundColour(cfg.LIGHT_GREY)
self.payoutpanel.SetWindowStyle(wx.RAISED_BORDER)
# create the first row
centeredflag = wx.SizerFlags(1).Align(wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER)
self.sizer.AddF(self.payoutpanel, centeredflag)
# create the text boxes
wagersizer, self.wagertext = self.create_labeled_num_box("Wager")
self.wagertext.SetValue(str(self.settings.betsizes[0]))
winsizer, self.wintext = self.create_labeled_num_box("Win")
balancesizer, self.balancetext = self.create_labeled_num_box("Balance", str(self.balance))
bottomflag = wx.SizerFlags(1).Align(wx.ALIGN_BOTTOM|wx.ALIGN_CENTER).Border(wx.ALL, 5)
#sizer for the info (wager size, balance, win)
infosizer = wx.BoxSizer(wx.HORIZONTAL)
infosizer.AddF(wagersizer, bottomflag)
infosizer.AddF(winsizer, bottomflag)
infosizer.AddF(balancesizer, bottomflag)
# the buttons will have to go in a separate sub-sizer
buttonsizer = wx.BoxSizer(wx.HORIZONTAL)
self.increasebtn = wx.BitmapButton(self, wx.ID_ANY, commongui.makeBitmap(cfg.IM_INCREASEWAGER), style = wx.NO_BORDER)
self.decreasebtn = wx.BitmapButton(self, wx.ID_ANY, commongui.makeBitmap(cfg.IM_DECREASEWAGER), style = wx.NO_BORDER)
self.spinbtn = wx.BitmapButton(self, wx.ID_ANY, commongui.makeBitmap(cfg.IM_SPIN), style = wx.NO_BORDER)
self.spinbtn.SetBitmapDisabled(commongui.makeBitmap(cfg.IM_SPIN_DEAC))
self.increasebtn.SetBitmapDisabled(commongui.makeBitmap(cfg.IM_INCREASEWAGER_DEAC))
self.decreasebtn.SetBitmapDisabled(commongui.makeBitmap(cfg.IM_DECREASEWAGER_DEAC))
buttonsizer.AddF(self.decreasebtn, bottomflag)
buttonsizer.AddF(self.spinbtn, bottomflag)
buttonsizer.AddF(self.increasebtn, bottomflag)
#spinning reel
self.create_spinning_wheel(self.sizer)
#buttons and info
self.sizer.AddF(infosizer, bottomflag)
self.sizer.AddF(buttonsizer, bottomflag)
self.sizer.AddStretchSpacer()
# create an outer sizer to have a nice border
outersizer = wx.BoxSizer(wx.VERTICAL)
outersizer.AddF(self.sizer, wx.SizerFlags(1).Expand().Align(
wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER).Border(wx.ALL, 20));
self.SetSizerAndFit(outersizer)
# bindings
self.decreasebtn.Bind(wx.EVT_BUTTON, lambda event, name='decrease':self.OnChangeWager(event, name))
self.increasebtn.Bind(wx.EVT_BUTTON, lambda event, name='increase':self.OnChangeWager(event, name))
self.Bind(wx.EVT_BUTTON, self.OnSpin, self.spinbtn)
# these bindings are for the not-quite-functional background
self.Bind(wx.EVT_SIZE, self.OnSize)
f = open('introtext.html', 'w')
f.write(self.settings.instructions)
f.close()
# create the initial instructions dialog
dialog = commongui.InfoDialog(self, "Welcome to CogSlots", 'introtext.html')
if (dialog.ShowModal() == wx.ID_CANCEL):
sys.exit(0)
#if gamblersFallacy, need to purge near misses from the combos list
if self.settings.gamblersFallacy:
newComs = []
for c in self.settings.combos:
if cfg.IM_BLANK not in c:
newComs.append(c)
self.settings.combos = newComs
# show thyself
self.Centre()
self.Show(True)
self.Refresh()
self.Update()
#starting vars to monitor subject activity
self.startTime = time.clock()
self.wagerIncreases = 0
self.wagerDecreases = 0
def on_paint(self, event):
# establish the painting canvas
dc = wx.PaintDC(self.payoutpanel)
x = 0
y = 0
w, h = self.payoutpanel.GetSize()
#dc.GradientFillLinear((x, y, w, h), cfg.STEEL_BLUE, cfg.DARK_BLUE, 1)
def create_labeled_num_box(self, label, defaultvalue="0"):
GAME_FONT = wx.FFont(16, family=wx.FONTFAMILY_SWISS, flags=wx.FONTFLAG_BOLD)
panel = wx.Panel(self)
panel.SetFont(GAME_FONT)
panel.SetForegroundColour(cfg.LIGHT_GREY)
panel.SetBackgroundColour(cfg.STEEL_BLUE)
box = wx.BoxSizer(wx.HORIZONTAL)
box.AddF(wx.StaticText(panel, wx.ID_ANY, label), wx.SizerFlags().Centre().Border(wx.TOP|wx.LEFT|wx.RIGHT, 10))
textbox = wx.TextCtrl(panel, wx.ID_ANY, style=wx.TE_READONLY|wx.TE_RIGHT)
box.AddF(textbox, wx.SizerFlags().Centre().Border(wx.BOTTOM|wx.LEFT|wx.RIGHT, 10))
textbox.SetValue(defaultvalue)
textbox.SetBackgroundColour(cfg.STEEL_BLUE)
textbox.SetForegroundColour(cfg.LIGHT_GREY)
panel.SetSizer(box)
return panel, textbox
def get_user_params(self):
#NOTE: this is stuff that should be retrieved from the database
self.settings.betsizes.sort()
self.balance = self.settings.seed# - self.settings.betsizes[0]
self.debtallowed = self.settings.debt
self.currency = self.settings.currency
self.numrounds = self.settings.rounds
self.betsizes = self.settings.betsizes
def num_val(self, text):
if text is '':
return self.num_val('0')
return commongui.StringToType(text)
def create_spinning_wheel(self, sizer, before=2, after=1):
global allstops, xrot, windowSize, stopAt, settle, inc
allstops = []
settle = False
inc = 0
windowSize = (600, 350)
reels = self.settings.slots.reels
for r in reels:
symbolList = []
for s in r.stops:
symbolList.append(r.symbols[s])
allstops.append(symbolList)
xrot = [0.0] * len(allstops)
stopAt = [0] * len(allstops)
self.GLinitialized = False
attribList = (glcanvas.WX_GL_RGBA, # RGBA
glcanvas.WX_GL_DOUBLEBUFFER, # Double Buffered
glcanvas.WX_GL_DEPTH_SIZE, 24) # 24 bit
#
# Create the canvas
self.reelBox = glcanvas.GLCanvas(self, attribList=attribList)
self.reelBox.SetSize(windowSize)
self.reelBox.Refresh(True)
#
# Set the event handlers.
self.reelBox.Bind(wx.EVT_ERASE_BACKGROUND, self.processEraseBackgroundEvent)
self.reelBox.Bind(wx.EVT_SIZE, self.processSizeEvent)
self.reelBox.Bind(wx.EVT_PAINT, self.processPaintEvent)
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.OnDraw, self.timer)
sizer.AddF(self.reelBox, wx.SizerFlags().Align(wx.ALIGN_CENTER))
def phoneySpin(self):
if self.settings.gamblersFallacy:
random.shuffle(self.settings.stimList)
theItem = self.settings.stimList.pop(0)
else:
odds = self.settings.override['odds']
nms = self.settings.override['nearMiss']
itemList =[]
index = 0
for o, nm in zip(odds, nms):
item = self.settings.combos[index]
itemList = itemList + ([item] * o)
if nm:
newItem = copy.deepcopy(item)
newItem[0] = cfg.IM_BLANK
random.shuffle(newItem)
itemList = itemList + ([newItem] * o)
index = index + 1
if nm:
numLoss = 100 - sum(odds) - sum(nms)
else:
numLoss = 100 - sum(odds)
itemList = itemList + (['LOSS'] * numLoss)
theItem = random.choice(itemList)
if theItem != "LOSS":
payline = theItem
if cfg.IM_EMPTY in theItem:
for i in range(0, len(theItem)):
if theItem[i] == cfg.IM_EMPTY:
theItem[i] = random.choice(self.settings.visibleSymbols)
#now we need to come up with the actual payline numbers
stopAt = []
count = 0
for item, reel in zip(theItem, self.settings.slots.reels):
symbolIndex = reel.symbols.index(item)
indeces = []
symcount = 0
for stop in reel.stops:
if stop == symbolIndex:
indeces.append(symcount)
symcount += 1
stopAt.append(random.choice(indeces))
count += 1
else:
loss = False
while not loss:
imageList, payline, stopAt = self.slots.spin()
outcome = self.judgeOutcome(payline)
if not outcome:
loss = True
return payline, stopAt
def OnSpin(self, event):
global settle, inc, stopAt
self.subject.inputData(self.round, 'oldbalance', self.balance)
wager = commongui.StringToType(self.wagertext.GetValue())
self.balance -= wager
self.balancetext.SetValue(str(self.balance))
self.wintext.SetValue("0")
RT = time.clock() - self.startTime
self.subject.inputData(self.round, "RT", RT)
self.subject.inputData(self.round, "wagerInc", self.wagerIncreases)
self.subject.inputData(self.round, "wagerDec", self.wagerDecreases)
self.wagerIncreases = 0
self.wagerDecreases = 0
self.spinbtn.Disable()
self.decreasebtn.Disable()
self.increasebtn.Disable()
if self.settings.gamblersFallacy or self.settings.override['engage']:
payline,stopAt = self.phoneySpin()
else:
imageList, payline, stopAt = self.slots.spin(2)
self.payline = payline
self.timer.Start(1)
pcount = 1
for p in payline:
self.subject.inputData(self.round, 'Reel %s' % pcount, p)
pcount += 1
settle = False
#SPIN!
inc = 30
self.spinning = True
def afterSpin(self):
self.startTime = time.clock()
wager = commongui.StringToType(self.wagertext.GetValue())
win = self.judgeOutcome(self.payline)
if win and win != "NEAR MISS":
payout = self.settings.payouts[win-1]
self.subject.inputData(self.round, 'outcome', 'WIN')
self.balance += wager*payout
self.subject.inputData(self.round, 'delta', wager*payout)
# Update the balance text box with the current balance
self.wintext.SetValue(str(wager*payout))
else:
payout = 0
if win == "NEAR MISS":
self.subject.inputData(self.round, 'outcome', 'NEAR MISS')
else:
self.subject.inputData(self.round, 'outcome', 'LOSS')
self.wintext.SetValue("-%s" % str(wager))
self.subject.inputData(self.round, 'delta', -wager)
self.subject.inputData(self.round, 'wager', wager)
self.subject.inputData(self.round, 'payout', payout)
self.subject.inputData(self.round, 'newbalance', self.balance)
self.balancetext.SetValue(str(self.balance))
# Reset the wager to zero
self.wagertext.SetValue(str(self.settings.betsizes[0]))
if self.settings.probDict['obtain'] == True:
msg = self.settings.probDict['msg']
pround = self.settings.probDict['interval']
if (self.round) % pround == 0:
dia = commongui.ProbDialog(self, "Probability Estimate", msg)
outcome = dia.ShowModal()
if outcome == wx.ID_OK:
est = dia.est.GetValue()
est = est.replace(",", "_")
self.subject.inputData(self.round, 'estimate', est)
else:
self.subject.inputData(self.round, 'estimate', "NA")
else:
self.subject.inputData(self.round, 'estimate', "NA")
self.round += 1
self.Refresh()
self.Update()
if self.balance <= 0 and not self.settings.debt:
self.gameOver("You're out of money.")
# Check to see if the maximum number of rounds has been reached
if self.round > self.settings.rounds:
self.gameOver("Round limit reached.")
self.subject.printData()
def judgeOutcome(self, payline):
#if we are dealing with the 'any' symbol, we must account for that
any_sym = False
for c in self.settings.combos:
if cfg.IM_EMPTY in c:
any_sym = True
if any_sym:
#if the any symbol is involved, grade accordingly
for c in self.settings.combos:
match = []
for cc, p in zip(c, payline):
if cc == cfg.IM_EMPTY or cc == p:
match.append(self.settings.combos.index(c) + 1)
else:
match.append(0)
if not match.count(0):
#if there's a winning combo in here, return it
return match[0]
else:
if payline.count(cfg.IM_BLANK) == 1:
i = payline.index(cfg.IM_BLANK)
for c in self.settings.combos:
count = 0
matchCount = 0
match = []
for cc, p in zip(c, payline):
if count != i:
if cc == cfg.IM_EMPTY or cc == p:
matchCount += 1
count += 1
if matchCount == (len(payline) - 1):
return "NEAR MISS"
else:
#otherwise just check for payline membership in combo list
if payline in self.settings.combos:
return self.settings.combos.index(payline) + 1
#but we have to see whether it's a near miss
if payline.count(cfg.IM_BLANK) == 1:
i = payline.index(cfg.IM_BLANK)
for c in self.settings.combos:
count = 0
matchCount = 0
for pp, cc in zip(payline, c):
if count != i:
if pp == cc:
matchCount += 1
count += 1
if matchCount == (len(payline) - 1):
return "NEAR MISS"
return 0
# Callbacks!
def OnChangeWager(self, event, name):
wager = self.wagertext.GetValue()
wager = commongui.StringToType(wager)
i = self.betsizes.index(wager)
# if we can't increase beyond zero, stop doing anything
if 'increase' in name:
self.wagerIncreases += 1
if (i + 1) >= len(self.betsizes):
self.wagerstep = self.betsizes[i+1]
else:
self.wagerstep = self.betsizes[i+1]
if (self.balance < self.wagerstep) and not self.settings.debt:
pass
else:
wager = self.wagerstep
elif 'decrease' in name:
self.wagerDecreases += 1
if i == 0:
self.wagerstep = self.betsizes[i]
else:
self.wagerstep = self.betsizes[i-1]
wager = self.wagerstep
self.wagertext.SetValue(str(wager))
self.balancetext.SetValue(str(self.balance))
def gameOver(self, msg):
self.subject.printData()
self.subject.preserve()
dlg = wx.MessageDialog(self, msg, "Game over", wx.OK)
dlg.ShowModal()
dlg.Destroy()
self.Destroy()
def OnSize(self, event):
#self.background = wx.ArtProvider.GetBitmap(cfg.IM_BACKGROUND, size=self.GetSize())
event.Skip()
self.Refresh(False)
#
# Canvas Proxy Methods
def GetGLExtents(self):
"""Get the extents of the OpenGL canvas."""
return self.reelBox.GetClientSize()
def SwapBuffers(self):
"""Swap the OpenGL buffers."""
self.reelBox.SwapBuffers()
#
# wxPython Window Handlers
def processEraseBackgroundEvent(self, event):
"""Process the erase background event."""
pass # Do nothing, to avoid flashing on MSWin
def processSizeEvent(self, event):
"""Process the resize event."""
if self.reelBox.GetContext():
# Make sure the frame is shown before calling SetCurrent.
self.Show()
self.reelBox.SetCurrent()
size = self.GetGLExtents()
self.OnReshape(size.width, size.height)
event.Skip()
def processPaintEvent(self, event):
"""Process the drawing event."""
self.reelBox.SetCurrent()
# This is a 'perfect' time to initialize OpenGL ... only if we need to
if not self.GLinitialized:
self.OnInitGL()
self.GLinitialized = True
self.OnDraw()
event.Skip()
#
# GLFrame OpenGL Event Handlers
def OnInitGL(self):
InitGL(windowSize[0], windowSize[1])
def OnReshape(self, width, height):
"""Reshape the OpenGL viewport based on the dimensions of the window."""
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(-0.5, 0.5, -0.5, 0.5, -1, 1)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
def OnDraw(self, *args, **kwargs):
"Draw the window."
global xrot, textures, texture_num, settle, radius, inset, inc, settle
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Clear The Screen And The Depth Buffer
glLoadIdentity() # Reset The View
glDisable(GL_TEXTURE_2D)
drawPayline()
glTranslatef(0.0,windowSize[1]/2 - quad_width/2,0.0) # Move Into The Screen
#glBindTexture(GL_TEXTURE_2D, int(textures[texture_num]))
glEnable(GL_TEXTURE_2D)
stopAngles = []
for s, p, r, stop in zip(allstops, xpos, xrot, stopAt):
sa = drawCylinder(s, p, r, stop)
stopAngles.append(sa)
#drawCylinder(allstops[1], 1.5, 0, xrot)
#drawCylinder(allstops[2], 1.5, .65, xrot)
#glBindTexture(GL_TEXTURE_2D, textures[0])
if xrot[0] > 365 and not settle:
inc = 21
if xrot[0] > 720 and not settle:
inc = 14
if xrot[0] > 1080 and not settle:
inc = 7
if xrot[0] > 1440:
settle = True
xrot = map(lambda x: x % 360, xrot)
#print settle
if settle:
inc = inc - 1
if inc < 1:
inc = 1
count = 0
stoppedReels = 0
for xr, sa in zip(xrot, stopAngles):
if int(xr % 360) == int(sa):
xrot[count] = xr
stoppedReels += 1
else:
xrot[count] = xr + inc
if stoppedReels == len(xrot) and self.spinning:
self.spinbtn.Enable()
self.decreasebtn.Enable()
self.increasebtn.Enable()
self.spinning = False
self.afterSpin()
count += 1
else:
xrot = map(lambda x: x + inc, xrot)
self.SwapBuffers()
if __name__ == "__main__":
app = wx.App(False)
mainframe = GamePlayGUI(None)
app.MainLoop()