-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsegment.h
More file actions
32 lines (26 loc) · 695 Bytes
/
segment.h
File metadata and controls
32 lines (26 loc) · 695 Bytes
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
#pragma once
// basically a specialized doubly linked list
enum class Direction {
up, down, left, right
};
class Segment {
public:
Segment(int y, int x); // Constructor for head
Segment(Segment *s); // Constructor tail
~Segment();
int row, col;
void move(); // call on tail
Segment* grow(); // returns a pointer to the last segment
// returns false if direction did not change
// e.g. if trying to go left when going right
// or trying to go right when already going right
bool up();
bool down();
bool right();
bool left();
Segment *getNext();
private:
Segment *next;
Segment *prev;
Direction dir;
};