def score(self): self.flag = False a = name[name.index('\\') + 1:] con = sqlite3.connect('data\\records.db') cur = con.cursor() result = cur.execute( '''SELECT * from records where map="{}"'''.format(a)).fetchall() result = list( map(lambda x: x[1] + ' = ' + str(x[0]), sorted(result, key=lambda x: x[0])))[:10] self.render(result[::-1]) font = pygame.font.Font(None, 30) screen.blit(font.render('назад', 1, (255, 255, 255)), (10, 30)) pygame.display.flip() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: terminate() elif event.type == pygame.MOUSEBUTTONDOWN: p = event.pos if 10 <= p[0] <= font.size('назад')[0] + 10 and 30 <= p[ 1] <= font.size('назад')[1] + 30: self.flag = True screen.fill((0, 0, 0)), screen.blit(FON, (0, 0)) return
def menu(): """функция осуществляющая отображение меню""" pygame.init() pygame.mixer.init() mix = pygame.mixer mix.music.load("data/music/menu.wav") mix.music.play(loops=-1) clear() clock = pygame.time.Clock() running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.MOUSEBUTTONDOWN: pos = event.pos for btn in btn_group: btn.event(pos) screen.fill(pygame.Color('black')) check_menu() menubtn_group.draw(screen) footsp_group.draw(screen) # mix.unpause() clock.tick(FPS) pygame.display.flip() pygame.quit()
def map(self): self.flag = False screen.fill((0, 0, 0)) path = r'map' files = os.listdir(path) font = pygame.font.Font(None, 30) lst = self.chunks(files, 20) i = 0 while True: for event in pygame.event.get(): if event.type == pygame.QUIT: terminate() elif event.type == pygame.MOUSEBUTTONDOWN: p = event.pos if 10 <= p[0] <= font.size('назад')[0] + 10 and 30 <= p[ 1] <= font.size('назад')[1] + 30: if i: i -= 1 else: self.flag = True screen.fill((0, 0, 0)), screen.blit(FON, (0, 0)) return elif 920 <= p[0] <= font.size( 'далее')[0] + 920 and 30 <= p[1] <= font.size( 'далее')[1] + 30: if i + 1 < len(lst): i += 1 for _ in range(len(lst[i])): if 400 <= p[0] <= font.size(lst[i][_])[0] + 400 and \ 30 * _ + 30 <= p[1] <= font.size(lst[i][_])[1] + 30 + 30 * _: name, self.flag = 'map\\' + lst[i][_], True screen.fill((0, 0, 0)), screen.blit(FON, (0, 0)) return self.render(lst[i]) screen.blit(font.render('назад', 1, (255, 255, 255)), (10, 30)) screen.blit(font.render('далее', 1, (255, 255, 255)), (920, 30)) pygame.display.flip()
def render(self, lst): screen.fill((0, 0, 0)) for i in range(len(lst)): font = pygame.font.Font(None, 30) screen.blit(font.render(lst[i], 1, (255, 255, 255)), (400, 30 * i + 30))
def game(): group = pygame.sprite.Group() player_anim = Anime(group, (228, 288)) board = Board.load_map(None, name) board.set_view(30, 30, 30) lst = [] if sum(board.hero[0]): player = Player(screen, player_anim, board, board.hero[0]) player_anim.resize(30) if sum(board.hero[1]): tverdolobiy = Tverdolobiy(group, board.hero[1], board, player) tverdolobiy.resize(30) lst.append(tverdolobiy) if sum(board.hero[2]): merzopakostniy = Merzopakostniy(group, board.hero[2], board, player) merzopakostniy.resize(30) if sum(board.hero[3]): legushka = Legushka(group, board.hero[3], board, player) legushka.resize(30) lst.append(legushka) running = True c = 0 while running: c += 1 for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.MOUSEBUTTONDOWN: board.get_click(event.pos) if event.type == pygame.KEYDOWN: if event.key in up: player.set_dir('up') if event.key in down: player.set_dir('down') if event.key in left: player.set_dir('left') if event.key in right: player.set_dir('right') if event.key == pygame.K_LEFT: player.set_dir('left') if event.key == pygame.K_RIGHT: player.set_dir('right') if event.key == pygame.K_UP: player.set_dir('up') if event.key == pygame.K_DOWN: player.set_dir('down') screen.fill((0, 0, 0)) board.render() if not len(board.check_points): board.check_points.add(None) if not board.are_left(): board.reset() player.move([]) player_anim.rect.x, player_anim.rect.y = player.x, player.y if sum(board.hero[2]): merzopakostniy.move() if not c % 2: if sum(board.hero[3]): legushka.move() if sum(board.hero[1]): tverdolobiy.move() group.draw(screen) if c % 20 == 0: player_anim.update() if sum(board.hero[2]): check = Check(player, merzopakostniy.num_bomb() + lst) elif sum(board.hero[0]): check = Check(player, lst) if check.checkaed(): running = False draw(str(len(board.check_points) - 1 + board.count)) pygame.display.flip() Finish(group, str(len(board.check_points) - 1 + board.count))