diff --git a/ja b/ja index e562d4d..1ee6f54 100644 --- a/ja +++ b/ja @@ -90,6 +90,27 @@ class Player(pygame.sprite.Sprite): def draw(self, surface): surface.blit(self.image, self.rect) +class Cheese(pygame.sprite.Sprite): + def __init__(self, x, y): + super().__init__() + self.image = pygame.image.load('cheese.png').convert_alpha() + self.rect = self.image.get_rect() + self.rect.topleft = (x, y) + +def draw_maze(maze): + walls = [] + 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 == 'C': # 奶酪 + screen.blit(pygame.image.load('cheese.png'), (x * 32, y * 32)) + return walls + +player = Player(32, 32) +cheese = Cheese(416, 416) # 奶酪位置 + class Villain(pygame.sprite.Sprite): def __init__(self, x, y, player): super().__init__() @@ -129,19 +150,6 @@ class Villain(pygame.sprite.Sprite): def draw(self, surface): surface.blit(self.image, self.rect) -def draw_maze(maze): - walls = [] - 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 == 'C': # 奶酪 - screen.blit(pygame.image.load('cheese.png'), (x * 32, y * 32)) - return walls - -player = Player(32, 32) -cheese = Cheese(416, 416) # 奶酪位置 villain = Villain(704, 704, player) # 反派角色的起始位置 clock = pygame.time.Clock() @@ -185,6 +193,16 @@ while running: print("Game Over! You were caught by the villain.") running = False + # 如果玩家与奶酪碰撞,增加奶酪计数并将奶酪移动到新位置 + if player.rect.colliderect(cheese.rect): + player.cheese_count += 1 + print("You collected a cheese! Total cheese count:", player.cheese_count) + cheese.rect.topleft = (-32, -32) # 移除奶酪 + # 如果玩家收集了10个奶酪,则结束游戏 + if player.cheese_count >= 10: + print("Congratulations! You collected 10 cheeses!") + running = False + screen.fill(BLUE) draw_maze(maze) player.draw(screen)