-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatamanager.cpp
More file actions
60 lines (32 loc) · 1.26 KB
/
datamanager.cpp
File metadata and controls
60 lines (32 loc) · 1.26 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
#include "datamanager.h"
#include <QFile>
#include <QRegExp>
void DataManager::loadLevelData(QString fileToLoad){
QFile file(fileToLoad);
if(!file.open(QIODevice::ReadOnly)){
std::cerr << "fail to open file :" << fileToLoad.toStdString() << std::endl;
exit(1);
}
QString stringFile(file.readAll());
QRegExp flyRegExp("fly,(\\d+),(\\d+)");
stringFile.contains(flyRegExp);
initPos.first = flyRegExp.cap(1).toInt();
initPos.second = flyRegExp.cap(2).toInt();
QRegExp bestTimeRegExp("Best time,(\\d+):(\\d+):(\\d+)");
stringFile.contains(bestTimeRegExp);
bestTime = bestTimeRegExp.cap(1).toInt()*60000 + bestTimeRegExp.cap(2).toInt()*1000+bestTimeRegExp.cap(3).toInt();
//TODO : cacaLoader
file.close();
}
void DataManager::saveHighScore(QString fileToLoad,QString score){
QFile file(fileToLoad);
if(!file.open(QIODevice::WriteOnly)){
std::cerr << "fail to open file :" << fileToLoad.toStdString() << std::endl;
exit(1);
}
QString flypos("fly," +QString::number(initPos.first) + "," + QString::number(initPos.second) + "\n");
QString string("Best time," + score +"\n");
file.write(flypos.toAscii());
file.write(string.toAscii());
file.close();
}