-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.cpp
87 lines (71 loc) · 1.39 KB
/
Node.cpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// Node.cpp
// TicTacToe
//
// Created by Савелий Никулин on 02.07.2024.
//
#include "Node.hpp"
Node::Node() {
parent = nullptr;
}
void Node::setPosition(const float x, const float y) {
this->x = x;
this->y = y;
}
void Node::setSize(const float w, const float h) {
this->w = w;
this->h = h;
}
void Node::setName(const string name) {
this->name = name;
}
void Node::addNode(Node *node) {
node->parent = this;
nodes.push_back(*node);
}
bool Node::isInteract(Node *node) {
if (node->getX() > x && node->getX() < x + w &&
node->getY() > y && node->getY() < y + h) {
return true;
}
}
bool Node::isInteract(int x, int y) {
if (x > this->x && x < this->x + w &&
y > this->y && y < this->y + h) {
return true;
}
}
bool Node::operator==(const Node &r) {
if (this->name == r.name &&
this->x == r.x &&
this->y == r.y &&
this->w == r.w &&
this->h == r.h) {
return true;
}
return false;
}
float Node::getX() {
return x;
}
float Node::getY() {
return y;
}
float Node::getW() {
return w;
}
float Node::getH() {
return h;
}
string Node::getName() {
return name;
}
vector<Node> &Node::getNodes() {
return nodes;
}
Node &Node::getNodeByName(string name) {
for (Node &node : nodes) {
if (node.name == name)
return node;
}
}