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

96 lines
2.1 KiB
C++

//
// Created by jser on 09/12/2021.
//
#include "X212Adapter.h"
X212Adapter::X212Adapter() {
Compteur::ajouterConstructeur();
x212 = new X212();
pdv =30;
}
X212Adapter::X212Adapter(const X212Adapter &x212adapter) {
Compteur::ajouterConstructeurCopie();
x212 = new X212(*x212adapter.x212);
pdv = x212adapter.pdv;
}
X212Adapter::~X212Adapter() {
Compteur::ajouterDestructeur();
delete(x212);
}
void X212Adapter::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) {
x212->esquive(x, y, xEnnemi, yEnnemi);}
while (x==xs && y==ys && nbm <=4){
srand(time(NULL));
int choix = rand()%2;
if (choix ==1){x212->mouvement(x, y);}
else {x212->superCourse(x,y);}
if (x==xs && y==ys){x212->setDirection(rand()%4);}
nbm++;
}
int deg = rand()%5;
pdv = pdv-deg;
}
}
int X212Adapter::calculerDistance(int x, int y, int xEnnemi, int yEnnemi) {
return sqrt((xEnnemi-x)^2 + (yEnnemi-y)^2);
}
int X212Adapter::attaquer(int x, int y, int xEnnemi, int yEnnemi) {
//truc du prof, à adapter ?
if (!estFonctionnel())
return 0;
else {
if(x212->getVision() > calculerDistance(x,y,xEnnemi,yEnnemi))
return x212->bloquer();
return 0;
}
}
void X212Adapter::defendre(int degat) {
int a =0;
a = 1;
}
bool X212Adapter::estFonctionnel() {
return pdv>0;
}
string X212Adapter::toStringg() {
string robot;
robot = "nom : " + x212->getNom() +" " + " direction : " + to_string(x212->getDirection()) + " " + "force : " +
to_string(x212->getForce()) + " " + "vitesse : " + to_string(x212->getVitesse()) +" "+ "vision : "+
to_string(x212->getVision());
return robot;
}
X212Adapter::X212Adapter(X212* x212) {
Compteur::ajouterConstructeur();
this->x212=x212;
pdv = 30;
}
int X212Adapter::getPdv() const {
return pdv;
}
void X212Adapter::setPdv(int pdv) {
X212Adapter::pdv = pdv;
}