-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPacMan.cs
More file actions
72 lines (66 loc) · 2.04 KB
/
Copy pathPacMan.cs
File metadata and controls
72 lines (66 loc) · 2.04 KB
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
namespace PacMan;
public class PacMan
{
private readonly int tileSize;
private const int _speed = 5;
private const int _side = 24;
private int _x;
private int _y;
public int GetX => _x;
public int GetY => _y;
public int GetSide => _side;
public DirectionType Direction { get; set; }
public PacMan(int x, int y, int mapTileSize)
{
_x = x;
_y = y;
tileSize = mapTileSize;
}
public void Draw(Graphics g)
{
Brush br = new SolidBrush(Color.Yellow);
int startAngle, sweepAngle = 300;
switch (Direction)
{
case DirectionType.Up:
startAngle = 300;
break;
case DirectionType.Down:
startAngle = 120;
break;
case DirectionType.Left:
startAngle = 210;
break;
case DirectionType.Right:
startAngle = 30;
break;
default:
startAngle = 210;
break;
}
g.FillPie(br, _x + 3, _y + 3, _side, _side, startAngle, sweepAngle);
}
public void MoveTo(DirectionType direction, Map map)
{
switch (direction)
{
case DirectionType.Right:
if (!map.IsWall(_x + tileSize, _y) && !map.IsWall(_x + tileSize, _y + tileSize - 1))
_x += _speed;
break;
case DirectionType.Left:
if (!map.IsWall(_x - _speed, _y) && !map.IsWall(_x - _speed, _y + tileSize - 1))
_x -= _speed;
break;
case DirectionType.Up:
if (!map.IsWall(_x, _y - _speed) && !map.IsWall(_x + tileSize - 1, _y - _speed))
_y -= _speed;
break;
case DirectionType.Down:
if (!map.IsWall(_x, _y + tileSize ) && !map.IsWall(_x + tileSize - 1, _y + tileSize))
_y += _speed;
break;
}
Direction = direction;
}
}