-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.h
72 lines (53 loc) · 995 Bytes
/
bot.h
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
#pragma once
#define _USE_MATH_DEFINES
#include <windows.h>
#include <math.h>
class Bot
{
public:
Bot(COORD coord) : direction(UP), coord{ 0 }
{
this->coord.X = coord.X;
this->coord.Y = coord.Y;
map[coord.Y][coord.X] = 'B';
SetConsoleCursorPosition(hd, coord);
printf("B");
};
void step()
{
if (speed_step++ > 3)
{
COORD coord = this->coord;
if (direction == UP)
coord.Y--;
else
coord.Y++;
if (map[coord.Y][coord.X] != ' ')
{
if (direction == UP)
{
direction = DOWN;
coord.Y += 1;
}
else
{
direction = UP;
coord.Y -= 1;
}
}
map[this->coord.Y][this->coord.X] = ' ';
SetConsoleCursorPosition(hd, this->coord);
printf(" ");
this->coord.X = coord.X;
this->coord.Y = coord.Y;
map[this->coord.Y][this->coord.X] = 'B';
SetConsoleCursorPosition(hd, this->coord);
printf("B");
speed_step = 0;
}
};
private:
COORD coord;
direct_t direction;
int speed_step = 0;
};