有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Android中的java Clear data structures/Restart应用程序

我有一个名为“重启”的菜单按钮,它使用ArrayList重启屏幕上的一个简单文本游戏。我不确定如何“重启”我的应用程序,所以如果用户想玩新游戏,我可以为他们创建新的随机变量并清除屏幕

最佳的代码应该是,当在菜单上点击“restart”时,我可以重新启动应用程序

有什么想法吗

谢谢


共 (1) 个答案

  1. # 1 楼答案

    这是一个使用Memento Pattern的经典案例

    基本上,当一个阶段开始时,您将数据结构存储给发起者,当您想要重新启动时,您只需保存上一个memento,并根据检索到的memento恢复当前数据结构

    SimplyVinay.com

    The memento pattern deals with capturing an object’s internal state and saving it externally so that the internal state of that object can be restored later. This pattern is usually used in computer games where the state of the game can be saved, and can be started from the same point.