X-BOT/R234.cpp
2025-02-04 20:53:52 -05:00

57 lines
1.1 KiB
C++

//
// Created by Louis Gallet on 15/01/2025.
//
#include "R234.h"
void R234::initialiser(int const direction, int const strength, int const speed, int const 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 const 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;
}