-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cs
More file actions
40 lines (34 loc) · 1.02 KB
/
Player.cs
File metadata and controls
40 lines (34 loc) · 1.02 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
using System;
namespace State
{
public class Player
{
public string Name { get; private set; }
public float Health { get; private set; }
public float X { get; private set; }
public float Y { get; private set; }
public bool IsAlive => Health > 0;
public Player(string name, float health, float x, float y)
{
Name = name ?? throw new ArgumentNullException(nameof(name));
Health = health;
X = x;
Y = y;
}
public void TakeDamage(float damage)
{
Health -= Math.Max(damage, 0);
Health = Math.Max(Health, 0);
}
public void MoveTo(float x, float y)
{
X = x; Y = y;
}
public float GetDistanceTo(Enemy enemy)
{
double deltaX = enemy.X - X;
double deltaY = enemy.Y - Y;
return (float)Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
}
}
}