164 lines
3.6 KiB
C++
164 lines
3.6 KiB
C++
//
|
|
// Created by onnig on 18/11/2021.
|
|
//
|
|
|
|
#include "G990.h"
|
|
|
|
//const int n = 10;
|
|
|
|
G990::G990() {
|
|
Compteur::ajouterConstructeur();
|
|
nord = true;
|
|
est = false;
|
|
energiePhysique = 20;
|
|
energieMaximale = 10;
|
|
vision = 4;
|
|
|
|
}
|
|
|
|
G990::~G990() {Compteur::ajouterDestructeur();}
|
|
|
|
G990::G990(const G990 &g990) {
|
|
Compteur::ajouterConstructeurCopie();
|
|
nord = g990.nord;
|
|
est = g990.est;
|
|
energiePhysique = g990.energiePhysique;
|
|
energieMaximale = g990.energieMaximale;
|
|
vision = g990.vision;
|
|
|
|
}
|
|
|
|
bool G990::getNord() const {
|
|
return nord;
|
|
}
|
|
|
|
void G990::setNord(bool nord) {
|
|
G990::nord = nord;
|
|
}
|
|
|
|
bool G990::getEst() const {
|
|
return est;
|
|
}
|
|
|
|
void G990::setEst(bool est) {
|
|
G990::est = est;
|
|
}
|
|
|
|
long G990::getEnergiePhysique() const {
|
|
return energiePhysique;
|
|
}
|
|
|
|
void G990::setEnergiePhysique(long energiePhysique) {
|
|
G990::energiePhysique = energiePhysique;
|
|
}
|
|
|
|
long G990::getEnergieMaximale() const {
|
|
return energieMaximale;
|
|
}
|
|
|
|
void G990::setEnergieMaximale(long energieMaximale) {
|
|
G990::energieMaximale = energieMaximale;
|
|
}
|
|
|
|
long G990::getVision() const {
|
|
return vision;
|
|
}
|
|
|
|
void G990::setVision(long vision) {
|
|
G990::vision = vision;
|
|
}
|
|
|
|
void G990::regarderNord() {
|
|
nord = true;
|
|
}
|
|
|
|
void G990::regarderSud() {
|
|
nord = false;
|
|
}
|
|
|
|
void G990::regarderEst() {
|
|
est = true;
|
|
}
|
|
|
|
void G990::regarderOuest() {
|
|
est = false;
|
|
}
|
|
|
|
void G990::deplacementNordSud(int valeur, int &x, int &y){
|
|
if (valeur <= energieMaximale){
|
|
if(nord){
|
|
if (x - valeur > 0)
|
|
x -= valeur;
|
|
} else {
|
|
if (x + valeur < n)
|
|
x += valeur;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void G990::deplacementEstOuest(int valeur, int &x, int &y) {
|
|
if (valeur <= energieMaximale){
|
|
if (est){
|
|
if (y - valeur > 0)
|
|
y -= valeur;
|
|
} else {
|
|
if (y + valeur < n)
|
|
y += valeur;
|
|
}
|
|
}
|
|
}
|
|
|
|
G990::G990(bool nord, bool est, long energiePhysique, long energieMaximale, long vision) : nord(nord), est(est),
|
|
energiePhysique(
|
|
energiePhysique),
|
|
energieMaximale(
|
|
energieMaximale),
|
|
vision(vision) {Compteur::ajouterConstructeur();}
|
|
|
|
|
|
void G990::bloquer(int xAmi, int yAmi, int &x, int &y, int xEnnemi, int yEnnemi) {
|
|
//définir les points
|
|
int pt_x = round((xAmi + xEnnemi)/2);
|
|
int pt_y = round((yAmi + yEnnemi)/2);
|
|
|
|
//cout << "pt_x :" << pt_x << " pt_y : " << pt_y << endl;
|
|
|
|
//tourner dans la bonne direction et se déplacer
|
|
|
|
int dist_x = x - pt_x; //calcul de la distance
|
|
if (dist_x > 0)
|
|
nord = true;
|
|
else
|
|
nord = false;
|
|
|
|
int dist_y = y - pt_y;
|
|
if (dist_y > 0)
|
|
est = true;
|
|
else
|
|
est = false;
|
|
cout << "DEBUG : Bloquer : " << " dist_x " << dist_x << " dist_y " << dist_y << endl;
|
|
|
|
deplacementNordSud(abs(dist_x),x,y);
|
|
deplacementEstOuest(abs(dist_y),x,y);
|
|
|
|
}
|
|
|
|
/*
|
|
int dist_x = x - pt_x; //calcul de la distance
|
|
int dist_y = y - pt_y;
|
|
|
|
if (dist_x > dist_y){
|
|
if (dist_x > 0)
|
|
nord = true;
|
|
else
|
|
nord = false;
|
|
deplacementNordSud(dist_x,x,y);
|
|
}
|
|
else{
|
|
if (dist_y > 0)
|
|
est = true;
|
|
else
|
|
est = false;
|
|
deplacementEstOuest(dist_y,x,y);
|
|
}*/
|