162 lines
3.6 KiB
C++
162 lines
3.6 KiB
C++
//
|
|
// Created by onnig on 18/11/2021.
|
|
//
|
|
|
|
#include "W000.h"
|
|
#include <cmath>
|
|
|
|
//const int n = 10;
|
|
|
|
W000::W000() {
|
|
Compteur::ajouterConstructeur();
|
|
nom = "w000";
|
|
direction = 0;
|
|
force = 5;
|
|
vitesse =4;
|
|
vision =4;
|
|
|
|
}
|
|
|
|
W000::~W000() {
|
|
Compteur::ajouterDestructeur();
|
|
}
|
|
|
|
W000::W000(const W000 &w000) {
|
|
Compteur::ajouterConstructeurCopie();
|
|
nom = w000.nom;
|
|
direction = w000.direction;
|
|
force = w000.force;
|
|
vitesse = w000.vitesse;
|
|
vision = w000.vision;
|
|
}
|
|
|
|
const string &W000::getNom() const {
|
|
return nom;
|
|
}
|
|
|
|
void W000::setNom(const string &nom) {
|
|
W000::nom = nom;
|
|
}
|
|
|
|
int W000::getDirection() const {
|
|
return direction;
|
|
}
|
|
|
|
void W000::setDirection(int direction) {
|
|
if (direction < 0){direction=0;}
|
|
else if (direction > 3){direction=3;}
|
|
else {W000::direction = direction;}
|
|
}
|
|
|
|
int W000::getForce() const {
|
|
return force;
|
|
}
|
|
|
|
void W000::setForce(int force) {
|
|
W000::force = force;
|
|
}
|
|
|
|
int W000::getVitesse() const {
|
|
return vitesse;
|
|
}
|
|
|
|
void W000::setVitesse(int vitesse) {
|
|
W000::vitesse = vitesse;
|
|
}
|
|
|
|
int W000::getVision() const {
|
|
return vision;
|
|
}
|
|
|
|
void W000::setVision(int vision) {
|
|
W000::vision = vision;
|
|
}
|
|
|
|
void W000::bouger(int &x, int &y) {
|
|
|
|
switch (direction) {
|
|
case 0: //avance
|
|
if (x-vitesse-2 >=0){x=x-vitesse-2;}
|
|
else {x=0; cout<<"Impossible d'aller plus loin"<<endl;}
|
|
break;
|
|
|
|
case 1: //droite
|
|
if (y+vitesse+2 <= n){y = y+vitesse+2;}
|
|
else {y=n; cout<<"Impossible d'aller plus loin"<<endl;}
|
|
break;
|
|
|
|
case 2: //reculer
|
|
if (x+vitesse+2 <= n){x = x+vitesse+2;}
|
|
else {x=n; cout<<"Impossible d'aller plus loin"<<endl;}
|
|
break;
|
|
|
|
case 3: //gauche
|
|
if (y-vitesse-2 >= 0){y = y-vitesse-2;}
|
|
else {y=0; cout<<"Impossible d'aller plus loin"<<endl;}
|
|
break;
|
|
}
|
|
}
|
|
|
|
void W000::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);
|
|
|
|
//tourner dans la bonne direction
|
|
|
|
int dist_x = x - pt_x;
|
|
int dist_y = y - pt_y;
|
|
|
|
if (dist_x > dist_y){
|
|
if (dist_x > 0)
|
|
setDirection(0);
|
|
else
|
|
setDirection(2);
|
|
}
|
|
else{
|
|
if (dist_y > 0)
|
|
setDirection(1);
|
|
else
|
|
setDirection(3);
|
|
}
|
|
|
|
// déplacement
|
|
|
|
switch (direction) {
|
|
case 0: //avance
|
|
if (x-vitesse-2 >=0){x=x-vitesse-2;}
|
|
else {x=0; cout<<"Impossible d'aller plus loin"<<endl;}
|
|
break;
|
|
|
|
case 1: //droite
|
|
if (y+vitesse+2 <= n){y = y+vitesse+2;}
|
|
else {y=n; cout<<"Impossible d'aller plus loin"<<endl;}
|
|
break;
|
|
|
|
case 2: //reculer
|
|
if (x+vitesse+2 <= n){x = x+vitesse+2;}
|
|
else {x=n; cout<<"Impossible d'aller plus loin"<<endl;}
|
|
break;
|
|
|
|
case 3: //gauche
|
|
if (y-vitesse-2 >= 0){y = y-vitesse-2;}
|
|
else {y=0; cout<<"Impossible d'aller plus loin"<<endl;}
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
W000::W000(string nom) {
|
|
Compteur::ajouterConstructeur();
|
|
W000::nom = nom;
|
|
direction = 0;
|
|
force = 5;
|
|
vitesse = 4;
|
|
vision = 4;
|
|
|
|
}
|
|
|
|
W000::W000(string nom, int direction, int force, int vitesse, int vision) : nom(nom), direction(direction),
|
|
force(force), vitesse(vitesse),
|
|
vision(vision) {Compteur::ajouterConstructeur();}
|
|
|