-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCharacter.cs
69 lines (63 loc) · 2.21 KB
/
Character.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Roguelike
{
abstract class Character : BaseCharacter
{
public int HitPoints { get; set; }
public int MovePoints { get; set; }
public int SpeedPoints { get; set; }
public int RangeOfVision { get; set; }
public bool IsActionDone { get; set; }
public BaseEntity Target { get; set; }
protected abstract void ResetGameAction();
protected abstract bool HandleCollisions(TileFlyweight tile);
//sets IsActionDone, sets CurrentGameAction, returns true if we can move
public override void Move()
{
TileFlyweight tile;
bool isMoved;
SetPrevCoords();
Target = null;
switch (CurrentMoveAction)
{
case MoveAction.Up:
tile = Program.GameEngine.GetTile(Coords.X, Coords.Y - 1);
break;
case MoveAction.Down:
tile = Program.GameEngine.GetTile(Coords.X, Coords.Y + 1);
break;
case MoveAction.Left:
tile = Program.GameEngine.GetTile(Coords.X - 1, Coords.Y);;
break;
case MoveAction.Right:
tile = Program.GameEngine.GetTile(Coords.X + 1, Coords.Y);
break;
default:
IsActionDone = false;
return;
}
if(tile.Price == -1)
{
ResetGameAction();
IsActionDone = true;
if (this.Symbol == '@') //simple check, <=> (this is Hero)
Program.GameEngine.InfoBorder.WriteNextLine($"{Name} can't go there"); //this code is not nessesary
return;
}
MovePoints += SpeedPoints;
if(MovePoints < tile.Price)
{
ResetGameAction();
IsActionDone = true;
return;
}
MovePoints -= tile.Price;
isMoved = HandleCollisions(tile);
if (isMoved) MoveEntity();
}
}
}