更新 jajaja
parent
12f5820f9b
commit
cdb464e0fa
10
jajaja
10
jajaja
|
@ -100,14 +100,18 @@ class Cheese(pygame.sprite.Sprite):
|
||||||
|
|
||||||
def draw_maze(maze):
|
def draw_maze(maze):
|
||||||
walls = []
|
walls = []
|
||||||
|
roads = [] # 存储道路的矩形列表
|
||||||
for y, row in enumerate(maze):
|
for y, row in enumerate(maze):
|
||||||
for x, char in enumerate(row):
|
for x, char in enumerate(row):
|
||||||
if char == '#':
|
if char == '#':
|
||||||
pygame.draw.rect(screen, BLACK, (x * 32, y * 32, 32, 32))
|
pygame.draw.rect(screen, BLACK, (x * 32, y * 32, 32, 32))
|
||||||
walls.append(pygame.Rect(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
|
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))
|
screen.blit(pygame.image.load('cheese.png'), (x * 32, y * 32))
|
||||||
return walls
|
return walls, roads
|
||||||
|
|
||||||
player = Player(32, 32)
|
player = Player(32, 32)
|
||||||
cheese = Cheese(416, 416) # Cheese position
|
cheese = Cheese(416, 416) # Cheese position
|
||||||
|
@ -183,7 +187,7 @@ while running:
|
||||||
elif keys[pygame.K_DOWN]:
|
elif keys[pygame.K_DOWN]:
|
||||||
dx = 0
|
dx = 0
|
||||||
|
|
||||||
walls = draw_maze(maze)
|
walls, roads = draw_maze(maze)
|
||||||
player.move(dx, dy, walls)
|
player.move(dx, dy, walls)
|
||||||
player.update_image(dx, dy)
|
player.update_image(dx, dy)
|
||||||
|
|
||||||
|
@ -196,7 +200,7 @@ while running:
|
||||||
if player.rect.colliderect(cheese.rect):
|
if player.rect.colliderect(cheese.rect):
|
||||||
player.cheese_count += 1
|
player.cheese_count += 1
|
||||||
print("You collected a cheese! Total cheese count:", player.cheese_count)
|
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:
|
if player.cheese_count >= 10:
|
||||||
print("Congratulations! You collected 10 cheeses!")
|
print("Congratulations! You collected 10 cheeses!")
|
||||||
running = False
|
running = False
|
||||||
|
|
Loading…
Reference in New Issue