forked from WeihanLi/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
52 lines (40 loc) · 1.19 KB
/
Program.cs
File metadata and controls
52 lines (40 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
namespace MementoPattern
{
public class Program
{
public static void Main(string[] args)
{
#region Prototype
var originator = new Originator
{
State = "On"
};
originator.Show();
var caretaker = new Caretaker
{
Memento = originator.CreateMemento()
};
originator.State = "Off";
originator.Show();
originator.SetMemento(caretaker.Memento);
originator.Show();
Console.WriteLine();
#endregion Prototype
var lixiaoyao = new GameRole();
lixiaoyao.StateDisplay();
//保存状态
var stateCaretasker = new RoleStateCarertaker
{
Memento = lixiaoyao.SaveState()
};
// 大战 Boss
lixiaoyao.FightWithBoss();
lixiaoyao.StateDisplay();
// 快被 Boss 打挂了,恢复之前的状态,继续打
lixiaoyao.RecoveryState(stateCaretasker.Memento);
lixiaoyao.StateDisplay();
Console.ReadLine();
}
}
}