-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
105 lines (90 loc) · 2.77 KB
/
main.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
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
#include "mainwindow.h"
#include <QApplication>
#include <QtDebug>
#include <QFile>
#include <QTextStream>
#include <QTranslator>
#include <QTime>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <QTime>
#include <QObject>
#include <QDesktopWidget>
#include <QStyle>
#include <network/server.h>
#include <network/client.h>
#include <gui/playground.h>
#include <settings.h>
#include "gameLogic/humanplayer.h"
#ifdef TEST
#include "gameLogic/Test/gamecontroller_test.h"
#include "gameLogic/Test/decktest.h"
#include "gameLogic/Test/aiplayer_test.h"
#endif
MauClient* client;
void customMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message)
{
(void)(context);
QString txt;
QTime time;
std::cout << message.toStdString() << std::endl;
switch (type) {
case QtDebugMsg:
txt = QString("Debug - %1: %2").arg(time.currentTime().toString()).arg(message);
break;
case QtWarningMsg:
txt = QString("Warning - %1: %2").arg(time.currentTime().toString()).arg(message);
break;
case QtCriticalMsg:
txt = QString("Critical - %1: %2").arg(time.currentTime().toString()).arg(message);
break;
case QtFatalMsg:
txt = QString("Fatal - %1: %2").arg(time.currentTime().toString()).arg(message);
abort();
}
QFile outFile("maumau-log.txt");
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream ts(&outFile);
ts << txt << endl;
}
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
//set seed for rand()
std::time_t t;
time(&t);
srand((unsigned int)t);
if (QFile::exists("maumau-log.txt")) {
QFile::remove("maumau-log.txt");
}
//This should be changeable in the option menu
QTranslator translator;
translator.load(Settings::getInstance()->getProperty("common/language"));
app.installTranslator(&translator);
//Lets register our custom debug handler, before we start
qInstallMessageHandler(customMessageHandler);
MainWindow window;
//Center window
//QDesktopWidget *s = QApplication::desktop();
window.setGeometry(
QStyle::alignedRect(
Qt::LeftToRight,
Qt::AlignCenter,
QSize(Settings::getInstance()->getProperty("common/width").toInt(), Settings::getInstance()->getProperty("common/height").toInt()),
app.desktop()->availableGeometry()));
window.show();
#ifdef TEST
//TODO TEST
GameControllerTest* gcTest = new GameControllerTest();
QTest::qExec(gcTest);
// delete gcTest;
DeckTest* deckTest = new DeckTest();
QTest::qExec(deckTest);
// delete deckTest;
AIPlayer_test* aiP_test = new AIPlayer_test();
QTest::qExec(aiP_test);
// delete aiP_test;
#endif
return app.exec();
}