214 lines
5.4 KiB
C++
214 lines
5.4 KiB
C++
//
|
|
// Created by onnig on 18/11/2021.
|
|
//
|
|
|
|
#include "X215.h"
|
|
|
|
//const int n = 10;
|
|
|
|
X215::X215() {
|
|
Compteur::ajouterConstructeur();
|
|
nom = "x215";
|
|
direction = 0;
|
|
force = 5;
|
|
vision = 4;
|
|
vitesse = 4;
|
|
rageCombat = false;
|
|
|
|
}
|
|
|
|
X215::~X215() {Compteur::ajouterDestructeur();}
|
|
|
|
X215::X215(const X215 &x215) {
|
|
Compteur::ajouterConstructeurCopie();
|
|
nom = x215.nom;
|
|
vitesse = x215.vitesse;
|
|
direction = x215.direction;
|
|
force = x215.force;
|
|
vision = x215.vision;
|
|
rageCombat = x215.rageCombat;
|
|
}
|
|
|
|
const string &X215::getNom() const {
|
|
return nom;
|
|
}
|
|
|
|
void X215::setNom(const string &nom) {
|
|
X215::nom = nom;
|
|
}
|
|
|
|
int X215::getDirection() const {
|
|
return direction;
|
|
}
|
|
|
|
void X215::setDirection(int direction) {
|
|
if (direction < 0){direction=0;}
|
|
else if (direction > 3){direction=3;}
|
|
else {X215::direction = direction;}
|
|
}
|
|
|
|
int X215::getForce() const {
|
|
return force;
|
|
}
|
|
|
|
void X215::setForce(int force) {
|
|
X215::force = force;
|
|
}
|
|
|
|
int X215::getVitesse() const {
|
|
return vitesse;
|
|
}
|
|
|
|
void X215::setVitesse(int vitesse) {
|
|
X215::vitesse = vitesse;
|
|
}
|
|
|
|
int X215::getVision() const {
|
|
return vision;
|
|
}
|
|
|
|
void X215::setVision(int vision) {
|
|
X215::vision = vision;
|
|
}
|
|
|
|
bool X215::isRageCombat() const {
|
|
return rageCombat;
|
|
}
|
|
|
|
void X215::setRageCombat(bool rageCombat) {
|
|
X215::rageCombat = rageCombat;
|
|
}
|
|
|
|
int X215::bloquer() {
|
|
if (rageCombat){return force * 3;}
|
|
else {return vitesse/3 + force;}
|
|
}
|
|
|
|
void X215::tournerLesTalons() {
|
|
if (direction == 0){direction=2;}
|
|
else if (direction == 1){direction=3;}
|
|
else if (direction == 2){direction=0;}
|
|
else if (direction == 3){direction=1;}
|
|
}
|
|
|
|
void X215::exploserRage() {
|
|
rageCombat=true;
|
|
}
|
|
|
|
void X215::controlerRage() {
|
|
rageCombat=false;
|
|
}
|
|
|
|
void X215::mouvement(int &x, int &y) {
|
|
switch (direction) {
|
|
case 0: //avance
|
|
if (x-vitesse >=0){x=x-vitesse;}
|
|
else {x=0; cout<<"Impossible d'aller plus loin"<<endl;}
|
|
break;
|
|
|
|
case 1: //droite
|
|
if (y+vitesse <= n){y = y+vitesse;}
|
|
else {y=n; cout<<"Impossible d'aller plus loin"<<endl;}
|
|
break;
|
|
|
|
case 2: //reculer
|
|
if (x+vitesse <= n){x = x+vitesse;}
|
|
else {x=n; cout<<"Impossible d'aller plus loin"<<endl;}
|
|
break;
|
|
|
|
case 3: //gauche
|
|
if (y-vitesse >= 0){y = y-vitesse;}
|
|
else {y=0; cout<<"Impossible d'aller plus loin"<<endl;}
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
void X215::mouvesquive(int &x, int &y) {
|
|
switch (direction) {
|
|
case 0: //avance
|
|
if (x - 3 >= 0){x = x - 3;}
|
|
else {x=0; cout<<"Impossible d'aller plus loin"<<endl;}
|
|
break;
|
|
|
|
case 1: //droite
|
|
if (y + 3 <= n){y = y + 3;}
|
|
else {y=n; cout<<"Impossible d'aller plus loin"<<endl;}
|
|
break;
|
|
|
|
case 2: //reculer
|
|
if (x + 3 <= n){x = x + 3;}
|
|
else {x=n; cout<<"Impossible d'aller plus loin"<<endl;}
|
|
break;
|
|
|
|
case 3: //gauche
|
|
if (y - 3 >= 0){y = y - 3;}
|
|
else {y=0; cout<<"Impossible d'aller plus loin"<<endl;}
|
|
break;
|
|
}
|
|
}
|
|
|
|
void X215::esquive(int &x, int &y, int xDanger, int yDanger) { //enlever supercourse au pire
|
|
if ((y == yDanger) && ((abs(x-xDanger)<= 3))){ // danger devant ou derrière
|
|
if (x-xDanger > 0) {// danger devant, à faire : changer de direction pour pas qu'il rushe comme un con
|
|
direction = 2;
|
|
mouvesquive(x,y);
|
|
} else { //danger derrière
|
|
direction = 2;
|
|
mouvesquive(x,y);
|
|
}
|
|
} if ((x == xDanger) && ((abs(y-yDanger) <= 3))){
|
|
if (y-yDanger > 0){ //danger à droite
|
|
direction = 1;
|
|
mouvesquive(x,y);
|
|
}
|
|
else {
|
|
direction = 3;
|
|
mouvesquive(x,y);
|
|
}
|
|
}
|
|
}
|
|
|
|
X215::X215(string nom) {
|
|
Compteur::ajouterConstructeur();
|
|
X215::nom = nom;
|
|
direction = 0;
|
|
force = 5;
|
|
vision = 4;
|
|
vitesse = 4;
|
|
rageCombat = false;
|
|
|
|
}
|
|
|
|
X215::X215(string nom, int direction, int force, int vitesse, int vision) : nom(nom), direction(direction),
|
|
force(force), vitesse(vitesse),
|
|
vision(vision), rageCombat(false) {Compteur::ajouterConstructeur();}
|
|
|
|
void X215::superCourse(int &x, int &y) {
|
|
|
|
if (rageCombat){
|
|
switch (direction) {
|
|
case 0: //avance
|
|
if (x - (vitesse + (vitesse * force / 10)) >= 0) { x = x - (vitesse + (vitesse * force / 10)); }
|
|
else {x = 0; cout << "Impossible d'aller plus loin" << endl;}
|
|
break;
|
|
|
|
case 1: //droite
|
|
if (y + (vitesse + (vitesse * force / 10)) <= n) { y = y + (vitesse + (vitesse * force / 10)); }
|
|
else {y = n; cout << "Impossible d'aller plus loin" << endl;}
|
|
break;
|
|
|
|
case 2: //reculer
|
|
if (x + (vitesse + (vitesse * force / 10)) <= n) { x = x + (vitesse + (vitesse * force / 10)); }
|
|
else {x = n; cout << "Impossible d'aller plus loin" << endl;}
|
|
break;
|
|
|
|
case 3: //gauche
|
|
if (y - (vitesse + (vitesse * force / 10)) >= 0) { y = y - (vitesse + (vitesse * force / 10)); }
|
|
else {y = 0; cout << "Impossible d'aller plus loin" << endl;}
|
|
break;
|
|
}
|
|
}
|
|
else {X215::mouvement(x, y);}
|
|
|
|
}
|