59 lines
1.1 KiB
C++
59 lines
1.1 KiB
C++
//
|
|
// Created by Louis Gallet on 15/01/2025.
|
|
//
|
|
|
|
#include "R234.h"
|
|
|
|
#include <algorithm>
|
|
|
|
void R234::initialiser(int direction, int strength, int speed, int range) {
|
|
setDirection(direction);
|
|
setStrength(strength);
|
|
setSpeed(speed);
|
|
setRange(range);
|
|
}
|
|
|
|
int R234::doAttack(int defenceEnemy) const {
|
|
if ((this->strength - defenceEnemy) < 0) {
|
|
return 0;
|
|
}
|
|
return this->strength - defenceEnemy;
|
|
}
|
|
|
|
int R234::doProtect(int attackEnemy) const {
|
|
int toReturn = attackEnemy-(this->speed+this->strength)/2;
|
|
if (toReturn < 0) {
|
|
return 0;
|
|
}
|
|
return toReturn;
|
|
}
|
|
|
|
void R234::doMove(int &x, int &y) const {
|
|
switch (direction) {
|
|
case 0:
|
|
x -= speed;
|
|
break;
|
|
case 1:
|
|
y += speed;
|
|
break;
|
|
case 2:
|
|
x += speed;
|
|
break;
|
|
case 3:
|
|
y -= speed;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
x = std::max(std::min(x, 9), 0);
|
|
y = std::max(std::min(y, 9), 0);
|
|
}
|
|
|
|
void R234::doRotateLeft() {
|
|
direction = (direction - 1 + 4) % 4;
|
|
}
|
|
|
|
void R234::doRotateRight() {
|
|
direction = (direction + 1) % 4;
|
|
}
|