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

224 lines
6.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// Created by onnig on 18/11/2021.
//
#include "X212.h"
//const int n = 10;
X212::X212() {Compteur::ajouterConstructeur();
nom = "x212";
direction = 0;
force = 5;
vision = 4;
vitesse = 4;
}
X212::~X212() {Compteur::ajouterDestructeur();}
//X212(nom, direction, force, vitesse, vision)
X212::X212(const X212 &x212) {
Compteur::ajouterConstructeurCopie();
nom = x212.nom;
vitesse = x212.vitesse;
direction = x212.direction;
force = x212.force;
vision = x212.vision;
}
const string &X212::getNom() const {
return nom;
}
void X212::setNom(const string &nom) {
X212::nom = nom;
}
int X212::getDirection() const {
return direction;
}
void X212::setDirection(int direction) {
if (direction < 0){direction=0;}
else if (direction > 3){direction=3;}
else {X212::direction = direction;}
}
int X212::getForce() const {
return force;
}
void X212::setForce(int force) {
X212::force = force;
}
int X212::getVitesse() const {
return vitesse;
}
void X212::setVitesse(int vitesse) {
X212::vitesse = vitesse;
}
int X212::getVision() const {
return vision;
}
void X212::setVision(int vision) {
X212::vision = vision;
}
int X212::bloquer() {
return vitesse/3 + force;
}
/* 0
* ^
* |
* |
* 3<------|------>1
* |
* |
*
* 2
* */
void X212::mouvement(int &x, int &y) {
switch (direction) {
case 0: //avance
if (x-vitesse-1 >=0){x=x-vitesse-1;}
else {x=0; cout<<"Impossible d'aller plus loin"<<endl;}
break;
case 1: //droite
if (y+vitesse+1 <= n){y = y+vitesse+1;}
else {y=n; cout<<"Impossible d'aller plus loin"<<endl;}
break;
case 2: //reculer
if (x+vitesse+1 <= n){x = x+vitesse+1;}
else {x=n; cout<<"Impossible d'aller plus loin"<<endl;}
break;
case 3: //gauche
if (y-vitesse-1 >= 0){y = y-vitesse-1;}
else {y=0; cout<<"Impossible d'aller plus loin"<<endl;}
break;
}
}
void X212::superCourse(int &x, int &y) {
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;
}
}
/*
void X212::esquive(int &x, int &y, int xDanger, int yDanger) {
//X212 tente déviter un obstacle. Au besoin, il peut réaliser 2 actions: changer de direction et
// bouger à la moitié de sa vitesse.Inventer une règle simple qui lui permettra dêtre à au moins 3 points du danger.
// Sil en est incapable, il ne bouge pas!
if (x == xDanger + 3) { // Danger a l'avant //
if (y != yDanger - 3) {//SI PAS DE DANGER A DROITE
y = y + (vitesse / 2) + 1; // ALLER A DROITE
} else if (y != yDanger + 3) { //SI DANGER A DROITE ET PAS DANGER A GAUCHE
y = y - (vitesse / 2) - 1; //ALLER A GAUCHE
}
//sinon ne rien faire else {break;}
} else if (y == yDanger - 3) { //DANGER A DROITE
if (y != yDanger + 3) { //SI DANGER A DROITE ET PAS DANGER A GAUCHE
y = y - (vitesse / 2) - 1; //ALLER A GAUCHE
}
} else if (y == yDanger + 3) { //DANGER A GAUCHE
if (y != yDanger + 3) { //SI DANGER A GAUCHE ET PAS DANGER A DROITE
y = y - (vitesse / 2) - 1; //ALLER A GAUCHE
}
}
//else { break; }//sinon ne rien faire
}
*/
void X212::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 X212::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);
}
}
}
X212::X212(string nom) {
Compteur ::ajouterConstructeur();
X212::nom = nom;
direction = 0;
force = 5;
vision = 4;
vitesse = 4;
}
X212::X212(string nom, int direction, int force, int vitesse, int vision) : nom(nom), direction(direction),
force(force), vitesse(vitesse),
vision(vision) {Compteur::ajouterConstructeur();}