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
| #include "tribaltime.h"
#include "ui_tribaltime.h"
#include "configMonde.h"
#include <QtGui>
#include <sstream>
#include <fstream>
#include <string>
#include <iostream>
TribalTime::TribalTime(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::TribalTime)
{
ui->setupUi(this);
QStatusBar *barreEtat = statusBar();
monde = 16;
vitesseMonde = 1;
vitesseUnite = 1;
connect(ui->actionQuitter, SIGNAL(triggered()), qApp, SLOT(quit()));
ui->actionQuitter->setShortcut(tr("Ctrl+Q"));
QString qstr = QString::fromStdString("Monde " + getMonde());
QLabel *mondeActuel = new QLabel(qstr);
barreEtat->addWidget(mondeActuel);
connect(ui->actionA_propos_de_TribalTime, SIGNAL(triggered()), this, SLOT(aPropos()));
connect(ui->actionAjouterMonde, SIGNAL(clicked()), this, SLOT(ajouterMonde()));
connect(ui->actionCalculerTemps, SIGNAL(clicked()), this, SLOT(changerTemps()));
}
std::string TribalTime::getMonde() const
{
std::ostringstream flux;
flux << this->monde;
return flux.str();
}
void TribalTime::setMonde(int m_monde)
{
this->monde = m_monde;
}
void TribalTime::aPropos()
{
QMessageBox::information(this, tr("A propos de TribalTime"), tr("Inspiré de TribalSync."));
}
void TribalTime::ajouterMonde()
{
std::ofstream fichierMondes("C:/Users/Simon/Desktop/tribaltime/tribaltime/data/mondes.txt");
if(fichierMondes)
{
ConfigMonde config();
fichierMondes << config;
QMessageBox::information(this, tr("Monde ajouté"), tr("Le monde a été correctement ajouté."));
}
else
{
QMessageBox::critical(this, tr("Erreur"), tr("Erreur lors de l'ouverture du fichier des mondes."));
}
}
float TribalTime::calculCases(int x1, int y1, int x2, int y2)
{
//Erreur d'une seconde pour certaines destinations
int differenceX = abs(x1-x2);
int differenceY = abs(y1-y2);
float hypothenuse = (differenceX*differenceX) + (differenceY*differenceY);
hypothenuse = sqrt(hypothenuse);
return hypothenuse;
}
void TribalTime::changerTemps()
{
int xCible = ui->xVillageCible->text().toInt();
int yCible = ui->yVillageCible->text().toInt();
int xPersonnel = ui->xVillagePersonnel->text().toInt();
int yPersonnel = ui->yVillagePersonnel->text().toInt();
int delais = ui->delais->text().toInt();
float nbCases = this->calculCases(xCible,yCible,xPersonnel,yPersonnel);
std::map<int, int> tempsUnites; //temps par unité en secondes
tempsUnites[0] = 35; //noble
tempsUnites[1] = 18; //lancier
tempsUnites[2] = 22; //épée
tempsUnites[3] = 18; //hache
tempsUnites[4] = 18; //archer
tempsUnites[5] = 9; //éclaireur
tempsUnites[6] = 10; //cavalierie légère
tempsUnites[7] = 10; //archer monté
tempsUnites[8] = 11; //cavalerie lourde
tempsUnites[9] = 30; //bélier
tempsUnites[10] = 30; //catapulte
tempsUnites[11] = 10; //paladin
QDateTime heure1 = ui->dateTimeEdit->dateTime();
QDateTime heure1Plus10 = heure1.addSecs((60*tempsUnites[ui->selectionUniteLente->currentIndex()]*nbCases)-delais);
ui->dateTimeEdit->setDateTime(heure1Plus10);
}
TribalTime::~TribalTime()
{
delete ui;
} |
Partager