static void Main(string[] args) { Stage[] stages = new[] { new Stage(Stage1), new Stage(Stage2), new Stage(Stage3), new Stage(Stage4), new Stage(Stage5), }; Originator originator = new Originator(); CareTaker careTaker = new CareTaker(); originator.SetStage(0); while (true) { int curStage = originator.GetStage(); if (curStage >= stages.Length) { break; } Console.WriteLine("-------------当前关卡 " + (curStage + 1) + "-------------"); careTaker.Add(originator.SaveStateToMemento()); bool isStageWin = stages[curStage].RunStage(new Random().Next(1, 6)); if (isStageWin) { Console.WriteLine("恭喜获胜,即将进入下一关"); originator.SetStage(++curStage); } else { Console.WriteLine("挑战失败,即将重新挑战"); curStage = careTaker.Get().GetStage(); originator.SetStage(curStage); } Console.WriteLine("------------------------------------"); Thread.Sleep(1000); } Console.WriteLine("恭喜通过所有关卡"); }