-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoint.vala
53 lines (52 loc) · 1.04 KB
/
Point.vala
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
namespace Snake {
public class Point : Object {
public double x;
public double y;
public char symb;
public Point (double _x, double _y, char _symb) {
x = _x;
y = _y;
symb = _symb;
}
public Point.copy (Point p) {
x = p.x;
y = p.y;
symb = p.symb;
}
public void draw (Cairo.Context cr) {
cr.save ();
cr.set_source_rgb (0.1, 0.1, 0.1);
cr.select_font_face ("Adventure", Cairo.FontSlant.NORMAL, Cairo.FontWeight.BOLD);
cr.set_font_size (15);
cr.move_to (x, y);
cr.show_text (symb.to_string());
cr.restore ();
}
public void move (int offset, Direction dir) {
offset *= 10;
switch (dir) {
case Direction.RIGHT:
x += offset;
break;
case Direction.LEFT:
x -= offset;
break;
case Direction.UP:
y -= offset;
break;
case Direction.DOWN:
y += offset;
break;
}
}
public bool is_match (Point p) {
bool is_match;
if (this.x == p.x && this.y == p.y) {
is_match = true;
} else {
is_match = false;
}
return is_match;
}
}
}