forked from yogykwan/design-patterns-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemento.cc
More file actions
48 lines (34 loc) · 810 Bytes
/
memento.cc
File metadata and controls
48 lines (34 loc) · 810 Bytes
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
//
// Created by Jennica on 2017/1/3.
//
#include "memento.h"
#include <iostream>
StateMemento::StateMemento(int hp, int mp): hp_(hp), mp_(mp) {}
int StateMemento::GetHp() {
return hp_;
}
int StateMemento::GetMp() {
return mp_;
}
GameRole::GameRole(): hp_(100), mp_(100) {}
StateMemento* GameRole::CreateMemento() {
return new StateMemento(hp_, mp_);
}
void GameRole::StateDisplay() {
std::cout << hp_ << " " << mp_ << std::endl;
}
void GameRole::Fight() {
hp_ = 0;
mp_ = 0;
}
void GameRole::RecoveryState(StateMemento *memento) {
hp_ = memento->GetHp();
mp_ = memento->GetMp();
}
StateCaretaker::StateCaretaker(StateMemento *memento): memento_(memento) {}
StateCaretaker::~StateCaretaker() {
delete memento_;
}
StateMemento* StateCaretaker::GetMemento() {
return memento_;
}