## Sayohatchi import os import time import pygame import random import easysql as es pygame.init() pygame.display.set_caption(f"SAYOHATCHI") DISPLAY = pygame.display.set_mode((1366, 768)) def load(path): return path base = es.contact("database.db").base for onq in es.select(base, 'localist').all: es.delete(base, 'localist', f"SavID={onq[0]}") for question in es.select(base, 'questions').all: es.insert(base, 'localist', """ %s, '%s', '%s' """ % (question[0], question[1], question[2])) pygame.display.set_icon(pygame.image.load(load('icon%s.ico' % 1))) class sep: balloons = {1:692, 2:1800, 3:3030, 4:4092, 5:5000, 6:5777, 7:6478, 8:6930, 9:7555, 10:8465} background = pygame.image.load(load('121212.png')).convert_alpha() bg_x = 0 bg_y = 0 player = pygame.image.load(load('player1.png')) pl_x = 80 pl_y = 415 speed = 3 startbg = pygame.image.load(load('startbg1.png')) balloon = pygame.image.load(load('balloon1.png')) def draw_text(surf, text, size, color, x, y, font='gamefont.otf'): font = pygame.font.Font(load(font), size) text_surface = font.render(text, True, color) text_rect = text_surface.get_rect() text_rect.midtop = (x, y) surf.blit(text_surface, text_rect) clock = pygame.time.Clock() FPS = 60 START = True GAME = False QUIZ = False MOTION = False QUESTWIN = False run = True while run: while START: for event in pygame.event.get(): if event.type == pygame.QUIT: run = False START = run elif event.type == pygame.KEYDOWN: if event.key == 13: START = False GAME = True DISPLAY.blit(sep.startbg, (0, 0)) draw_text(DISPLAY, "O'yinni boshlash uchun ENTERni bosing", 36, (0, 0, 0),695, 700) pygame.display.update() while GAME: for event in pygame.event.get(): if event.type == pygame.QUIT: run = False GAME = run elif event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT or event.key == pygame.K_d: MOTION = True elif event.type == pygame.KEYUP: if event.key == pygame.K_RIGHT or event.key == pygame.K_d: MOTION = False if MOTION: if sep.bg_x < -8444: final = True while final: for event in pygame.event.get(): if event.type == pygame.QUIT: final = False GAME = False run = False gameoverph = pygame.image.load(load('gamewin.png')) DISPLAY.blit(gameoverph, (0, 0)) draw_text(DISPLAY, "Siz yutdingiz!", 100, (0, 0, 0), 700, 41) pygame.display.update() else: newballoons = sep.balloons.copy() for balloonx in sep.balloons: newballoons.update({balloonx:int(sep.balloons[balloonx] - sep.speed)}) sep.balloons.clear() sep.balloons = newballoons sep.bg_x -= sep.speed updaten_balloons = {} balloonhits = False for ballooncor in sep.balloons: if sep.balloons[ballooncor] <= int(sep.pl_x + 270): balloonhits = True else: updaten_balloons.update({ballooncor:sep.balloons[ballooncor]}) sep.balloons.clear() sep.balloons = updaten_balloons DISPLAY.blit(sep.background, (sep.bg_x, sep.bg_y)) DISPLAY.blit(sep.player, (sep.pl_x, sep.pl_y)) for balloon in sep.balloons: DISPLAY.blit(sep.balloon, (sep.balloons[balloon], sep.pl_y)) if balloonhits: GAME = False QUIZ = True pygame.display.update() clock.tick(FPS) while QUIZ: power = True fon = pygame.image.load(load('whitefon.png')) DISPLAY.blit(fon, (334, 187)) questions = [] for quest in es.select(base, 'localist').all: questions.append(quest) questiox = random.choice(questions) es.delete(base, 'localist', f'SavID={questions.index(questiox) + 1}') draw_text(DISPLAY, questiox[1], 20, (0, 0, 0), 683, 200, 'ARIAL.TTF') pygame.display.update() answer = '' while power: for event in pygame.event.get(): if event.type == pygame.QUIT: power = False QUIZ = False run = False elif event.type == pygame.KEYDOWN: try: if event.key == pygame.K_BACKSPACE: if not answer == '': answer = answer[:-1] elif event.key == 13: power = False else: unic = chr(event.key) answer = f"{answer}{unic.upper()}" except: pass DISPLAY.blit(fon, (334, 187)) draw_text(DISPLAY, questiox[1], 20, (0, 0, 0), 683, 200, 'ARIAL.TTF') draw_text(DISPLAY, answer, 36, (0, 0, 0), 683, 303, 'ARIAL.TTF') pygame.display.update() correct = False if answer.upper() == questiox[2].upper(): correct = True if not correct: draw_text(DISPLAY, questiox[2], 44, (255, 0, 0), 683, 333) pygame.display.update() time.sleep(3) waittime = True while waittime: for event in pygame.event.get(): if event.type == pygame.QUIT: run = False QUIZ = False waittime = False gameoverim = pygame.image.load(load('gameover.png')) DISPLAY.blit(gameoverim, (0, 0)) draw_text(DISPLAY, "O'yin tugadi!", 100, (0, 0, 0), 700, 41) pygame.display.update() elif correct: QUIZ = False GAME = True pygame.quit() ## Olma Daraxti import os import time import random import pygame from pygame_widgets import update as wgupdate from pygame_widgets.button import Button import easysql as es pygame.init() DISPLAY = pygame.display.set_mode((1641, 823)) pygame.display.set_caption('Olma Daraxti') def load(path): DIR = os.getcwd() PATH = "%s\\%s" % (DIR, path) return PATH pygame.display.set_icon(pygame.image.load(load('icon.ico'))) corrects = 0 mistakes = 0 base = es.contact('database.db').base def draw_text(surf, text, size, color, x, y, font='gamefont.otf'): font = pygame.font.Font(load(font), size) text_surface = font.render(text, True, color) text_rect = text_surface.get_rect() text_rect.midtop = (x, y) surf.blit(text_surface, text_rect) questions = es.select(base, 'questions').all pressedb = 0 def b1f(c): b1.hide() ButtonFunc() def b2f(c): b2.hide() ButtonFunc() def b3f(c): b3.hide() ButtonFunc() def b4f(c): b4.hide() ButtonFunc() def b5f(c): b5.hide() ButtonFunc() def b6f(c): b6.hide() ButtonFunc() def b7f(c): b7.hide() ButtonFunc() def b8f(c): b8.hide() ButtonFunc() def b9f(c): b9.hide() ButtonFunc() def b10f(c): b10.hide() ButtonFunc() def ButtonFunc(): global pressedb one = random.choice(questions) questions.remove(one) answer = '' power = True global run while power: for event in pygame.event.get(): if event.type == pygame.QUIT: power = False run = False elif event.type == pygame.KEYDOWN: try: if event.key == pygame.K_BACKSPACE: if not answer == '': answer = answer[:-1] elif event.key == 13: power = False else: unic = chr(event.key) answer = f"{answer}{unic.upper()}" except: pass DISPLAY.blit(pygame.image.load(load('sprites/whitefon.png')), (471, 215)) draw_text(DISPLAY, f"SAVOL : {one[1]}", 20, (0, 0, 0), 820, 230, 'ARIAL.TTF') draw_text(DISPLAY, answer, 30, (0, 0, 0), 820, 360, 'ARIAL.TTF') pygame.display.update() correct = False if answer.upper() == one[2].upper(): correct = True global corrects, mistakes if not correct: mistakes += 1 draw_text(DISPLAY, one[2], 36, (255, 0, 0), 820, 430) pygame.display.update() time.sleep(3) elif correct: corrects += 1 pressedb += 1 run = True apples = [(155, 64),(125,235),(310, 215),(26, 235),(255, 59),(151, 151),(84, 120),(251, 163),(36, 171),(227, 234)] tree = pygame.image.load(load('sprites/tree_1.png')) apple = pygame.image.load(load('sprites/apple_1.png')) ground = pygame.image.load(load('sprites/ground.png')) once_only = True while run: for event in pygame.event.get(): if event.type == pygame.QUIT: run = False break DISPLAY.fill((255, 255, 255)) DISPLAY.blit(ground, (0, 0)) DISPLAY.blit(tree, (620, 220)) buttons = [] olmalar = [] for a in apples: x = a[0] x += 630 y = a[1] y += 220 olmalar.append((x, y)) if once_only: b1 = Button(DISPLAY, olmalar[0][0], olmalar[0][1], 40, 49, radius=30, onClick=lambda: b1f((apples[0][0], apples[0][1])), image=apple) b2 = Button(DISPLAY, olmalar[1][0], olmalar[1][1], 40, 49, radius=30, onClick=lambda: b2f((apples[1][0], apples[1][1])), image=apple) b3 = Button(DISPLAY, olmalar[2][0], olmalar[2][1], 40, 49, radius=30, onClick=lambda: b3f((apples[2][0], apples[2][1])), image=apple) b4 = Button(DISPLAY, olmalar[3][0], olmalar[3][1], 40, 49, radius=30, onClick=lambda: b4f((apples[3][0], apples[3][1])), image=apple) b5 = Button(DISPLAY, olmalar[4][0], olmalar[4][1], 40, 49, radius=30, onClick=lambda: b5f((apples[4][0], apples[4][1])), image=apple) b6 = Button(DISPLAY, olmalar[5][0], olmalar[5][1], 40, 49, radius=30, onClick=lambda: b6f((apples[5][0], apples[5][1])), image=apple) b7 = Button(DISPLAY, olmalar[6][0], olmalar[6][1], 40, 49, radius=30, onClick=lambda: b7f((apples[6][0], apples[6][1])), image=apple) b8 = Button(DISPLAY, olmalar[7][0], olmalar[7][1], 40, 49, radius=30, onClick=lambda: b8f((apples[7][0], apples[7][1])), image=apple) b9 = Button(DISPLAY, olmalar[8][0], olmalar[8][1], 40, 49, radius=30, onClick=lambda: b9f((apples[8][0], apples[8][1])), image=apple) b10 = Button(DISPLAY, olmalar[9][0], olmalar[9][1], 40, 49, radius=30, onClick=lambda: b10f((apples[9][0], apples[9][1])), image=apple) once_only = False elif not once_only: None if pressedb == 10: final = True oncetype = True def typer(surf,text,size,cor,wait): written = '' for t in text: surf.blit(pygame.image.load(load('sprites/result.png')), (0, 0)) written = '%s%s' % (written, t) draw_text(surf, written, size, (255, 255, 255), cor[0], cor[1]) time.sleep(wait) pygame.display.update() while final: for event in pygame.event.get(): if event.type == pygame.QUIT: final = False run = False break if oncetype: typer(DISPLAY, 'Natija', 100, (820, 41), 0.15) typer(DISPLAY, f"To'g'ri javoblar : {corrects}", 36, (820, 400), 0.1) typer(DISPLAY, f"Noto'g'ri javoblar : {mistakes}", 36, (820, 440), 0.1) draw_text(DISPLAY, 'Natija', 100, (255, 255, 255), 820, 41) draw_text(DISPLAY, f"To'g'ri javoblar : {corrects}", 36, (255, 255, 255), 820, 400) draw_text(DISPLAY, f"Noto'g'ri javoblar : {mistakes}", 36, (255, 255, 255), 820, 440) pygame.display.update() oncetype = False wgupdate(pygame.event.get()) pygame.display.update() pygame.quit() exit()