forked from FengJungle/DesignPattern
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameAccount.cpp
More file actions
78 lines (67 loc) · 1.33 KB
/
GameAccount.cpp
File metadata and controls
78 lines (67 loc) · 1.33 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "GameAccount.h"
#include "Level.h"
#include <Windows.h>
#include <time.h>
#define random(x) (rand()%x)
GameAccount::GameAccount(){
level = nullptr;
printf("创立游戏角色,积分:100,级别:PRIMARY\n");
score = 100;
name = "none";
setLevel(new Primary(this));
}
GameAccount::GameAccount(string iName){
level = nullptr;
printf("创立游戏角色,积分:100,级别:PRIMARY\n");
score = 100;
name = iName;
setLevel(new Primary(this));
}
GameAccount::~GameAccount(){
if(level){
delete level;
level = nullptr;
}
}
void GameAccount::setLevel(Level* iLevel){
if(level != nullptr){
delete level;
level = nullptr;
}
this->level = iLevel;
}
string GameAccount::getName(){
return name;
}
void GameAccount::playCard(){
this->level->playCard();
Sleep(100);
srand((int)time(0));
int res = random(2);
if (res % 2 == 0){
this->win();
}
else{
this->lose();
}
this->level->upgradeLevel();
}
void GameAccount::win(){
if (this->getScore() < 200){
setScore(getScore() + 50);
}
else{
setScore(getScore() + 100);
}
printf("\n\t胜利,最新积分为 %d\n", score);
}
void GameAccount::lose(){
setScore(getScore() + 30);
printf("\n\t输牌,最新积分为 %d\n", score);
}
int GameAccount::getScore(){
return this->score;
}
void GameAccount::setScore(int iScore){
this->score = iScore;
}