Test/LAB3_BRULEZ_HUGUET_SERRE/X-BOTS/W000Adapter.cpp
2022-03-03 15:44:04 +01:00

89 lines
2 KiB
C++

//
// Created by jser on 09/12/2021.
//
#include "W000Adapter.h"
W000Adapter::~W000Adapter() {
Compteur::ajouterDestructeur();
delete(w000);
}
W000Adapter::W000Adapter() {
Compteur::ajouterConstructeur();
w000 = new W000();
}
W000Adapter::W000Adapter(const W000Adapter &w000adapter) {
Compteur::ajouterConstructeurCopie();
w000 = new W000(*w000adapter.w000);
}
void W000Adapter::bouger(int xAmi, int yAmi, int &x, int &y, int xEnnemi, int yEnnemi) {
int xs = x; //sauvegardes des coordonnées
int ys = y;
int nbm = 0;
if (!estFonctionnel()){}
else {
if (pdv > 10) {
w000->bloquer(xAmi, yAmi, x, y, xEnnemi, yEnnemi);}
while (x==xs && y==ys && nbm <=4){
srand(time(NULL));
w000->bouger(x, y);
if (x==xs && y==ys){w000->setDirection(rand()%4);}
nbm++;
}
}
}
int W000Adapter::attaquer(int x, int y, int xEnnemi, int yEnnemi) {
int xs = x; //sauvegardes des coordonnées
int ys = y;
int nbm = 0;
if (!estFonctionnel()){}
else {
while (x==xs && y==ys && nbm <=4){
srand(time(NULL));
w000->bouger(x, y);
if (x==xs && y==ys){w000->setDirection(rand()%4);}
nbm++;
}
int deg = rand()%5;
pdv = pdv-deg;
}
return 0;
}
void W000Adapter::defendre(int degat) {
int a = 0;
a = 1;
}
bool W000Adapter::estFonctionnel() {
return pdv>0;
}
string W000Adapter::toStringg() {
string robot;
robot = "nom : " + w000->getNom() +" " + " direction : " + to_string(w000->getDirection()) + " " + "force : " +
to_string(w000->getForce()) + " " + "vitesse : " + to_string(w000->getVitesse()) +" "+ "vision : "+
to_string(w000->getVision());
return robot;
}
W000Adapter::W000Adapter(W000 *w000) {
Compteur::ajouterConstructeur();
this->w000=w000;
pdv = 30;
}
int W000Adapter::getPdv() const {
return pdv;
}
void W000Adapter::setPdv(int pdv) {
W000Adapter::pdv = pdv;
}