-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreature.cpp
More file actions
68 lines (50 loc) · 1.34 KB
/
Copy pathCreature.cpp
File metadata and controls
68 lines (50 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Creature.cpp
*
* Created on: Apr 20, 2023
* Author: süleyman yağız başaran
* id: 22103782
* sec: 3
* hw: 3
*/
#include <string.h>
#include <iostream>
#include <cmath>
using namespace std;
#include "Creature.h"
Creature::Creature(){};
Creature::~Creature(){};
Creature::Creature(int ID, double x, double y, int health){
this->ID = ID;
this->x = x;
this->y = y;
this->health = health;
}
bool Creature::ifRadiusEatFood(Food food) {
if( this->health > 0) {
double diffX = this->x - food.x;
double tempPowdiffX = pow(diffX,2);
double diffY = this->y - food.y;
double tempPowdiffY = pow(diffY,2);
double realDistance = sqrt(tempPowdiffX + tempPowdiffY);
if (realDistance < 1)
return true;
else return false;
}
else return false;
}
bool Creature::checkFight(Creature creature) {
if((this->health < creature.health) || this->health == 0 || creature.health == 0)
return false;
else {
double diffX = this->x - creature.x;
double tempPowdiffX = pow(diffX,2);
double diffY = this->y - creature.y;
double tempPowdiffY = pow(diffY,2);
double realDistance = sqrt(tempPowdiffX + tempPowdiffY);
if (realDistance < 2)
return true;
else return false;
}
//?
}