Created
August 12, 2021 12:05
-
-
Save thaisviana/79b110bd73939d6643089e73f28cfcdf to your computer and use it in GitHub Desktop.
Jogo Quadradinho
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
from CONSTANTS import largura_tela, altura_tela, cor, tempo_total_do_jogo,numero_inicial_de_quadradinhos | |
from Quadradinho import Quadradinho | |
from time import sleep | |
def mostra_tempo(tempo, pontos): | |
font = pygame.font.Font(None, 24) | |
text = font.render(f"Tempo: {tempo}s | Pontuação: {pontos}", 1, cor['BRANCO']) | |
textpos = text.get_rect(centerx=tela.get_width()/2) | |
tela.blit(text, textpos) | |
def mostra_pontuacao_final(tela, pontos): | |
tela.fill(cor['PRETO']) # Limpa tela | |
font = pygame.font.Font(None, 36) | |
text = font.render("Pontuação: " + str(pontos) + " quadradinhos", 1, cor['BRANCO']) | |
textpos = text.get_rect(center=(tela.get_width()/2, tela.get_height()/2)) | |
tela.blit(text, textpos) | |
pygame.init() | |
tela = pygame.display.set_mode((largura_tela, altura_tela)) | |
clock = pygame.time.Clock() | |
tempo_corrente = tempo_total_do_jogo | |
pontos = 0 | |
conta_clocks = 0 | |
terminou = False | |
lista_de_quadradinhos = Quadradinho.cria_n_quadradinhos(numero_inicial_de_quadradinhos) | |
while not terminou: | |
conta_clocks += 1 | |
if tempo_corrente > 0: | |
mostra_tempo(tempo_corrente, pontos) | |
for q in lista_de_quadradinhos: | |
q.desenha(tela) | |
if conta_clocks == 50: | |
conta_clocks = 0 | |
tempo_corrente -= 1 | |
lista_de_quadradinhos = Quadradinho.cria_n_quadradinhos(numero_inicial_de_quadradinhos) | |
for event in pygame.event.get(): | |
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: | |
pos = pygame.mouse.get_pos() | |
for q in lista_de_quadradinhos: | |
if q.area.collidepoint(pos): | |
lista_de_quadradinhos.remove(q) | |
pontos = pontos + 1 | |
if event.type == pygame.QUIT: | |
terminou = True | |
if tempo_corrente == 0: | |
lista_de_quadradinhos.clear() | |
mostra_pontuacao_final(tela, pontos) | |
pygame.display.update() | |
tela.fill(cor['PRETO']) | |
else: | |
mostra_pontuacao_final(tela, pontos) | |
pygame.display.update() | |
tela.fill(cor['PRETO']) | |
clock.tick(50) | |
pygame.display.quit() | |
pygame.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment