设计模式 memento_test 实现

2022-07-21 浏览 (1201)

golang 设计模式 memento_test 代码实现

package memento

func ExampleGame() {
	game := &Game{
		hp: 10,
		mp: 10,
	}

	game.Status()
	progress := game.Save()

	game.Play(-2, -3)
	game.Status()

	game.Load(progress)
	game.Status()

	// Output:
	// Current HP:10, MP:10
	// Current HP:7, MP:8
	// Current HP:10, MP:10
}

目录

go 设计模式

相关文章

备忘录模式

设计模式 memento 实现

  • 所属分类: 后端技术
  • 本文标签: golang
  • 版权声明: 本文链接 https://seaxiang.com/blog/dbcd1f9174ae48c4a9772840423c076d