def do_button(self, bu): if bu == 'back': self.pages_on() return if bu == 'try': value = self.ctry.try1() return value if bu == 'clear': self.ctry.clear() return if bu == 'replay': self.ctry.setup() return if bu == 'minus': self.do_key(pygame.K_MINUS) return if bu == 'space': self.do_key(pygame.K_SPACE) return if bu == 'fd': self.pages.fd() return if bu == 'bk': self.pages.bk() return if bu == 'blue': g.pages = False buttons.on(('clear', 'try', 'minus', 'space', 'replay')) buttons.off(('fd', 'blue', 'bk'))
def do_button(self, bu): if bu == 'reset': self.board.reset() buttons.off('reset') if bu == 'new': self.board.setup() buttons.off('reset')
def click(self): if self.aim.running: return False if g.wrong: return False ind = self.which() if ind == -1: return False if len(self.aim.list1) == 0: return False self.player.glow_start(ind) if self.sugar: self.back_button.set_sensitive(False) else: buttons.off('back') if ind == self.aim.list1[g.player_n]: g.player_n += 1 if g.player_n > g.score: g.score = g.player_n if g.player_n == len(self.aim.list1): # all correct - add another self.aim.inc() g.player_n = 0 else: g.wrong = True g.wrong_ind = ind g.right_ind = self.aim.list1[g.player_n] if self.sugar: self.green_button.set_sensitive(True) else: buttons.on('green') return True # click processed
def display(self): g.screen.fill(utils.WHITE) if g.toc_showing: g.screen.blit(self.toc.surf, (g.offset, 0)) buttons.draw() return g.screen.blit(self.layout.surf, (g.offset, 0)) if g.jig: self.jig.draw() if g.mouse_locn: x, y = pygame.mouse.get_pos() m = '(' + str(x) + ',' + str(y) + ')' cxy = (g.sx(29), g.sy(1.2)) utils.message(g.screen, g.font1, m, cxy, 5) if g.colors: g.screen.blit(g.colors_img, g.colors_xy) if utils.mouse_on_img(g.colors_img, g.colors_xy): c = g.screen.get_at(pygame.mouse.get_pos()) r, g1, b = '0', '0', '0' if c[0] > 200: r = '255' if c[1] > 200: g1 = '255' if c[2] > 200: b = '255' m = '(' + r + ',' + g1 + ',' + b + ')' cxy = (g.sx(5.3), g.sy(19.5)) utils.message(g.screen, g.font1, m, cxy, 5) if self.layout.movie != None: self.layout.movie.draw() buttons.on(['fd', 'back']) if g.page == 1: buttons.off('back') elif g.page == g.last_page: buttons.off('fd') buttons.draw() if g.rect_on: pygame.draw.rect(g.screen, utils.GREEN, g.rect) if self.popup != None: surf, x, y = self.popup g.screen.blit(surf, (x, y))
def reset(self): g.state = 1 g.top = utils.copy_list(g.nos) g.buffr = [] buttons.off(['plus', 'times', 'equals']) buttons.off('back') self.mouse_init()
def do_key(self, key): if key in g.SQUARE: g.state = 0 g.grid.setup() buttons.off("cyan") return if key == pygame.K_v: g.version_display = not g.version_display return
def fast_start(self): #self.start_ms=pygame.time.get_ticks() self.cg() self.home() self.n = self.poly_n self.a = 360 / self.n self.i = 0 self.j = 0 buttons.off('turtle')
def run(self): g.init() if not self.journal: utils.load() self.board = sud.Board() self.board.setup() load_save.retrieve() self.board.check() self.buttons_setup() if self.journal: # Sugar only a, b, c, d = pygame.cursors.load_xbm('my_cursor.xbm', 'my_cursor_mask.xbm') pygame.mouse.set_cursor(a, b, c, d) going = True while going: # Pump GTK messages. while gtk.events_pending(): gtk.main_iteration() # Pump PyGame messages. for event in pygame.event.get(): if event.type == pygame.QUIT: # only in standalone version if not self.journal: utils.save() going = False elif event.type == pygame.MOUSEMOTION: g.redraw = True if self.canvas <> None: self.canvas.grab_focus() elif event.type == pygame.MOUSEBUTTONDOWN: g.redraw = True if event.button == 2: # centre button if not self.journal: g.version_display = not g.version_display if event.button == 1: bu = buttons.check() if bu != '': self.do_button(bu) elif not g.finished: if not self.help_check(): self.board.click() if g.finished: buttons.on('new') buttons.off('reset') if event.button == 3: if not g.finished: self.board.right_click() if not going: break if g.redraw: self.display() if g.version_display: utils.version_display() #g.screen.blit(g.pointer,(g.mx,g.my)) pygame.display.flip() g.redraw = False self.count = g.count tf = False if pygame.mouse.get_focused(): tf = True pygame.mouse.set_visible(tf) g.clock.tick(40)
def buttons_setup(self): cx=g.sx(30.25); cy=g.sy(6.5); dy=g.sy(2) buttons.Button('save',(cx,cy)); cy+=dy y1=cy; cy+=2*dy buttons.Button('load',(cx,cy)); cy+=dy y2=cy; cy+=2*dy buttons.Button('clear',(cx,cy)); cy+=dy self.save_c=(cx,y1); self.load_c=(cx,y2) if g.saves_n==0: buttons.off('load') self.load_d=g.sy(.5) # half size of number for clicking
def do_button(self, bu): if bu == 'new': if g.state == 3: if self.jigsaw.complete(): n = self.jigsaw.pic_n if g.level > g.best[n - 1]: g.best[n - 1] = g.level g.state = 2 buttons.off('new') self.menu.orange = None self.menu.orange_set()
def display(self): g.screen.fill((0, 0, 120)) self.som.draw() if self.som.complete(): buttons.off(['cream', 'yellow']) buttons.on('black') else: buttons.on(['cream', 'yellow']) buttons.off('black') buttons.draw()
def new1(self): g.nos = self.gen_nos() g.aim = self.gen_aim() g.top = utils.copy_list(g.nos) g.buffr = [] buttons.off(['plus', 'times', 'equals']) buttons.off('back') g.state = 1 self.mouse_init() self.anim_start() self.scored = False
def run(self): g.init() self.rects=rects.Rects() if not self.journal: utils.load() else: g.level=self.level self.slider=slider.Slider(g.sx(16),g.sy(20.5),10,utils.GREEN) self.new1() bx=g.sx(29.5); by=g.sy(12) buttons.Button("cyan",(bx,by),True) by=g.sy(16) buttons.Button("black",(bx,by),True) if self.journal: # Sugar only a,b,c,d=pygame.cursors.load_xbm('my_cursor.xbm','my_cursor_mask.xbm') pygame.mouse.set_cursor(a,b,c,d) going=True while going: # Pump GTK messages. while gtk.events_pending(): gtk.main_iteration() # Pump PyGame messages. for event in pygame.event.get(): if event.type==pygame.QUIT: if not self.journal: utils.save() going=False elif event.type == pygame.MOUSEMOTION: g.redraw=True elif event.type == pygame.MOUSEBUTTONDOWN: g.redraw=True if event.button==2: # centre button if not self.journal: g.version_display=not g.version_display; break bu=buttons.check() if bu<>'': self.button(bu); break if self.slider.mouse(): self.new1(); break if self.rects.click(): if not g.magic_show: if self.rects.correct(): g.score+=g.level; g.magic_show=True buttons.off("black") if not going: break if g.redraw: self.display() if g.version_display: utils.version_display() pygame.display.flip() g.redraw=False tf=False if pygame.mouse.get_focused(): tf=True pygame.mouse.set_visible(tf) g.clock.tick(40) # be ready for xo quit at any time self.level=g.level
def draw(self): g.screen.fill((100, 0, 100)) if self.current == None: self.current = 1 if self.img == None: file1 = str(self.current) + '.png' self.img = utils.load_image(file1, False, 'pages') g.screen.blit(self.img, self.xy) buttons.on(('fd', 'bk')) if self.current == 1: buttons.off('bk') if self.current == 10: buttons.off('fd') s = 'The Flags of the World page ' + str(self.current) utils.text_blit1(g.screen, s, g.font1, self.textxy, utils.CREAM, False)
def buttons_control(self): if g.button_display: buttons.on(['back', 'fd']) if g.tess_n == 1: buttons.off('back') if g.tess_n > g.max_n: buttons.off('fd') if g.tess_n == len(g.tesses): buttons.off('fd') if g.tess_n > g.max_n or self.tessl.complete(): buttons.off('solve') else: buttons.on('solve') else: buttons.off(['back', 'fd', 'solve'])
def do_button(bu): if bu == 'green': player_start() g.checked = False elif bu == 'red': player.stop() elif bu == 'cyan': next1() buttons.off('cyan') elif bu == 'white': player.clear() elif bu == 'turtle': player.toggle_turtle()
def buttons_setup(self): d = g.d + g.space x = g.xc y = g.y0 + d dy = d buttons.Button('reset', (x, y), True) y += dy buttons.Button('new', (x, y), True) y += dy g.yc = y + d + d # for count if g.count == 0: buttons.off('new') if g.started == 0: buttons.off('reset') # turned on when tile placed by sud.click()
def do_button(self, bu): if bu == 'green': # start self.aim.new1() g.player_n = 0 g.wrong = False g.score = 0 if self.sugar: self.green_button.set_sensitive(True) self.back_button.set_sensitive(False) else: buttons.off('green') buttons.on('back') elif bu == 'back': self.aim.start() # show again
def do_button(self, bu): max_n = len(g.tesses) if bu == 'fd': # next tessellation g.tess_n += 1 if g.tess_n > max_n: g.tess_n = 1 self.tessl = tess.Tess(g.tesses[g.tess_n - 1]) elif bu == 'back': # previous tessellation g.tess_n -= 1 if g.tess_n < 1: g.tess_n = max_n self.tessl = tess.Tess(g.tesses[g.tess_n - 1]) elif bu == 'solve': self.tessl.solve() buttons.off('solve') self.tess_n = g.tess_n
def do_button(self,bu): for n in range(1,19): if bu==str(n): self.chess.set_layout(n); self.chess.setup() for b in range(1,19): buttons.off(str(b)) buttons.on(['menu','new']) if self.chess.layout in self.chess.help: buttons.on('help') g.menu=False; return if bu=='menu': self.menu(); return if bu=='help': if g.help1: g.help1=False; buttons.on('new') else: self.help1() if bu=='new': self.chess.setup()
def do_button(self,button): if button=='equals': self.calc() buttons.off(['plus','times','equals']) if self.correct(): if not g.correct: g.score+=g.level g.correct=True elif button=='back': self.reset() elif button=='new': self.new1() else: g.buffr.append(button) buttons.off(['plus','times','equals'])
def display(self): g.screen.fill(self.colors[1]) if not self.sugar: g.screen.blit(g.bgd, (g.sx(0), 0)) self.let.draw() if self.sugar: self.back_button.set_sensitive(False) self.tick_button.set_sensitive(False) else: buttons.off(['back', 'tick']) if g.state in (2, 4): if len(self.let.ans) > 0: if self.sugar: self.back_button.set_sensitive(True) else: buttons.on('back') if len(self.let.ans) > 1: if self.sugar: self.tick_button.set_sensitive(True) else: buttons.on('tick') buttons.draw() #utils.display_number(g.state,(10,10),g.font1) if g.state == 3: ln = len(self.let.ans) if ln == 2: s = _('Your word scores one point.') else: s = _('Your word scores %s points.' % (str(2 ** (ln - 2)))) utils.text_blit(g.screen, s, g.font2, g.message_cxy, self.colors[0], False) if g.state == 4: s = _('Sorry, %s is not in my word list' % self.let.ans) utils.text_blit(g.screen, s, g.font2, g.message_cxy, self.colors[0], False) if self.sugar: self.label.set_markup( '<span><big><b> %s (%s)</b></big></span>' % (str(g.score), str(g.best))) else: if g.score > 0: s = _('Total: %s' % (str(g.score))) utils.text_blit(g.screen, s, g.font1, g.score_cxy, self.colors[0], False) if g.best > 0: s = _('Best: %s' % (str(g.best))) utils.text_blit(g.screen, s, g.font1, g.best_cxy, self.colors[0], False) if g.help_on: utils.centre_blit(g.screen, g.help_img, g.help_cxy)
def buttons_setup(self): cx = g.sx(29.5) cy = g.sy(5) dy = g.sy(3) buttons.Button('cyan', (cx, cy)) cy += dy buttons.Button('green', (cx, cy)) cy += dy buttons.Button('red', (cx, cy)) cy += dy buttons.Button('reset', (cx, cy)) cy += dy buttons.Button('one', (cx, cy)) cy += dy if g.pattern == 1: buttons.off('one')
def display(self): g.screen.fill(self.colors[1]) if not self.sugar: g.screen.blit(g.bgd, (g.sx(0), 0)) self.let.draw() if self.sugar: self.back_button.set_sensitive(False) self.tick_button.set_sensitive(False) else: buttons.off(['back', 'tick']) if g.state in (g.STATE_PLAY, g.STATE_WRONG): if len(self.let.ans) > 0: if self.sugar: self.back_button.set_sensitive(True) else: buttons.on('back') if len(self.let.ans) > 1: if self.sugar: self.tick_button.set_sensitive(True) else: buttons.on('tick') buttons.draw() if g.state == g.STATE_RIGHT: ln = len(self.let.ans) if ln == 2: s = _('Your word scores one point.') else: s = _('Your word scores %s points.' % (str(2**(ln - 2)))) utils.text_blit(g.screen, s, g.font2, g.message_cxy, self.colors[0], False) if g.state == g.STATE_WRONG: s = _('Sorry, %s is not in my word list' % self.let.ans) utils.text_blit(g.screen, s, g.font2, g.message_cxy, self.colors[0], False) if self.sugar: self.label.set_markup('<span><big><b> %s (%s)</b></big></span>' % (str(g.score), str(g.best))) else: if g.score > 0: s = _('Total: %s' % (str(g.score))) utils.text_blit(g.screen, s, g.font1, g.score_cxy, self.colors[0], False) if g.best > 0: s = _('Best: %s' % (str(g.best))) utils.text_blit(g.screen, s, g.font1, g.best_cxy, self.colors[0], False) if g.help_on: utils.centre_blit(g.screen, g.help_img, g.help_cxy)
def buttons_setup(self): cy=g.sy(5.8); dx=g.sy(4.87); dy=g.sy(7.1); n=1 for r in range(3): cx=g.sx(3.82) for c in range(6): buttons.Button(str(n),(cx,cy),colour='yellow') buttons.off(str(n)) cx+=dx; n+=1 cy+=dy cx,cy=g.sx(29),g.h-g.sy(7.2); dy=g.sy(3.5) buttons.Button('menu',(cx,cy)) buttons.Button('help',(g.sy(3),cy)); cy+=dy buttons.Button('new',(cx,cy),colour='cyan') g.bw=(g.sy(3),cy) k=g.sy(3); g.star_c=[(k+g.offset,k),(g.w-k+g.offset,k)] self.menu()
def do_button(self, button): if button == 'equals': self.calc() buttons.off(['plus', 'times', 'equals']) if not self.complete(): g.state = 1 self.mouse_init() elif button == 'back': self.reset() elif button in ['new', 'green']: self.new1() else: g.buffr.append(button) buttons.off(['plus', 'times', 'equals']) g.state = 1 self.mouse_init()
def display(self): g.screen.fill((0, 0, 0)) g.level = self.levels[self.menu.green.n] if g.state == 'menu': self.menu.draw() n = self.slider_n() if n != None: self.slider[n].draw() else: self.tr[g.level].draw() buttons.off(['1', '2', '3', '4']) if not self.tr[g.level].complete(): buttons.on(['1', '2', '3', '4']) g.screen.blit(g.arrows, g.arrows_xy) elif self.tr[g.level].success: utils.centre_blit(g.screen, g.smiley, g.smiley_c) buttons.draw()
def buttons_setup(self): if self.sugar: self.tick_button.set_sensitive(False) self.back_button.set_sensitive(False) return dx = g.sy(4) cx = g.sx(16) - 1.5 * dx cy = g.sy(15) buttons.Button('new', (cx, cy)) cx += dx buttons.Button('tick', (cx, cy)) cx += dx buttons.off('tick') buttons.Button('back', (cx, cy)) cx += dx buttons.off('back') buttons.Button('help', (cx, cy))
def click(): if aim.running: return False if g.wrong: return False ind=which() if ind==-1: return False if len(aim.list1)==0: return False player.glow_start(ind) buttons.off("back") if ind==aim.list1[g.player_n]: g.player_n+=1 if g.player_n>g.score: g.score=g.player_n if g.player_n==len(aim.list1): # all correct - add another aim.inc(); g.player_n=0 else: g.wrong=True; g.wrong_ind=ind; g.right_ind=aim.list1[g.player_n] buttons.on("green") return True # click processed
def display(self): g.screen.fill(self.colors[1]) if not self.sugar: g.screen.fill((255, 255, 192)) g.screen.blit(g.magician, (g.sx(0), g.sy(18.0))) cx = g.sx(26) cy = g.sy(5.0) utils.centre_blit(g.screen, g.target, (cx, cy)) if g.aim > 0: self.display_n_glow(g.aim, (cx, cy)) x, y = g.xy1 pale = False if g.state == 2: pale = True for i in range(len(g.top)): x = self.display_n(g.top[i], (x, y), True, False, pale) x += g.sp1 x, y = g.xy3 for i in range(len(g.buffr)): m = g.buffr[i] if m == 'plus': g.screen.blit(g.plus, (x, y)) x += g.plus.get_width() elif m == 'times': g.screen.blit(g.times, (x, y)) x += g.times.get_width() elif m == 'equals': g.screen.blit(g.equals, (x, y)) x += g.equals.get_width() else: x = self.display_n(g.buffr[i], (x, y)) x += g.sp2 if len(g.top) == 0: buttons.off(['plus', 'times']) buttons.draw() if not self.sugar: self.slider.draw() if g.state == 4: utils.centre_blit(g.screen, g.smiley, (g.sx(16), g.sy(12))) if g.score > 0: self.display_score() if not self.sugar and g.best > 0: utils.text_blit(g.screen, str(g.best), g.font2, g.best_c, utils.ORANGE)
def do_key(self, key): if key == pygame.K_1: g.version_display = not g.version_display return if key in g.CROSS: self.do_click() return if key in g.CIRCLE: if g.help_on: if not self.sugar: g.help_on = False buttons.on('help') return else: if not self.sugar: g.help_on = True buttons.off('help') return if key in g.SQUARE: self.do_button('new') return if key in g.UP: if g.state in (2, 4): self.do_button('back') return if key in g.LEFT: self.let.left() return if key in g.RIGHT: self.let.right() return if key in g.TICK: if len(self.let.ans) > 1: self.do_tick() return #if key==pygame.K_4: self.let.given='clangers'; return### if g.state in (2, 4): letter = letter_keys.which(key) if letter is not None: self.let.key(letter) return if key == pygame.K_BACKSPACE: g.state = 2 self.let.back() return
def display(self): g.screen.fill(self.colors[1]) if not self.sugar: g.screen.fill((255, 255, 192)) g.screen.blit(g.magician, (g.sx(0), g.sy(18.0))) cx = g.sx(26) cy = g.sy(5.0) utils.centre_blit(g.screen, g.target, (cx, cy)) if g.aim > 0: self.display_n_glow(g.aim, (cx, cy)) x, y = g.xy1 pale = False if g.state == 2: pale = True for i in range(len(g.top)): x = self.display_n(g.top[i], (x, y), True, False, pale) x += g.sp1 x, y = g.xy3 for i in range(len(g.buffr)): m = g.buffr[i] if m == 'plus': g.screen.blit(g.plus, (x, y)) x += g.plus.get_width() elif m == 'times': g.screen.blit(g.times, (x, y)) x += g.times.get_width() elif m == 'equals': g.screen.blit(g.equals, (x, y)) x += g.equals.get_width() else: x = self.display_n(g.buffr[i], (x, y)) x += g.sp2 if len(g.top) == 0: buttons.off(['plus', 'times']) buttons.draw() if not self.sugar: self.slider.draw() if g.state == 4: utils.centre_blit(g.screen, g.smiley, (g.sx(16), g.sy(12))) if g.score > 0: self.display_score() if not self.sugar and g.best > 0: utils.text_blit( g.screen, str(g.best), g.font2, g.best_c, utils.ORANGE)
def do_key(self, key): if key == pygame.K_1: g.version_display = not g.version_display return if key in g.CROSS: self.do_click() return if key in g.CIRCLE: if g.help_on: if not self.sugar: g.help_on = False buttons.on('help') return else: if not self.sugar: g.help_on = True buttons.off('help') return if key in g.SQUARE: self.do_button('new') return if key in g.UP: if g.state in (g.STATE_PLAY, g.STATE_WRONG): self.do_button('back') return if key in g.LEFT: self.let.left() return if key in g.RIGHT: self.let.right() return if key in g.TICK: if len(self.let.ans) > 1: self.do_tick() return if g.state in (g.STATE_PLAY, g.STATE_WRONG): letter = letter_keys.which(key) if letter is not None: self.let.key(letter) return if key == pygame.K_BACKSPACE: g.state = g.STATE_PLAY self.let.back() return
def do_button(self, bu): if bu == 'new': if not self.let.check(): if g.score > 0: g.score -= 1 self.let.setup() g.state = 1 return if bu == 'back': self.let.reset() g.state = 2 return if bu == 'tick': self.do_tick() return if bu == 'help': g.help_on = True if not self.sugar: buttons.off('help')
def do_button(self, bu): if bu == 'cyan': g.pattern += 1 if g.pattern == 123: g.pattern = 1 g.help1 = 0 g.help2 = 0 self.get_goal() self.tu.win = False g.finale = False g.show_help = False self.tu.changed = True self.tu.clear() if self.sugar: self.cyan_button.set_sensitive(False) else: buttons.off('cyan') self.mouse_1st_no() # to 1st number elif bu == 'black': self.tu.current = utils.copy_list(g.numbers) self.tu.setup(self.colors[0]) g.show_help = False elif bu == 'green': self.tu.between_levels = False g.show_help = False if self.tu.changed: self.tu.current = utils.copy_list(g.numbers) self.tu.setup(self.colors[0]) self.tu.changed = False self.tu.running = True elif self.tu.win or self.tu.crashed: self.tu.setup(self.colors[0]) self.tu.running = True else: if self.tu.step_count == 0: self.tu.ms = pygame.time.get_ticks() self.tu.running = True elif bu == 'red': self.tu.running = False
def run(self, restore=False): g.init() if not self.journal: utils.load() self.let = let.Let() # setup before retrieve load_save.retrieve() self.buttons_setup() if self.canvas is not None: self.canvas.grab_focus() pygame.key.set_repeat(600, 120) going = True while going: if self.journal: # Pump GTK messages. while Gtk.events_pending(): Gtk.main_iteration() if not going: break # Pump PyGame messages. for event in pygame.event.get(): if event.type == pygame.QUIT: if not self.journal: utils.save() return elif event.type == pygame.VIDEORESIZE: pygame.display.set_mode(event.size, pygame.RESIZABLE) g.redraw = True elif event.type == pygame.MOUSEMOTION: g.pos = event.pos g.redraw = True if self.canvas is not None: self.canvas.grab_focus() elif event.type == pygame.MOUSEBUTTONDOWN: g.redraw = True if event.button == 1: if not self.sugar and g.help_on: g.help_on = False buttons.on('help') elif self.do_click(): pass else: bu = buttons.check() if bu != '': self.do_button(bu) if not self.sugar and event.button == 3: g.help_on = True buttons.off('help') elif event.type == pygame.KEYDOWN: if not self.sugar and event.key not in g.CIRCLE: g.help_on = False buttons.on('help') self.do_key(event.key) g.redraw = True elif event.type == pygame.KEYUP: pass if not going: break if g.state == g.STATE_SETUP: self.let.choose() if g.redraw: self.display() if g.version_display: utils.version_display() if g.state != g.STATE_SETUP: g.screen.blit(g.pointer, g.pos) pygame.display.flip() g.redraw = False g.clock.tick(40)
def run(self, restore=False): self.g_init() if not self.journal: utils.load() load_save.retrieve() if restore: self.restore_pattern() else: g.delay = (3 - g.level) * 400 self.tu = my_turtle.TurtleClass() self.tu.current = [1, 1, 1, 3, 2] self.get_goal() if g.pattern == 1: self.tu.current = utils.copy_list(g.goal) self.tu.setup(self.colors[0]) g.numbers = utils.copy_list(self.tu.current) #buttons x = g.sx(7.3) y = g.sy(16.5) dx = g.sy(2.6) if not self.sugar: buttons.Button("cyan", (x, y), True) x += dx buttons.off('cyan') buttons.Button("green", (x, y), True) x += dx buttons.Button("red", (x, y), True) x += dx buttons.Button("black", (x, y), True) x += dx self.slider = slider.Slider(g.sx(23.5), g.sy(21), 3, utils.YELLOW) self.mouse_1st_no() # to 1st number if self.canvas is not None: self.canvas.grab_focus() ctrl = False pygame.key.set_repeat(600, 120) key_ms = pygame.time.get_ticks() going = True while going: if self.journal: # Pump GTK messages. while gtk.events_pending(): gtk.main_iteration() # Pump PyGame messages. for event in pygame.event.get(): if event.type == pygame.QUIT: if not self.journal: utils.save() going = False elif event.type == pygame.MOUSEMOTION: g.pos = event.pos g.redraw = True if self.canvas is not None: self.canvas.grab_focus() elif event.type == pygame.MOUSEBUTTONDOWN: g.redraw = True if g.big: g.big = False else: bu = buttons.check() if bu != '': self.do_button(bu) self.flush_queue() elif not self.sugar: if utils.mouse_on_img1(g.magician, g.magician_c): self.help2() elif utils.mouse_in(g.x1, g.y0, g.x1 + g.bw, g.y0 + g.bw): self.big_pic() elif self.slider.mouse(): g.delay = (3 - g.level) * 400 else: g.show_help = False self.check_nos(event.button) else: g.show_help = False self.check_nos(event.button) elif event.type == pygame.KEYDOWN: # throttle keyboard repeat if pygame.time.get_ticks() - key_ms > 110: key_ms = pygame.time.get_ticks() if ctrl: if event.key == pygame.K_q: if not self.journal: utils.save() going = False break else: ctrl = False if event.key in (pygame.K_LCTRL, pygame.K_RCTRL): ctrl = True break self.do_key(event.key) g.redraw = True self.flush_queue() elif event.type == pygame.KEYUP: ctrl = False if not going: break if self.tu.running: self.tu.move() if not g.crash_drawn: g.crash_drawn = True g.redraw = True if g.redraw: self.display() if g.version_display: utils.version_display() g.screen.blit(g.pointer, g.pos) pygame.display.flip() g.redraw = False g.clock.tick(40)
def run(self, restore=False): g.init() if not self.journal: utils.load() self.let = let.Let() # setup before retrieve load_save.retrieve() self.buttons_setup() if self.canvas is not None: self.canvas.grab_focus() ctrl = False pygame.key.set_repeat(600, 120) key_ms = pygame.time.get_ticks() going = True while going: if self.journal: # Pump GTK messages. while Gtk.events_pending(): Gtk.main_iteration() # Pump PyGame messages. for event in pygame.event.get(): if event.type == pygame.QUIT: if not self.journal: utils.save() going = False elif event.type == pygame.MOUSEMOTION: g.pos = event.pos g.redraw = True if self.canvas is not None: self.canvas.grab_focus() elif event.type == pygame.MOUSEBUTTONDOWN: g.redraw = True if event.button == 1: if not self.sugar and g.help_on: g.help_on = False buttons.on('help') elif self.do_click(): pass else: bu = buttons.check() if bu != '': self.do_button(bu) self.flush_queue() if not self.sugar and event.button == 3: g.help_on = True buttons.off('help') elif event.type == pygame.KEYDOWN: if not self.sugar and event.key not in g.CIRCLE: g.help_on = False buttons.on('help') # throttle keyboard repeat if pygame.time.get_ticks() - key_ms > 110: key_ms = pygame.time.get_ticks() if ctrl: if event.key == pygame.K_q: if not self.journal: utils.save() going = False break else: ctrl = False if event.key in (pygame.K_LCTRL, pygame.K_RCTRL): ctrl = True break self.do_key(event.key) g.redraw = True self.flush_queue() elif event.type == pygame.KEYUP: ctrl = False if not going: break if g.state == 1: self.let.choose() if g.redraw: self.display() if g.version_display: utils.version_display() if g.state != 1: g.screen.blit(g.pointer, g.pos) pygame.display.flip() g.redraw = False g.clock.tick(40)
def run(self, restore=False): self.g_init() if not self.journal: utils.load() load_save.retrieve() self.aim = simon.Simon(1200) # arg is glow time if self.sugar: self.set_delay(800) else: self.set_delay() self.player = simon.Simon(200) if restore: self.restore_pattern() self.aim.started = True if self.sugar: self.green_button.set_sensitive(True) self.back_button.set_sensitive(False) else: bx = g.sx(22.42) by = g.sy(20.8) buttons.Button('green', (bx, by), True) buttons.Button('back', (bx, by), True) buttons.off('back') self.slider = slider.Slider(g.sx(9), g.sy(20.8), 3, utils.BLUE) self.rc = rc_skip_last.RC(3, 5) if self.canvas is not None: self.canvas.grab_focus() ctrl = False pygame.key.set_repeat(600, 120) key_ms = pygame.time.get_ticks() going = True while going: if self.journal: # Pump GTK messages. while gtk.events_pending(): gtk.main_iteration() # Pump PyGame messages. for event in pygame.event.get(): if event.type == pygame.QUIT: if not self.journal: utils.save() going = False elif event.type == pygame.MOUSEMOTION: g.pos = event.pos g.redraw = True if self.canvas is not None: self.canvas.grab_focus() self.mouse_set() elif event.type == pygame.MOUSEBUTTONDOWN: g.redraw = True if event.button == 1: self.do_click() self.flush_queue() elif event.type == pygame.KEYDOWN: # throttle keyboard repeat if pygame.time.get_ticks() - key_ms > 110: key_ms = pygame.time.get_ticks() if ctrl: if event.key == pygame.K_q: if not self.journal: utils.save() going = False break else: ctrl = False if event.key in (pygame.K_LCTRL, pygame.K_RCTRL): ctrl = True break self.do_key(event.key) g.redraw = True self.flush_queue() elif event.type == pygame.KEYUP: ctrl = False if not going: break if self.sugar: if g.player_n == 0 and not self.green_button.get_sensitive(): self.back_button.set_sensitive(True) else: if g.player_n == 0 and not buttons.active('green'): buttons.on('back') self.player.do() self.aim.do() if g.redraw: self.display() if g.version_display: utils.version_display() if self.aim.running or self.aim.glow_active: pass else: g.screen.blit(g.pointer, g.pos) pygame.display.flip() g.redraw = False g.clock.tick(40)