def __init__(self, width=700, height=500): self.colors = [self.red[:], self.white[:], self.green[:], self.yellow[:]] self.colornames = ['red', 'white', 'green', 'yellow'] boolgame.BoolGame.__init__(self, self.title, width, height, description=self.descriptiontext, color = self.color) self.loadGameSettings() self.leftBtn = RectangularButton('yellow', 1, self.width//2 - 120, self.description.y - 100, w = 120, h = 100, color = self.solarized, textcolor=self.red, textsize = 22) self.rightBtn = RectangularButton('white', 1, self.width//2 + 20, self.description.y - 100, w = 120, h = 100, color = self.solarized, textcolor=self.yellow, textsize = 22)
class ColorMeaningGame(boolgame.BoolGame, Colors): title = 'Color Meaning' color = '#0B3526' descriptiontext = 'Check if meaning of text on left is same as color of text on right' gameid = 'colormeaning' def __init__(self, width=700, height=500): self.colors = [self.red[:], self.white[:], self.green[:], self.yellow[:]] self.colornames = ['red', 'white', 'green', 'yellow'] boolgame.BoolGame.__init__(self, self.title, width, height, description=self.descriptiontext, color = self.color) self.loadGameSettings() self.leftBtn = RectangularButton('yellow', 1, self.width//2 - 120, self.description.y - 100, w = 120, h = 100, color = self.solarized, textcolor=self.red, textsize = 22) self.rightBtn = RectangularButton('white', 1, self.width//2 + 20, self.description.y - 100, w = 120, h = 100, color = self.solarized, textcolor=self.yellow, textsize = 22) def on_draw(self): self.window.clear() self.leftBtn.draw() self.rightBtn.draw() def addNew(self): self.syncKey = True self.answer = maths.weightedRandomIndex([0.5, 0.5]) # 0.5 for 0 i.e wrong answer leftid = maths.randint(0,3) leftnameid = maths.randint(0,3) if self.answer == 0: rightid_pdf = popList(leftid, 0.2) + [0.4] + popList(3-leftid, 0.2) # 0.4 chance left color = right color rightid = leftnameid while rightid == leftnameid: rightid = maths.weightedRandomIndex(rightid_pdf) rightnameid = maths.randint(0,3) else: rightid = leftnameid rightnameid_pdf = popList(leftid, 0.2) + [0.4] + popList(3-leftid, 0.2) rightnameid = maths.weightedRandomIndex(rightnameid_pdf) self.rightBtn.label.text = self.colornames[rightnameid] self.rightBtn.label.color = self.colors[rightid] + [255] self.leftBtn.label.text = self.colornames[leftnameid] self.leftBtn.label.color = self.colors[leftid] + [255] self.syncKey = False
def __init__(self, title, score, width=600, height=500, highscore = 0): self.window = pyglet.window.Window(width, height, caption = title) self.heading = pyglet.text.Label(title, font_size=30, x = width // 2, y = height - 60, anchor_x = 'center') self.score = pyglet.text.Label(str(score), font_size=26, font_name='Verdana', x = width // 2, y = self.heading.y - 100, anchor_x = 'center') self.highest = pyglet.text.Label('Best : ' + str(highscore), font_size = 16, x = width // 2, y = self.score.y - 50, anchor_x = 'center', color = [70,70,70,255]) self.againBtn = RectangularButton('Play Again', 1, x = width // 2 - 75, y = self.highest.y - 60, w = 150, h = 60, textsize = 18) self.backBtn = RectangularButton('Exit', 2, x = width // 2 - 75, y = self.againBtn.y - 70, w = 150, h= 60, color = [0,255,0], textsize = 18) self.clickables = [self.againBtn, self.backBtn] self.retCode = 0 @self.window.event def on_draw(): self.window.clear() self.heading.draw() self.score.draw() self.highest.draw() self.againBtn.draw() self.backBtn.draw() @self.window.event def on_close(): self.retCode = 0 @self.window.event def on_mouse_release(x, y, button, modifiers): if button != pyglet.window.mouse.LEFT: return for i in self.clickables: if x < i.x or x > (i.x + i.w): continue if y > i.y or y < (i.y - i.h): continue self.click_event(i.value) break
def __init__(self, title, score, width=600, height=500, highscore=0): self.window = pyglet.window.Window(width, height, caption=title) self.heading = pyglet.text.Label(title, font_size=30, x=width // 2, y=height - 60, anchor_x='center') self.score = pyglet.text.Label(str(score), font_size=26, font_name='Verdana', x=width // 2, y=self.heading.y - 100, anchor_x='center') self.highest = pyglet.text.Label('Best : ' + str(highscore), font_size=16, x=width // 2, y=self.score.y - 50, anchor_x='center', color=[70, 70, 70, 255]) self.againBtn = RectangularButton('Play Again', 1, x=width // 2 - 75, y=self.highest.y - 60, w=150, h=60, textsize=18) self.backBtn = RectangularButton('Exit', 2, x=width // 2 - 75, y=self.againBtn.y - 70, w=150, h=60, color=[0, 255, 0], textsize=18) self.clickables = [self.againBtn, self.backBtn] self.retCode = 0 @self.window.event def on_draw(): self.window.clear() self.heading.draw() self.score.draw() self.highest.draw() self.againBtn.draw() self.backBtn.draw() @self.window.event def on_close(): self.retCode = 0 @self.window.event def on_mouse_release(x, y, button, modifiers): if button != pyglet.window.mouse.LEFT: return for i in self.clickables: if x < i.x or x > (i.x + i.w): continue if y > i.y or y < (i.y - i.h): continue self.click_event(i.value) break