-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstdoutlogger.cpp
More file actions
184 lines (158 loc) · 6.1 KB
/
stdoutlogger.cpp
File metadata and controls
184 lines (158 loc) · 6.1 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include "stdoutlogger.h"
#include <ctime>
#include <iostream>
#include <iomanip>
#include "constants.h"
#include "host.h"
static void PrintTime(std::ostream& out, time_t tmTime){
tm* tmLocalTime = localtime(&tmTime);
out << '[' << tmLocalTime->tm_year+1900 << '/'
<< tmLocalTime->tm_mon << '/'
<< tmLocalTime->tm_mday << ' '
<< tmLocalTime->tm_hour << ':'
<< tmLocalTime->tm_min << ':'
<< tmLocalTime->tm_sec << ']';
}
StdoutLogger::StdoutLogger():EventLogger("StdoutLogger"), Out(std::cout){}
void StdoutLogger::HostInitialized(time_t tmTime){
PrintTime(Out, tmTime);
Out << " Host is initialized." << std::endl;
}
void StdoutLogger::AISetup(time_t tmTime, int iCount){
PrintTime(Out, tmTime);
Out << ' ' << iCount << " AI(s) are set up." << std::endl;
}
void StdoutLogger::GameStarted(time_t tmTime){
PrintTime(Out, tmTime);
Out << " Game is started." << std::endl;
}
void StdoutLogger::GameEnded(time_t tmTime, const int* iId){
using std::endl;
using std::setw;
PrintTime(Out, tmTime);
Out << " Game is ended." << endl;
Out << "Result:" << endl;
Out << std::left;
Out << setw(7) << "Id"
<< setw(7) << "Author"
<< setw(7) << "Points"
<< setw(7) << "Bonus"
<< setw(7) << "Exp"
<< setw(7) << "Level"
<< setw(7) << "Kill"
<< setw(7) << "Dead"
<< setw(7) << "Attack"
<< setw(7) << "Speed"
<< setw(7) << "HP"
<< setw(7) << "MaxHP"
<< endl;
for (int i = 0; i<host.getPlayerCount(); ++i){
int x = iId[i];
Out << setw(7) << x
<< setw(7) << host.getIdentifier(x)
<< setw(7) << host.getPoint(x)
<< setw(7) << host.getKillBonus(x)
<< setw(7) << host.getExp(x)
<< setw(7) << host.getLevel(x)
<< setw(7) << host.getKillCount(x)
<< setw(7) << host.getDeadCount(x)
<< setw(7) << host.getAtt(x)
<< setw(7) << host.getSp(x)
<< setw(7) << host.getHP(x)
<< setw(7) << host.getMaxHP(x)
<< endl;
}
}
void StdoutLogger::HostDestroyed(time_t tmTime){
PrintTime(Out, tmTime);
Out << " Host is destroyed." << std::endl;
}
void StdoutLogger::FishBorn(int iId){
Out << "...Fish " << iId << " is born at (" << host.getX(iId) << ", " << host.getY(iId) <<")." << std::endl;
}
void StdoutLogger::FoodRefreshed(const int* ipPosX, const int* ipPosY){
Out << "...Food is refreshed." << std::endl;
#ifdef _DEBUG_VER_
Out << "......<Position List>" << std::endl;
for (int i = 0; i<MAX_FOOD; ++i)
Out << "......(" << ipPosX[i] << ", " << ipPosY[i] << ")" << std::endl;
#endif
}
void StdoutLogger::FishInitializing(int iId){
Out << "...Fish " << iId << " is being initialized." << std::endl;
}
void StdoutLogger::RoundStarted(int iRoundCount){
Out << "...Round " << iRoundCount << std::endl;
}
void StdoutLogger::FishRevived(int iId){
Out << "...Fish " << iId << " is revived at (" << host.getX(iId) << ", " << host.getY(iId) << ")." << std::endl;
}
void StdoutLogger::SequenceDecided(const int* iId){
Out << "...Sequence is decided." << std::endl;
#ifdef _DEBUG_VER_
Out << "......<Sequence>" << std::endl;
for (int i = 0, tar = host.getPlayerCount(); i<tar; ++i)
Out << "......Fish " << iId[i] << std::endl;
#endif
}
void StdoutLogger::FishInAction(int iId){
Out << "......Fish " << iId << " is now in action." << std::endl;
#ifdef _DEBUG_VER_
Out << ".........<Fish Properties>" << std::endl;
Out << ".........Remaining property points: " << host.getPropertyPoint(iId) << std::endl;
Out << ".........Points: " << host.getPoint(iId) << std::endl;
Out << ".........Level: " << host.getLevel(iId) << std::endl;
Out << ".........Experience: " << host.getExp(iId) << std::endl;
Out << ".........X-coordinate: " << host.getX(iId) << std::endl;
Out << ".........Y-coordinate: " << host.getY(iId) << std::endl;
Out << ".........HP: " << host.getHP(iId) << std::endl;
Out << ".........MaxHP:" << host.getMaxHP(iId) << std::endl;
Out << ".........Attack: " << host.getAtt(iId) << std::endl;
Out << ".........Speed: " << host.getSp(iId) << std::endl;
#endif
}
void StdoutLogger::FishMove(int iId, int iFormerPosX, int iFormerPosY, int iTargetPosX, int iTargetPosY, int iResult){
Out << ".........Fish " << iId << " attempts to move from (" << iFormerPosX << ", "
<< iFormerPosY << ") to (" << iTargetPosX << ", " << iTargetPosY << "). "
<< pstrResultString[iResult] << std::endl;
}
void StdoutLogger::FishAttack(int iId, int iTargetPosX, int iTargetPosY, int iTarget, int iResult){
Out << ".........Fish(att= " << host.getAtt(iId) << ") " << iId << " attempts to attack ";
switch (iTarget){
case FOOD:
Out << "food";
break;
case EMPTY:
Out << "null";
break;
default:
Out << "fish " << iTarget;
}
Out <<" at (" << iTargetPosX << ", " << iTargetPosY << "). " << pstrResultString[iResult] << std::endl;
}
void StdoutLogger::FishDead(int iId){
Out << ".........Fish " << iId << " is dead" << std::endl;
}
void StdoutLogger::FishExpIncreased(int iId){
#ifdef _DEBUG_VER_
Out << ".........Fish " << iId << "'s exp is increased to "<< host.getExp(iId) << std::endl;
#endif
}
void StdoutLogger::FishLevelUp(int iId){
Out << ".........Fish " << iId << " is upgraded to Lv. " << host.getLevel(iId) << std::endl;
}
void StdoutLogger::FishHPModified(int iId){
Out << ".........Fish " << iId << "'s HP is now " << host.getHP(iId) << std::endl;
}
void StdoutLogger::FishActionFinished(int iId){
Out << "......Fish " << iId << " quits action normally." << std::endl;
}
void StdoutLogger::FishTimeout(int iId, int iTimeUsage){
Out << "......Fish " << iId << " exceeds time limit. Time usage: " << iTimeUsage << "ms." << std::endl;
}
void StdoutLogger::FishHealthIncreased(int iId){
}
void StdoutLogger::FishSpeedIncreased(int iId){
}
void StdoutLogger::FishStrengthIncreased(int iId){
}