Esempio n. 1
0
    def process_keys(self):
        for event in pygame.event.get(KEYDOWN):
            if event.key == K_w or event.key == K_UP:
                self.set_direction('UP')
                self.dx = 0
                self.dy -= self.move_speed
            if event.key == K_s or event.key == K_DOWN:
                self.set_direction('DOWN')
                self.dx = 0
                self.dy += self.move_speed
            if event.key == K_a or event.key == K_LEFT:
                self.set_direction('LEFT')
                self.dx -= self.move_speed
                self.dy = 0
            if event.key == K_d or event.key == K_RIGHT:
                self.set_direction('RIGHT')
                self.dx += self.move_speed
                self.dy = 0
            if event.key == K_ESCAPE:
                terminate()

        for event in pygame.event.get(KEYUP):
            if (event.key == K_w or event.key == K_UP) and self.dy < 0:
                self.dy += min(-self.dy, self.move_speed)
            if (event.key == K_s or event.key == K_DOWN) and self.dy > 0:
                self.dy -= min(self.dy, self.move_speed)
            if (event.key == K_a or event.key == K_LEFT) and self.dx < 0:
                self.dx += min(-self.dx, self.move_speed)
            if (event.key == K_d or event.key == K_RIGHT) and self.dx > 0:
                self.dx -= min(self.dx, self.move_speed)
Esempio n. 2
0
 def update(self, pos, flag=False):
     font = pygame.font.Font(None, 30)
     x, y = pos
     if 20 <= x <= 30 + self.play[0] + 10 and 300 <= y <= 300 + self.play[
             1] and self.flag:
         screen.blit(font.render(self.word[0], 1, (0, 0, 0)), (30, 300))
         if flag:
             return True
     elif 20 <= x <= 30 + self.new_map[
             0] + 10 and 340 <= y <= 340 + self.new_map[1] and self.flag:
         screen.blit(font.render(self.word[1], 1, (0, 0, 0)), (30, 340))
         if flag:
             self.map()
     elif 20 <= x <= 30 + self.records[
             0] + 10 and 380 <= y <= 380 + self.records[1] and self.flag:
         screen.blit(font.render(self.word[2], 1, (0, 0, 0)), (30, 380))
         if flag:
             self.score()
     elif 20 <= x <= 30 + self.bye[0] + 10 and 420 <= y <= 420 + self.bye[
             1] and self.flag:
         screen.blit(font.render(self.word[3], 1, (0, 0, 0)), (30, 420))
         if flag:
             terminate()
     elif self.flag:
         self.draw()
Esempio n. 3
0
 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
Esempio n. 4
0
 def __init__(self, group, record):
     super().__init__(group)
     self.image = load_image('die.jpg')
     self.rect = self.image.get_rect().move(-1000, 0)
     #pygame.mixer.music.load('data\\probitie.wav')
     #pygame.mixer.music.play()
     while True:
         for event in pygame.event.get():
             if event.type == pygame.QUIT:
                 terminate()
             if event.type == pygame.MOUSEBUTTONDOWN and not self.rect.x:
                 x, y = event.pos
                 if 20 <= x <= 230 and 320 <= y <= 350:
                     return
                 elif 20 <= x <= 195 and 455 <= y <= 485:
                     a = name[name.index('\\') + 1:]
                     con = sqlite3.connect('data\\records.db')
                     cur = con.cursor()
                     hero = input('Введите ник: ')
                     result = cur.execute(
                         '''SELECT * from records where map="{}" 
                     AND name="{}"'''.format(a, hero)).fetchall()
                     if len(result):
                         if result[0][0] < int(record):
                             cur.execute('''UPDATE records SET point = {}
                              WHERE name = "{}"'''.format(
                                 int(record), hero)).fetchall()
                     else:
                         cur.execute('''INSERT INTO records 
                         VALUES ({},"{}","{}")'''.format(
                             int(record), hero, a)).fetchall()
                         con.commit()
                     print('Успешно введино')
                 elif 20 <= x <= 125 and 545 <= y <= 575:
                     terminate()
         if self.rect.x < 0:
             self.rect.x += 2
         time.sleep(0.00001)
         group.draw(screen)
         group.update()
         pygame.display.flip()
Esempio n. 5
0
def load_screen():
    if True:
        p = (-1, -1)
        f = False
        group = pygame.sprite.Group()
        b = Button()
        screen.blit(FON, (0, 0))
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    terminate()
                elif event.type == pygame.MOUSEMOTION:
                    p = event.pos
                    group.update(event.pos, False)
                    b.update(event.pos)
                elif event.type == pygame.MOUSEBUTTONDOWN:
                    if b.update(event.pos, True):
                        game()
                        return
            group.update(p, f)
            group.draw(screen)
            pygame.display.flip()
            clock.tick(FPS)
Esempio n. 6
0
 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()