更新 jajaja

main
Vincents Xun 2024-04-26 06:41:55 +00:00
parent 12f5820f9b
commit cdb464e0fa
1 changed files with 7 additions and 3 deletions

10
jajaja
View File

@ -100,14 +100,18 @@ class Cheese(pygame.sprite.Sprite):
def draw_maze(maze):
walls = []
roads = [] # 存储道路的矩形列表
for y, row in enumerate(maze):
for x, char in enumerate(row):
if char == '#':
pygame.draw.rect(screen, BLACK, (x * 32, y * 32, 32, 32))
walls.append(pygame.Rect(x * 32, y * 32, 32, 32))
elif char == '.':
roads.append(pygame.Rect(x * 32, y * 32, 32, 32))
elif char == 'C': # Cheese
roads.append(pygame.Rect(x * 32, y * 32, 32, 32))
screen.blit(pygame.image.load('cheese.png'), (x * 32, y * 32))
return walls
return walls, roads
player = Player(32, 32)
cheese = Cheese(416, 416) # Cheese position
@ -183,7 +187,7 @@ while running:
elif keys[pygame.K_DOWN]:
dx = 0
walls = draw_maze(maze)
walls, roads = draw_maze(maze)
player.move(dx, dy, walls)
player.update_image(dx, dy)
@ -196,7 +200,7 @@ while running:
if player.rect.colliderect(cheese.rect):
player.cheese_count += 1
print("You collected a cheese! Total cheese count:", player.cheese_count)
cheese.rect.topleft = (random.randint(0, 24) * 32, random.randint(0, 24) * 32) # Move cheese to a new position
cheese.rect.topleft = random.choice(roads).topleft # Move cheese to a random position on a road
if player.cheese_count >= 10:
print("Congratulations! You collected 10 cheeses!")
running = False