Boa tarde, estou fazendo um jogo para um trabalho da escola, e queria fazer um jogo em python, mas sou bem iniciante.
A ideia é um jogo da cobra normal, mas a cada 10~15 vezes que o jogador come a fruta aparece uma especial, que abre uma tela que mostra uma pergunta, aí ele tem que apertar o botao da correta, se ele acertar, cresce só um vez, se errar cresce 10, mas como sou iniciante não tneho muita ideia de como fazer, então copiei um código pronto e tentei adaptar, mas tá dando milhares de erros e eu não tenho a minima ideia de como arrumar, e esta totalmente errado
import pygame
import sys
import time
import random
import collections
import itertools
import os
def main():"""Snake v 1.59"""
score =0# Initial score
speed = pygame.time.Clock()
direction ="R"# Initial direction
snake_position = collections.deque([100,50])# Initial snake position
snake_body = collections.deque([[100,50],[90,50],[100,50]])# Initial snake body# It places the food randomly, excluding the border
food_position =[random.randrange(1,72)*10, random.randrange(1,46)*10]
food_spawn =True
comida_position =[random.randrange(1,72)*10, random.randrange(1,46)*10]
question_spawn =True# Will define the colors
white = pygame.Color("white")
red = pygame.Color("red")
green = pygame.Color("green")
black = pygame.Color("black")
orange = pygame.Color("orange")
grey = pygame.Color("light grey")# Game surface
player_screen = pygame.display.set_mode((720,460))# Set screen size
pygame.display.set_caption("Snake Game - The Crow")# Set screen title and versiondef initializer():## """ Checks the mistakes, and closes the program if it does while## printing on the console how many bugs it has, also initializes## the mixers, and game """## pygame.mixer.pre_init(44100, -16, 1, 512)## pygame.mixer.init()## bugs = pygame.init()## if bugs[1] > 0:## print("There are", bugs[1], "bugs! quiting.....")## time.sleep(3)## sys.exit("Closing program")## else:print("The game was initialized")def you_lose():""" When the players loses, it will show a red message in times new
roman font with 44 px size in a rectangle box"""
font_game_over = pygame.font.SysFont("times new roman",44)
game_over_surface = font_game_over.render("Game over :(",True, red)
game_over_position = game_over_surface.get_rect()
game_over_position.midtop =(360,15)
player_screen.blit(game_over_surface, game_over_position)
scoring()
pygame.display.flip()# Updates the screen, so it doesnt freeze
quiting()def pause_menu():"""It displays the pause menu"""
player_screen.fill(white)
pause_font = pygame.font.SysFont("times new roman",44)
pause_surface = pause_font.render("Paused",True, black)
pause_position = pause_surface.get_rect()
pause_position.midtop =(360,15)
player_screen.blit(pause_surface, pause_position)
pygame.display.flip()def question_menu():"""Question about the book"""
player_screen.fill(orange)
question_font = pygame.font.SysFont("arial",44)
question_surface = question_font.render("Questions",True, black)
question_position = question_surface.get_rect()
question_position.midtop =(360,15)
player_screen.blit(question_surface, question_position)classQuestion:def __init__(self, prompt, answer):
self.prompt = prompt
self.answer = answer
question_prompts =['Ta errado? \n(0) Sim \n(1) Claro \n(2) Obvio \n(3) Com certeza''Ta incorreo? \n(0) Sim \n(1) Claro \n(2) Obvio \n(3) Com certeza']
questions =[Question(question_prompts[0],"0"),Question(question_prompts[1],"1"),]
key_00 = event.key in(pygame.K_0)
key_01 = event.key in(pygame.K_1)
key_02 = event.key in(pygame.K_2)
key_03 = event.key in(pygame.K_3)def run_quiz(questions):for question in questions:
resposta = input(question.prompt)if answer == question.answer:
score +=1else:
score +=10
run_quiz(questions)
pygame.display.flip()def quiting():""" When this function is called, it will wait 4 seconds and exit"""
time.sleep(4)
pygame.quit()
sys.exit()def scoring():""" It will shows the score after the game over in times new
roman font with 16px size and black color in a rectangle box"""
score_font = pygame.font.SysFont("times new roman",16)
score_surface = score_font.render("Score : {}".format(score),True, red)
score_position = score_surface.get_rect()
score_position.midtop =(360,80)
player_screen.blit(score_surface, score_position)
initializer()
paused =FalsewhileTrue:for event in pygame.event.get():if event.type == pygame.QUIT:
quiting()elif event.type == pygame.KEYDOWN:if event.key == pygame.K_p:# Pausing/ unpausing
paused =not paused
if paused:
pause_menu()# Choose direction by user input, block opposite directions
key_right = event.key in(pygame.K_RIGHT, pygame.K_d)
key_left = event.key in(pygame.K_LEFT, pygame.K_a)
key_down = event.key in(pygame.K_DOWN, pygame.K_s)
key_up = event.key in(pygame.K_UP, pygame.K_w)if key_right and direction !="L":
direction ="R"elif key_left and direction !="R":
direction ="L"elif key_down and direction !="U":
direction ="D"elif key_up and direction !="D":
direction ="U"elif event.key == pygame.K_ESCAPE:
quiting()# It will quit when esc is pressed# Simulates the snake movement(together with snake_body_pop)ifnot paused:if direction =="R":
snake_position[0]+=10elif direction =="L":
snake_position[0]-=10elif direction =="D":
snake_position[1]+=10elif direction =="U":
snake_position[1]-=10# Body mechanics
snake_body.appendleft(list(snake_position))if snake_position == collections.deque(comida_position):
question_menu()else:# If the food is taken it will not remove the last body piece(raising snakes size)
snake_body.pop()if question_spawn isFalse:# When a food is taken it will respawn randomly
comida_position =[random.randrange(1,72)*10, random.randrange(1,46)*10]
question_spawn =True# It will set the food to True again, to keep the cycle# Drawing
player_screen.fill(black)# Set the background to blackfor position in snake_body:# Snake representation on the screen
pygame.draw.rect(player_screen, green, pygame.Rect(position[0], position[1],10,10))# Food representation on the screen
pygame.draw.rect(player_screen, red, pygame.Rect(comida_position[0], comida_position[1],10,10))if snake_position[0]notin range(0,711)or snake_position[1]notin range(0,451):
you_lose()# Game over when the Snake hit a wallfor block in itertools.islice(snake_body,1,None):if snake_position == collections.deque(block):
you_lose()# Game over when the Snake hits itself
pygame.display.flip()# It constantly updates the screen
speed.tick(15)# It sets the speed to a playable valueif __name__ =="__main__":
main()
Pergunta
gust.oliveira
Boa tarde, estou fazendo um jogo para um trabalho da escola, e queria fazer um jogo em python, mas sou bem iniciante.
A ideia é um jogo da cobra normal, mas a cada 10~15 vezes que o jogador come a fruta aparece uma especial, que abre uma tela que mostra uma pergunta, aí ele tem que apertar o botao da correta, se ele acertar, cresce só um vez, se errar cresce 10, mas como sou iniciante não tneho muita ideia de como fazer, então copiei um código pronto e tentei adaptar, mas tá dando milhares de erros e eu não tenho a minima ideia de como arrumar, e esta totalmente errado
Link para o comentário
Compartilhar em outros sites
1 resposta a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.