From c4ef8e250ef9464e5a0241e4847ead43100d9bc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E5=BF=97=E6=9D=B0?= <12806428+kkm3278@user.noreply.gitee.com> Date: Sun, 17 Dec 2023 15:48:49 +0000 Subject: [PATCH] =?UTF-8?q?=E5=88=B6=E4=BD=9C=E4=B8=80=E4=B8=AA=E6=96=B0?= =?UTF-8?q?=E6=89=8B=E6=95=99=E7=A8=8B=E5=85=B3=E5=8D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孔志杰 <12806428+kkm3278@user.noreply.gitee.com> --- map.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/map.py b/map.py index 3c7c79f..d243a8a 100644 --- a/map.py +++ b/map.py @@ -163,6 +163,69 @@ class Map(Level): else: self.snake.outofbound = False +#新手教程 +class Tutorial(Map): + def __init__(self, width, height): + super().__init__(width, height) + self.attacks = [] + self.exp_balls = [] + self.goal = 10 + self.exp_gain = 2 + self.health_loss = 1 + self.tutorial_text = [ + "欢迎来到新手教程!", + "你的目标是吃掉10个经验球。", + "避开攻击物品,否则你的血量会减少。", + "开始吧!" + ] + self.current_tutorial_step = 0 + + def is_passed(self): + if self.snake.exp >= self.goal: + return True + return False + + def update(self): + # 更新攻击物品的位置 + for attack in self.attacks: + attack.move() + + # 更新经验球的位置 + for exp_ball in self.exp_balls: + exp_ball.move() + + # 检查蛇与攻击的碰撞 + for attack in self.attacks: + if self.snake.check_collision(attack): + self.snake.health -= self.health_loss + + # 检查蛇与经验球的碰撞 + for exp_ball in self.exp_balls: + if self.snake.check_collision(exp_ball): + self.snake.exp += self.exp_gain + + # 更新教程步骤 + self.current_tutorial_step += 1 + + def draw(self): + # 绘制蛇 + self.snake.draw() + + # 绘制攻击物品 + for attack in self.attacks: + attack.draw() + + # 绘制经验球 + for exp_ball in self.exp_balls: + exp_ball.draw() + + # 绘制教程文本 + if self.current_tutorial_step < len(self.tutorial_text): + self.draw_text(self.tutorial_text[self.current_tutorial_step]) + + def draw_text(self, text): + # 绘制文本 + pass class Level1(Map): """ -- Gitee