Oct-27-2023, 11:23 AM
Hello,
Long story short...I'm on my trip to learn programming. Recently I've bought a python book as a starting point. I've got some basics covered and at the end of the course plan was to write "snake" game - the same game as we know from Nokia 3310.
The code below is taken straight from the book.
Below is the code:
Could you take a look and suggest what's wrong with this code? Thanks in advance
Long story short...I'm on my trip to learn programming. Recently I've bought a python book as a starting point. I've got some basics covered and at the end of the course plan was to write "snake" game - the same game as we know from Nokia 3310.
The code below is taken straight from the book.
Below is the code:
import pygame
pygame.init()
CUBE_SIZE = 25
CUBES_NUM = 20
WIDTH = CUBE_SIZE * CUBES_NUM
screen = pygame.display.set_mode((WIDTH, WIDTH)) # here's the size of pygame window
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
WHITE = (255, 255, 255)
screen.fill(WHITE)
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
def draw_snake_part(x, y):
position = (x * CUBE_SIZE, y * CUBE_SIZE, CUBE_SIZE, CUBE_SIZE) # at this line I get error "This code is unreachable"
pygame.draw.rect(screen, GREEN, position)
pygame.display.update()
draw_snake_part(0, 0)
draw_snake_part(13, 16)At this point my program should've opened pygame window with two squares displayed, instead blank white window is opened.Could you take a look and suggest what's wrong with this code? Thanks in advance
