-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot.cpp
54 lines (47 loc) · 1.04 KB
/
dot.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
/**
* @file dot.cpp
* @author combofish ([email protected])
* @brief 存储网格所用的坐标数据类。
* @version 0.6
* @date 2021-10-16
*
* @copyright Copyright (c) 2021
*
*/
#include "dot.h"
using namespace snake_game;
Dot Dot::get_random_dot() {
int w1 = dist_width(eng) * 20;
int h1 = dist_width(eng) * 20;
return Dot(h1, w1);
}
void Dot::move(Direction d) {
switch (d) {
case Direction::UP:
y -= grid_width;
break;
case Direction::DOWN:
y += grid_width;
break;
case Direction::RIGHT:
x += grid_hight;
break;
case Direction::LEFT:
x -= grid_hight;
break;
default:
break;
}
}
Dot Dot::get_random_dot_exclude(const std::vector<Dot> &ps) {
Dot p = get_random_dot();
bool can_use = true;
for (Dot it: ps)
if (p == it) {
can_use = false;
break;
}
if (!can_use)
p = get_random_dot_exclude(ps);
return p;
}