/
Mover.cs
80 lines (75 loc) · 3.08 KB
/
Mover.cs
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
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace theQuest
{
abstract class Mover // entire class provided by the book
{
private const int MoveInterval = 10;
protected Point location;
public Point Location { get { return location; } }
protected Game game;
public Mover(Game game, Point location)
{
this.game = game;
this.location = location;
}
public bool Nearby(Point locationToCheck, int distance)
{
if(Math.Abs(location.X - locationToCheck.X) < distance && (Math.Abs(location.Y - locationToCheck.Y) < distance)) return true;
else return false;
}
public bool Nearby(Point location, Point locationToCheck, int distance) //I added this override method because the book used a three variable call in weapon.
{
if (Math.Abs(location.X - locationToCheck.X) < distance && (Math.Abs(location.Y - locationToCheck.Y) < distance)) return true;
else return false;
}
public Point Move(Direction direction, Rectangle boundaries)
{
Point newLocation = location;
switch (direction)
{
case Direction.Up:
if (newLocation.Y - MoveInterval >= boundaries.Top) newLocation.Y -= MoveInterval;
break;
case Direction.Down:
if (newLocation.Y + MoveInterval <= boundaries.Bottom) newLocation.Y += MoveInterval;
break;
case Direction.Left:
if (newLocation.X - MoveInterval >= boundaries.Left) newLocation.X -= MoveInterval;
break;
case Direction.Right:
if (newLocation.X + MoveInterval <= boundaries.Right) newLocation.X += MoveInterval;
break;
default:
break;
}
return newLocation;
}
public Point Move(Direction direction, Point location, Rectangle boundaries) //Again added this method because the book used a three variable call in Damage enemy.
{
Point newLocation = location;
switch (direction)
{
case Direction.Up:
if (newLocation.Y - MoveInterval >= boundaries.Top) newLocation.Y -= MoveInterval;
break;
case Direction.Down:
if (newLocation.Y + MoveInterval <= boundaries.Bottom) newLocation.Y += MoveInterval;
break;
case Direction.Left:
if (newLocation.X - MoveInterval >= boundaries.Left) newLocation.X -= MoveInterval;
break;
case Direction.Right:
if (newLocation.X + MoveInterval <= boundaries.Right) newLocation.X += MoveInterval;
break;
default:
break;
}
return newLocation;
}
}
}