-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGates.hpp
176 lines (143 loc) · 3.26 KB
/
Gates.hpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#pragma once
#include <iostream>
#include <raylib.h>
#include <string>
class Object {
protected:
Vector2 position = Vector2{100, 100};
bool mouseOn;
bool held = false;
bool dragging = false;
bool rightClicking = false;
bool leftClicking = false;
public:
virtual void Draw() = 0;
virtual void Cycle() = 0;
virtual void CheckMouse() = 0;
bool IsMouseOnThis();
bool DragMove();
void OffsetPosition(Vector2 offset);
};
class Gate;
class Output;
class Point : public Object {
protected:
std::string lable;
float radius = 26;
Color lampColor = RED;
Vector2 pointingTo;
Gate *GateConnectedTo = nullptr;
Output *OutputConnectedTo = nullptr;
bool Value = false;
bool ConnectedToGate = false;
bool ConnectedToOutput = false;
bool connDragging = false;
public:
Point();
virtual void Cycle();
void DragToConnect();
void SetPointingTo(Vector2 v) { this->pointingTo = v; }
virtual void Draw();
virtual void CheckMouse();
virtual bool Solve();
bool IsConnDragging();
void ConnectThis(Gate *);
void ConnectThis(Output *);
};
// Switch
class Switch : public Point {
protected:
Color color = RED;
public:
Switch() {
this->position = GetMousePosition();
this->radius = 15;
}
void SwitchValue();
virtual void Draw();
virtual void Cycle();
};
// Output
//
class Output : public Object {
protected:
Color color = RED;
float radius = 30;
Point *Input = nullptr;
bool value = false;
std::string label = "False";
public:
Output();
virtual void Draw();
virtual void CheckMouse();
virtual void Cycle();
void ConnectToThis(Point *);
void Solve();
Vector2 GetPosition() { return this->position; }
bool IsConnectedTo() { return (this->Input != nullptr); }
Point *GetInput() { return this->Input; }
void SetPosition(Vector2 v) { this->position = v; }
void SetLabel() {
if (this->value) {
this->label = "True";
this->color = GREEN;
} else {
this->label = "False";
this->color = RED;
}
};
};
// Gates
class Gate : public Point {
protected:
bool a;
bool b;
bool aIsKnown = false;
bool bIsKnown = false;
bool aIsConnected = false;
bool bIsConnected = false;
std::string name;
Point *Connectiona;
Point *Connectionb;
public:
Gate();
virtual bool CalcGate() = 0;
virtual bool Solve();
void ConnectToThis(Point *);
bool HasEmptyConn();
void Forget();
Vector2 GetPosition() { return this->position; }
void Draw();
void Cycle();
};
//
class AndGate : public Gate {
public:
AndGate() { this->lable = "And "; }
virtual bool CalcGate() { return this->a && this->b; }
};
class NandGate : public Gate {
public:
NandGate() { this->lable = "Nand"; }
virtual bool CalcGate() { return !(this->a && this->b); }
};
class OrGate : public Gate {
public:
OrGate() { this->lable = "Or"; }
virtual bool CalcGate() { return this->a || this->b; }
};
class NorGate : public Gate {
public:
NorGate() { this->lable = "Nor"; }
virtual bool CalcGate() { return !(this->a || this->b); }
};
class XorGate : public Gate {
public:
XorGate() { this->lable = "Xor"; }
virtual bool CalcGate() { return this->a != this->b; }
};
class XnorGate : public Gate {
public:
XnorGate() { this->lable = "Xnor"; }
virtual bool CalcGate() { return this->a == this->b; }
};