def __init__(self): img = utils.load_image('abcd.png', True) wf = 0.0 + img.get_width() / 26.0 self.h = img.get_height() x = 0.0 y = 0 self.w = int(wf) self.imgs = [] for i in range(26): self.imgs.append(img.subsurface((int(x + .5), y, self.w, self.h))) x += wf self.x0 = g.sx(16) - 4 * self.w self.y0 = g.sy(2) self.y1 = self.y0 + 1.5 * self.h g.message_cxy = (g.sx(16), self.y0 + 1.25 * self.h) self.setup() self.ind = None
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 __init__(self, sugar, label, colors): self.sugar = sugar self.label = label self.colors = colors self.pics = [] for ind in range(10): pic = utils.load_image(str(ind) + '.png', True) self.pics.append(pic) self.back = utils.load_image('back.png', True) self.front = utils.load_image('front.png', True) self.grey = utils.load_image('grey.png', True) self.star = utils.load_image('star.png', True) self.w = self.back.get_width() self.h = self.back.get_height() self.nr = g.nr self.nc = g.nc gutter = (g.sy(32) - self.nc * self.w) / (self.nc + 1.0) / 1.5 self.locns = [] ind = 0 card = 0 y = gutter pic = True x0 = (g.w - self.nc * (self.w + gutter)) / 2 for r in range(self.nr): x = x0 for c in range(self.nc): locn = Locn(x, y, r, c, ind, card, pic) self.locns.append(locn) x += (self.w + gutter) ind += 1 card += 1 if card == 10: card = 0 pic = False y += (self.h + gutter) self.xn = x0 / 2 self.yn = y self.green = None self.tries_cxy = (g.sx(3), g.sy(20.8)) self.best_xcy = (g.sx(26.5), g.sy(20.8)) self.star_xy = (self.best_xcy[0] - self.star.get_width() - 5, g.sy(20.1)) self.gutter = gutter
def ladder(self): if g.score > g.best: g.best = g.score if g.best > 11: cx = g.sx(30.55) cy = g.sy(13.25) utils.centre_blit(g.screen, g.star, (cx, cy)) utils.display_number(g.best, (cx, cy), g.font2) if g.score > 0: n = g.score - 1 if n > 11: n = 11 g.screen.blit(g.ladder, (g.sx(26.95), g.sy(13.7))) x = g.man_x0 + n * g.man_dx y = g.man_y0 + n * g.man_dy g.screen.blit(g.man, (x, y)) cx = x + g.man_sc_dx cy = y + g.man_sc_dy if g.score < g.best or g.best < 12: utils.centre_blit(g.screen, g.star, (cx, cy)) utils.display_number(g.score, (cx, cy), g.font2)
def which_pile(self): y = squares[0].y dx = g.sy(.8) dy = g.d + g.space for r in range(1, 10): # 1..9 x = g.sx(.2) for i in range(1, piles[r] + 1): if i == piles[r]: if utils.mouse_in(x, y, x + g.d, y + g.d): return r x += dx y += dy return 0
def display(): g.screen.fill((0,255,0)) for img in g.imgs: # img from ImgClickClass (centred) img.draw(g.screen) if g.wrong: img=g.imgs[g.wrong_ind] utils.centre_blit(g.screen,g.wrong_img,(img.cx,img.cy)) img=g.imgs[g.right_ind] utils.centre_blit(g.screen,g.glow[g.right_ind],(img.cx,img.cy)) buttons.draw() ladder() g.screen.blit(g.magician,(g.sx(3.2),g.sy(18.2)))
def display(self, wait=False): if g.state == 1: self.menu_display() utils.display_number(g.success, (g.sx(.2), g.sy(.15)), g.font2) else: if self.pj.complete(): g.screen.blit(g.bgd, (g.sx(0), 0)) utils.display_number(g.success, (g.sx(.5), g.sy(.5)), g.font1) else: # g.screen.fill((g.red,g.green,g.blue)) g.screen.fill(utils.CYAN) self.pj.draw() buttons.draw() if self.bu2.active: if self.pj.all_rotated(): self.bu2.off() else: utils.centre_blit(g.screen, g.smiley1, (g.smiley1_x, g.smiley_y)) utils.centre_blit(g.screen, g.smiley2, (g.smiley2_x, g.smiley_y))
def setup(self, pj_n): self.pj_n = pj_n random.shuffle(self.pieces) self.carry = None self.next_group = 0 fname = os.path.join('data', str(pj_n), 'pieces.txt') try: f = open(fname, 'r') except: print 'Peter says unable to load ' + fname return False for i in range(4): ignore = int(f.readline()) n = 0 factor = 32.0 / 1200.0 for ind in range(self.total): n += 1 pce = self.pce_from_index(ind) pce.cx0 = g.sx(factor * int(f.readline())) pce.cy0 = g.sy(factor * int(f.readline())) img = utils.load_image(str(n) + '.png', True, str(pj_n)) if img == None: return False if img == None: print 'Peter says unable to load data/' + str( pj_n) + '/' + str(n) + '.png' return False pce.img = img pce.rotated = None pce.group = 0 pce.angle = random.randint(0, 3) if pce.angle > 0: pce.rotated = pygame.transform.rotate(pce.img, -pce.angle * 90) try: g.red = int(f.readline()) g.green = int(f.readline()) g.blue = int(f.readline()) except: pass f.close self.layout() self.final = None self.ms = -1 self.unrotating = False self.unrotate_time = 500 if g.success > 2: self.unrotate_time = 50 if g.success < 3: self.demo = random.randint(11, 14) pce = self.pieces[self.demo] pygame.mouse.set_pos([pce.cx, pce.cy]) self.right_displaying = True self.rms = pygame.time.get_ticks( ) + 500 # need time for mouse to settle return True
def display(self): grey = 100 g.screen.fill((grey, grey, grey)) buttons.draw() g.screen.blit(g.help1, g.help1_xy) utils.display_number(g.count, (g.xc, g.yc), g.font2, utils.CREAM) colour = utils.YELLOW if g.helped > 5: colour = utils.RED utils.display_number(g.helped, (g.xc, g.yc + g.sy(6)), g.font1, colour) if g.finished: utils.centre_blit(g.screen, g.smiley, (g.sx(4), g.smiley_y)) self.board.draw()
def display_score(): if pygame.font: text = g.font2.render(str(g.score), True, ORANGE, BLUE) w = text.get_width() h = text.get_height() x = g.sx(5.7) y = g.sy(18.8) d = g.sy(.3) pygame.draw.rect(g.screen, BLUE, (x - d - g.sy(.05), y - d, w + 2 * d, h + 2 * d)) g.screen.blit(text, (x, y)) centre_blit(g.screen, g.sparkle, (x - d + g.sy(.05), y + h / 2 - g.sy(.2)))
def buttons_setup(self): cx = g.sx(3.7) cy = g.sy(16.4) dx = g.sy(3.6) dy = g.sy(3.3) buttons.Button('cls', (cx, cy)) cx += dx buttons.Button('run', (cx, cy)) cx -= dx cy += dy buttons.Button('grid', (cx, cy)) cx += dx buttons.Button('hide', (cx, cy))
def buttons_setup(self): cx1 = g.sx(1.5) cy1 = g.sy(1.5) cx2 = g.sx(32) - g.sy(1.5) cy2 = g.sy(19.8) buttons.Button('clear', (cx1, cy1), caption='clear', colour='yellow') buttons.Button('try', (cx2, cy2), caption='try', colour='yellow') buttons.Button('minus', (cx1, cy2), caption='dash', colour='yellow') buttons.Button('space', (cx1 + g.sy(3), cy2), caption='space', colour='yellow') buttons.Button('replay', (cx2, cy1), caption='replay', colour='yellow') dx = g.sy(2.4) bx = g.sx(16) - dx by = g.sy(20.2) buttons.Button('bk', (bx, by), True) bx += dx buttons.Button('blue', (bx, by), True) bx += dx buttons.Button('fd', (bx, by), True) buttons.Button('back', (g.sx(2), g.sy(18)), True) buttons.off(('fd', 'blue', 'bk', 'back'))
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 __init__(self): pic=utils.load_image('jig.jpg') nc=4; nr=3; w=pic.get_width()/nc; h=pic.get_height()/nr x0=g.sx(.5); y0=g.sy(2.2); npieces=nr*nc y=y0 for r in range(nr): x=x0 for c in range(nc): piece=Piece(pic.subsurface(x-x0,y-y0,w,h),x,y) pieces.append(piece) x+=w y+=h self.carry=None; self.empty=None; self.w=w; self.h=h self.shuffle()
def __init__(self): # oval letters self.azs = [] s = g.sy(1.1) dx = g.xy0[0] dy = g.sy(.5) for ind in range(26): l = chr(ind + 97) x, y = letters_c[ind] y2 = int(g.imgf * y + g.sy(.1) + .5) y1 = y2 - s - s x = int(g.imgf * x + dx + .5) az = AZ(l, x - s, y1, x + s, y2) self.azs.append(az) # user input self.answer = '' self.cxy = (g.sx(16), g.sy(16)) self.message = None self.message_c = (g.sx(16), g.sy(11)) fname = os.path.join('data', 'countries.txt') f = open(fname, 'r') self.countries = [] letters = '' for line in f.readlines(): ch = line[:1] if ch not in letters: letters += ch self.countries.append(line.rstrip().split(',')) self.no = [] for i in range(ord('A'), ord('Z') + 1): ch = chr(i) if ch not in letters: self.no.append(ch) f.close() self.setup() self.finished = False g.countries = self.countries
def display(self): # called each loop if g.big: g.screen.fill(self.colors[1]) utils.centre_blit(g.screen, g.big_surface, (g.sx(16), g.sy(11.5))) else: if self.sugar: g.screen.fill(self.colors[1]) else: g.screen.blit(g.bgd, (g.sx(0), 0)) g.screen.blit(g.box, (g.x0, g.y0)) g.screen.blit(g.box, (g.x1, g.y1)) if not self.sugar: utils.centre_blit(g.screen, g.magician, g.magician_c) self.draw_goal() utils.centre_blit(g.screen, g.turtle, (g.x0 + 4 * g.dd, g.y0 + 6 * g.dd)) self.tu.draw() if self.tu.win: utils.centre_blit(g.screen, g.smiley, (g.sx(16.6), g.sy(2.2))) if self.sugar: self.cyan_button.set_sensitive(True) else: buttons.on('cyan') if not self.journal: utils.save() self.draw_nos() if not self.sugar: buttons.draw() self.slider.draw() if g.score > 0: if self.sugar: self.label.set_markup( '<span><big><b> %s</b></big></span>' % (str(g.score))) else: utils.display_score() utils.display_number1(g.pattern, (g.sx(2.4), g.sy(2)), g.font1, utils.BLUE)
def setup(self): group = g.level # 1,2,3 or 4 self.nballs = group * 3 # 3,6,9,12 x_free = g.sx(3) y_free = g.sy(2.7) dy_free = g.sy(3.2) self.free_rect=pygame.Rect(x_free-self.d2,y_free-self.d2,\ 2*self.d2,3*dy_free+self.d2) i = 0 self.z = [] self.pan_n[0] = 0 self.pan_n[1] = 0 for ball in self.balls: ball.active = False ball.colour = 'blue' if i < self.nballs: if i < group: x, y = self.pan_posns[0][i] ball.pan = 0 self.pan_n[0] += 1 ball.posn = i elif i < group * 2: x, y = self.pan_posns[1][i - group] ball.pan = 1 self.pan_n[1] += 1 ball.posn = i - group else: x = x_free y = y_free y_free += dy_free ball.pan = None ball.c0 = (x, y) ball.c = (x, y) ball.active = True self.z.append(ball) i += 1 self.carry = None ind = random.randint(0, self.nballs - 1) self.rogue = self.balls[ind] self.heavy = random.randint(0, 1) self.count = 0 self.show_rogue = False self.ms = pygame.time.get_ticks() self.flutter_k = None self.flutter_ind = None self.state_save = None self.state = 2 # level self.result = None self.red_set = False # ensure exactly one red/gold per round
def bu_setup(self): self.bu = {'N': None, 'S': None, 'E': None, 'W': None, 'X': None} x0 = g.sx(23.2) y0 = g.sy(15.8) dx = g.sy(2.2) dy = dx for v in 'NSEWX': if v == 'N': x = x0 y = y0 - dy if v == 'S': x = x0 y = y0 + dy if v == 'E': x = x0 + dx y = y0 if v == 'W': x = x0 - dx y = y0 if v == 'X': x = x0 y = y0 self.bu[v] = buttons.Button(v, (x, y), True) buttons.Button('new', (g.sx(30), g.sy(20)), True)
def draw(self): g.screen.blit(self.bgd, (g.sx(0), 0)) cxy = (g.sx(30.5), g.sy(20)) utils.display_number(g.count, cxy, g.font2, utils.CREAM) for lf in lookFor: if not lf.found: utils.centre_blit(g.screen, lf.img, (lf.cx, lf.cy)) if not self.complete and not g.setup_on: img = lookFor[self.find_ind[self.current_ind]].img cxy = (self.frame_cx, self.frame_cy) utils.centre_blit(g.screen, self.frame, cxy) utils.centre_blit(g.screen, img, cxy) x, y = cxy x -= self.frame.get_width() / 2 x += g.sy(.24) y += self.frame.get_height() / 2 y -= g.sy(.76) n = self.found s = str(n) + ' / ' + str(self.find_n) utils.text_blit1(g.screen, s, g.font1, (x, y), utils.BLACK, False) if self.complete: cxy = (self.frame_cx, self.frame_cy) utils.centre_blit(g.screen, self.frame, cxy) utils.centre_blit(g.screen, self.smiley, cxy)
def check_numbers(self): if not buttons.active('plus') and not self.correct(): (mx,my)=pygame.mouse.get_pos() x1=g.sx(3);y1=g.sy(3.5);h=g.n[0].get_height() for i in range(len(g.top)): x=self.display_n(g.top[i],(x1,y1),False) w=x-x1 rect=pygame.Rect(x1,y1,w,h) if rect.collidepoint(mx,my): g.buffr.append(g.top[i]); del g.top[i] buttons.on(['back','plus','times']) if len(g.buffr)>1: buttons.on('equals') return True#**** x1=x+g.sp1 return False
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): if g.state == 1: # normal g.screen.fill(g.bgd_colour) self.castle.current_room.display() self.castle.health_display() utils.centre_blit(g.screen, g.bag_current_img, g.bag_cxy) if g.wishes > 0: utils.centre_blit(g.screen, g.wish_current_img, g.wish_cxy) x = g.wish_x y = g.wish_y utils.display_number(g.wishes, (x + g.sy(2.2), y + g.sy(.9)), g.font1) buttons.draw() if g.best > 0: x = g.sx(16) y = g.sy(20) utils.text_blit1(g.screen, str(g.best), g.font1, (x, y), (255, 128, 255)) x -= g.sy(1.5) y -= g.sy(.3) g.screen.blit(g.star, (x, y)) elif g.state == 2: # inside bag grey = 180 g.screen.fill((grey, grey, grey)) utils.centre_blit(g.screen, g.bag_base, (g.sx(16), g.sy(11.2))) ind = 0 for obj in g.bag: if obj <> None: utils.centre_blit(g.screen, obj.img0, g.inside_bag_cxy[ind]) ind += 1 g.screen.blit(g.inside_bag, (g.sx(0), g.sy(0))) elif g.state == 3: # wishes self.castle.wish_display() elif g.state == 4: # map self.castle.map_display()
def setup(): puzzle = puzzles[g.puzzle_n] x1 = g.sx(.2) x2 = g.sx(8.2) y1 = g.sy(1) y2 = g.sy(16) for ind in range(10): pce = pieces[ind] pce.img = utils.load_image(puzzle[ind] + '.png', True, 'pieces') w = pce.img.get_width() h = pce.img.get_height() x = random.randint(x1, x2 - w) y = random.randint(y1, y2 - h) pce.on_grid = False if ind == 0: x, y = g.x0, g.y0 pce.on_grid = True pce.xy = x, y if ind == 4: x1 = g.sx(23.5) x2 = g.sx(31.5) g.carry = None g.finished = False g.redrawn = False
def draw(self): g.screen.fill(utils.BLACK) g.screen.blit(self.img, (g.sx(0), 0)) if self.xy != None: utils.centre_blit(g.screen, self.circle, self.xy) s = self.country utils.text_blit(g.screen, s, g.font2, self.textxy, utils.CREAM, False) x, y = self.textxy if self.capital != '': s = 'Capital: ' + self.capital utils.text_blit(g.screen, s, g.font1, (x, y + g.sy(1.1)), utils.CREAM, False) if self.latlon != None: s = self.latlon utils.text_blit(g.screen, s, g.font1, (x, y + g.sy(2)), utils.CREAM, False)
def __init__(self): # grid letters img = utils.load_image('abcd.png', True) img_score = utils.load_image('abcd_score.png', True) wf = 0.0 + img.get_width() / 26.0 self.h = img.get_height() x = 0.0 y = 0 self.w = int(wf) self.imgs = [] self.imgs_score = [] for i in range(26): self.imgs.append(img.subsurface((int(x + .5), y, self.w, self.h))) self.imgs_score.append( img_score.subsurface((int(x + .5), y, self.w, self.h))) x += wf # oval letters self.azs = [] s = g.sy(1.1) dx = g.x0 dy = g.sy(.5) for ind in range(26): l = chr(ind + 97) x, y = letters_c[ind] y2 = int(g.imgf * y + g.sy(.1) + .5) y1 = y2 - s - s if l in 'bdfhkl': y1 -= dy if l in 'gjpqy': y2 += dy x = int(g.imgf * x + dx + .5) az = AZ(l, x - s, y1, x + s, y2) self.azs.append(az) # grid cells self.cells = [] s = g.sy(14.4) / 9 x0 = g.sx(16) - s * 4.5 y0 = g.sy(11.15) - s * 4.5 y = y0 ind = 0 for r in range(9): x = x0 for c in range(9): cell = Cell(int(x + .5), int(y + .5), r, c, ind) self.cells.append(cell) x += s ind += 1 y += s self.side = int(s + .5) self.setup()
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 display_score(self): if self.sugar: self.label.set_markup('<span><big><b> %s (%s)</b></big></span>' % (str(int(g.score)), str(int(g.best)))) else: text = g.font2.render(str(g.score), True, utils.ORANGE, utils.BLUE) w = text.get_width() h = text.get_height() x = g.sx(5.15) y = g.sy(19.6) d = g.sy(.3) pygame.draw.rect(g.screen, utils.BLUE, (x - d, y - d, w + 2 * d, h + 2 * d - g.sy(.2))) g.screen.blit(text, (x, y)) utils.centre_blit(g.screen, g.sparkle, (x - d + g.sy(.05), y - d + g.sy(1.1)))
def __init__(self): self.imgs = [] self.deck = [] for i in range(52): img = utils.load_image(str(i + 1) + '.png', True, 'cards') self.imgs.append(img) self.deck.append(i + 1) self.back = utils.load_image('back.png', True, 'cards') self.width = self.back.get_width() self.w2 = int(self.width / 2) self.height = self.back.get_height() self.h2 = int(self.height / 2) self.ok = 1 self.rule = 0 self._centres() self.back_c = (int(g.sx(16)), int(g.sy(10)))
def draw_legend(self): g.screen.blit(self.legend, self.legend_xy) x, y = self.legend_xy x += g.sy(2) y += g.sy(.05) utils.text_blit1(g.screen,'3 6 9 12',\ g.font2,(x,y),utils.BLUE,False) y += g.sy(1.25) utils.text_blit1(g.screen,'2 3 3 3',\ g.font2,(x,y),utils.BLACK,False) x = g.sx(14.2) y += g.sy(1.75) dx = g.sy(1.77) for n in g.scores: utils.display_number(n, (x, y), g.font2, utils.ORANGE) x += dx
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 display_score(self): if self.sugar: self.label.set_markup( '<span><big><b> %s (%s)</b></big></span>' % ( str(int(g.score)), str(int(g.best)))) else: text = g.font2.render(str(g.score), True, utils.ORANGE, utils.BLUE) w = text.get_width() h = text.get_height() x = g.sx(5.15) y = g.sy(19.6) d = g.sy(.3) pygame.draw.rect(g.screen, utils.BLUE, (x - d, y - d, w + 2 * d, h + 2 * d - g.sy(.2))) g.screen.blit(text, (x, y)) utils.centre_blit(g.screen, g.sparkle, (x - d + g.sy(.05), y - d + g.sy(1.1)))
def layout(self): ind = 0 y = g.sy(1.5) x0 = g.sx(2) dx = g.sy(4) dy = g.sy(2.7) for r in range(8): x = x0 for c in range(8): if r > 1 and r < 6 and c > 0 and c < 7: pass else: pce = self.pieces[ind] pce.cx = x pce.cy = y ind += 1 x += dx y += dy
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 __init__(self, n): # eg n=5->5x5 self.n = n self.cells = [] self.d = g.gold.get_width() s = self.d * n margin = g.sy(9.6) - s / 2 x0 = g.sx(32) - margin - s y0 = margin y = y0 for r in range(n): x = x0 for c in range(n): cell = Cell(r, c, x, y) self.cells.append(cell) x += self.d y += self.d self.x0 = x0 self.green_w = g.sy(.1) self.d2 = self.d / 2
def __init__(self,n): # 1,2,3 (level) self.nr,self.nc=rc[n-1] w=g.pic.get_width(); h=g.pic.get_height() dx=w/self.nc; dy=h/self.nr; self.dd=min(dx,dy) offset_x=(g.sy(32)-self.nc*self.dd)/2; offset_y=offset_x self.target_c=(g.sx(16),offset_y+h/2) self.pieces=[] y=0 for r in range(self.nr): x=0 for c in range(self.nc): img0=g.pic.subsurface(x,y,self.dd,self.dd) pce=piece(img0,r,c,x+g.offset+offset_x,y+offset_y) self.pieces.append(pce) x+=self.dd y+=self.dd d=g.sy(.25); x=g.offset+offset_x; y=offset_y w=self.nc*self.dd; h=self.nr*self.dd self.xywhd=x,y,w,h,d
def display(self): # called each loop if g.big: g.screen.fill(self.colors[1]) utils.centre_blit(g.screen, g.big_surface, (g.sx(16), g.sy(11.5))) else: if self.sugar: g.screen.fill(self.colors[1]) else: g.screen.blit(g.bgd, (g.sx(0), 0)) g.screen.blit(g.box, (g.x0, g.y0)) g.screen.blit(g.box, (g.x1, g.y1)) if not self.sugar: utils.centre_blit(g.screen, g.magician, g.magician_c) self.draw_goal() utils.centre_blit(g.screen, g.turtle, (g.x0 + 4 * g.dd, g.y0 + 6 * g.dd)) self.tu.draw() if self.tu.win: if self.sugar: if self.good_job is None: path = self.parent.good_job_image_path() self.good_job = utils.load_image(path, True) if g.w > g.h: utils.centre_blit( g.screen, self.good_job, (g.sx(7), g.sy(17))) else: utils.centre_blit(g.screen, self.good_job, (g.sx(7), g.sy(38))) else: utils.centre_blit(g.screen, g.smiley, (g.sx(16.6), g.sy(2.2))) if self.sugar: self.cyan_button.set_sensitive(True) else: buttons.on('cyan') if not self.journal: utils.save() self.draw_nos() if not self.sugar: buttons.draw() self.slider.draw() if g.score > 0: if self.sugar: self.parent.update_score(int(g.score)) else: utils.display_score() utils.display_number1(g.pattern, (g.sx(2.4), g.sy(2)), g.font1, utils.WHITE)
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)
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 buttons_setup(self): if not self.sugar: buttons.Button('new', (g.sx(16), g.sy(20.8)))
def run(self, restore=False): self.black = False g.init() if not self.journal: utils.load() load_save.retrieve() x = g.sx(26) y = g.sy(11.2) if not self.sugar: buttons.Button("new", (x, y)) x, y = g.cxy2 dx = g.sy(4) self.back_button = buttons.Button("back", (x, y)) x += dx buttons.Button("plus", (x, y)) x += dx buttons.Button("times", (x, y)) x += dx buttons.Button("equals", (x, y)) self.ops = ['back', 'plus', 'times', 'equals'] if not self.sugar: self.slider = slider.Slider(g.sx(22.4), g.sy(20.5), 10, utils.GREEN) self.mouse_auto = True self.anim_ms = None self.level1() # initial animation self.scored = False if restore: g.score = self.save_score ctrl = False pygame.key.set_repeat(600, 120) key_ms = pygame.time.get_ticks() going = True if self.canvas is not None: self.canvas.grab_focus() 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 self.anim_end() if event.button == 1: bu = buttons.check() if bu == '': if not self.check_numbers(): if not self.sugar: if self.slider.mouse(): self.level1() else: self.do_button(bu) # eg do_button('plus') self.flush_queue() elif event.type == pygame.KEYDOWN: self.anim_end() # 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 self.animation() if g.redraw: self.display() if g.version_display: utils.version_display() if not self.black: g.screen.blit(g.pointer, g.pos) pygame.display.flip() g.redraw = False g.clock.tick(40)