以下是一个简单的捕鱼达人游戏的代码示例: ```python import random class Fish: def __init__(self): self.x = random.randint(0, 10) self.y = random.randint(0, 10) def move(self): self.x += random.randint(-1, 1) self.y += random.randint(-1, 1) class Player: def __init__(self): self.x = 5 self.y = 5 self.score = 0 def move(self, direction): if direction == 'up': self.y -= 1 elif direction == 'down': self.y += 1 elif direction == 'left': self.x -= 1 elif direction == 'right': self.x += 1 def catch(self, fish): if fish.x == self.x and fish.y == self.y: self.score += 1 return True return False class Game: def __init__(self): self.player = Player() self.fishes = [Fish() for _ in range(5)] def play(self): while True: direction = input("输入移动方向(up/down/left/right): ") self.player.move(direction) for fish in self.fishes: fish.move() if self.player.catch(fish): print("你捕捉到一条鱼!") self.fishes.remove(fish) if len(self.fishes) == 0: print("恭喜你,你已经捕捉到所有鱼!得分:", self.player.score) break if __name__ == '__main__': game = Game() game.play() ``` 此代码示例使用Python实现一个简单的捕鱼达人游戏。游戏中有一个玩家和一些鱼。玩家可以移动,并尝试捕捉在游戏区域中移动的鱼。当玩家成功捕捉到所有鱼时,游戏结束。 游戏开始时,玩家位于`(5, 5)`的初始位置,而鱼的位置是随机生成的。玩家可以通过输入移动方向来移动,包括"up"、"down"、"left"和"right"。每次玩家移动后,游戏会更新鱼的位置,并检查是否有鱼被玩家捕捉到。如果有,玩家的得分将增加,并从鱼的列表中删除该鱼。 游戏循环执行直到所有鱼被捕捉或玩家选择退出游戏。当所有鱼被捕捉时,游戏会输出玩家的得分并结束。 [2024-06-14 15:23:35 | AI写代码神器 | 1338点数解答]