-
Notifications
You must be signed in to change notification settings - Fork 4
/
Replay.cpp
69 lines (52 loc) · 1.53 KB
/
Replay.cpp
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
#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include "common.h"
#include "Timer.h"
#include "Replay.h"
#include "Action.h"
#include "Field.h"
extern int gameState;
//extern Timer timer;
extern int squareSize;
Replay::Replay() {
recording=false;
}
void Replay::deleteData() {
data.clear();
}
void Replay::recordEvent(int x, int y, int button, long elapsedTime) {
if (recording) {
data.push_back(*(new Action(x,y,button,(gameState==GAME_INITIALIZED ? 0 : elapsedTime))));
// cout << "Elapsed time: " << elapsedTime << endl;
}
}
void Replay::writeToFile(ofstream *file, void* fieldPtr, Score *score) {
Field* field = (Field*)fieldPtr;
*file << "miny-replay-file-version: 2" << endl;
/* *file << field->playerName << endl << squareSize << endl;
*file << field->width << " " << field->height << endl;
*/
score->writeToFile(file);
for (int j=0;j<field->height;j++) {
for (int i=0;i<field->width;i++)
*file << field->isMine(i,j) << " ";
*file << endl;
}
*file << endl;
*file << data.size() << endl;
std::list<Action>::iterator iter;
for (iter=data.begin(); iter!=data.end(); iter++) {
*file << (*iter).timeSinceStart << " " << (*iter).x << " " << (*iter).y << " " << (*iter).button << endl;
}
}
void Replay::dump() {
cout << "Dumping replay data."<<endl;
std::list<Action>::iterator iter;
for (iter=data.begin(); iter!=data.end(); iter++) {
(*iter).dump();
}
}