GithubHelp home page GithubHelp logo

Lot about pygame HOT 1 OPEN

Michael11-2 avatar Michael11-2 commented on June 26, 2024
Lot

from pygame.

Comments (1)

Michael11-2 avatar Michael11-2 commented on June 26, 2024

import pygame
import sys

pygame.init()

Configurar la pantalla

screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption('Juego de IoT en Colombia')

Colores

WHITE = (255, 255, 255)
BLACK = (0, 0, 0)

Fuentes

font = pygame.font.Font(None, 36)

Preguntas y respuestas

questions = [
("¿Qué es el IoT?", "Internet de las Cosas"),
("Ejemplo de IoT en la agricultura en Colombia:", "Sensores de suelo"),
("Uso de IoT en la salud en Colombia:", "Monitoreo de pacientes")
]

current_question = 0
user_answer = ''
correct_answers = 0

def draw_text(text, font, color, surface, x, y):
textobj = font.render(text, 1, color)
textrect = textobj.get_rect()
textrect.topleft = (x, y)
surface.blit(textobj, textrect)

Bucle principal del juego

while True:
screen.fill(WHITE)

for event in pygame.event.get():
    if event.type == pygame.QUIT:
        pygame.quit()
        sys.exit()
    if event.type == pygame.KEYDOWN:
        if event.key == pygame.K_RETURN:
            # Verificar respuesta
            if user_answer.lower() == questions[current_question][1].lower():
                correct_answers += 1
            current_question += 1
            user_answer = ''
            if current_question >= len(questions):
                current_question = 0
        elif event.key == pygame.K_BACKSPACE:
            user_answer = user_answer[:-1]
        else:
            user_answer += event.unicode

if current_question < len(questions):
    draw_text(questions[current_question][0], font, BLACK, screen, 20, 100)
    draw_text(user_answer, font, BLACK, screen, 20, 200)
else:
    draw_text(f'Juego terminado! Respuestas correctas: {correct_answers}', font, BLACK, screen, 20, 100)

pygame.display.update()

from pygame.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.