fn victory(&mut self, ctx: &mut BTerm) { ctx.set_active_console(2); ctx.print_color_centered(2, GREEN, BLACK, "You have won!"); ctx.print_color_centered(4, WHITE, BLACK, "You put on the Amulet of Yala and feel its power course through\ your veins."); ctx.print_color_centered(5, WHITE, BLACK, "Your town is saved, and you can return to your normal life."); ctx.print_color_centered(7, GREEN, BLACK, "Press 1 to\ play again."); if let Some(VirtualKeyCode::Key1)=ctx.key { self.reset_game_state(); } }
最后,在 tick() 函数对应的匹配分支中添加对这个新函数的调用:
TurnState::GameOver => self.game_over(ctx), ➤ TurnState::Victory => self.victory(ctx),
这个函数提示玩家已经取得了胜利,并邀请他们再玩一局。现在运行游戏,一旦玩家角色找到了护身符,就取得了游戏的胜利,如图9-5和图9-6所示。
图9-5
图9-6
玩家找到了亚拉的护身符!恭喜,你赢了! EXr6287u6NNVz+GYLY+7SJneqzhu/PpYtW3JvBxL0w3TWONw8KRKos0qTZTOcW8905C1mNfvCHdpZEogE6oe6g==
评论 0条