109 lines
2.4 KiB
C++
109 lines
2.4 KiB
C++
//
|
|
// Created by onnig on 18/11/2021.
|
|
//
|
|
|
|
#include "R234.h"
|
|
|
|
R234::R234() {
|
|
Compteur::ajouterConstructeur();
|
|
direction = 0;
|
|
speed = 4;
|
|
range = 4;
|
|
strength = 5;
|
|
}
|
|
|
|
R234::~R234() {Compteur::ajouterDestructeur();}
|
|
|
|
R234::R234(const R234 &r234) {
|
|
Compteur::ajouterConstructeurCopie();
|
|
speed = r234.speed;
|
|
strength = r234.strength;
|
|
direction = r234.direction;
|
|
range = r234.range;
|
|
|
|
}
|
|
|
|
int R234::getDirection() const {
|
|
return direction;
|
|
}
|
|
|
|
|
|
|
|
void R234::setDirection(int direction) {
|
|
if (direction < 0){direction=0;}
|
|
else if (direction > 3){direction=3;}
|
|
else {R234::direction = direction;}
|
|
}
|
|
|
|
int R234::getStrength() const {
|
|
return strength;
|
|
}
|
|
|
|
void R234::setStrength(int strength) {
|
|
R234::strength = strength;
|
|
}
|
|
|
|
int R234::getSpeed() const {
|
|
return speed;
|
|
}
|
|
|
|
void R234::setSpeed(int speed) {
|
|
R234::speed = speed;
|
|
}
|
|
|
|
int R234::getRange() const {
|
|
return range;
|
|
}
|
|
|
|
void R234::setRange(int range) {
|
|
R234::range = range;
|
|
}
|
|
|
|
int R234::doAttack(int defenceEnemy) {
|
|
if (strength-defenceEnemy < 0){return 0;}
|
|
else {return strength-defenceEnemy;}
|
|
}
|
|
|
|
int R234::doProtect(int attackEnemy) {
|
|
if (attackEnemy - (speed + strength)/2 < 0) {return 0;}
|
|
else return attackEnemy - (speed + strength)/2;
|
|
}
|
|
|
|
void R234::doMove(int &x, int &y) {
|
|
int n = 9; //à delete taille arene
|
|
switch (direction) {
|
|
case 0: //avance
|
|
if (x-speed >=0){x=x-speed;}
|
|
else {x=0; cout<<"Impossible d'aller plus loin"<<endl;}
|
|
break;
|
|
|
|
case 1: //droite
|
|
if (y+speed <= n){y = y+speed;}
|
|
else {y=n; cout<<"Impossible d'aller plus loin"<<endl;}
|
|
break;
|
|
|
|
case 2: //reculer
|
|
if (x+speed <= n){x = x+speed;}
|
|
else {x=n; cout<<"Impossible d'aller plus loin"<<endl;}
|
|
break;
|
|
|
|
case 3: //gauche
|
|
if (y-speed >= 0){y = y-speed;}
|
|
else {y=0; cout<<"Impossible d'aller plus loin"<<endl;}
|
|
break;
|
|
}
|
|
}
|
|
|
|
R234::R234(int direction, int strength, int speed, int range) : direction(direction), strength(strength), speed(speed),
|
|
range(range) {Compteur::ajouterConstructeur();}
|
|
|
|
void R234::doRotateLeft() {
|
|
int rotat[4] = {3,0,1,2};
|
|
direction = rotat[direction];
|
|
}
|
|
|
|
void R234::doRotateRight() {
|
|
int rotat[4] = {1, 2, 3, 0};
|
|
direction = rotat[direction];
|
|
|
|
}
|