-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTurn.cs
More file actions
82 lines (81 loc) · 2.55 KB
/
Turn.cs
File metadata and controls
82 lines (81 loc) · 2.55 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
73
74
75
76
77
78
79
80
81
82
using System;
namespace simplegame
{
class Turn
{
public readonly int TurnNumber;
private Map GameMap;
public bool IsTurnDone{ get; private set; }
public bool IsPlayerDead{ get; private set; }
public bool IsEnemyDead{ get; private set; }
public string Action{ get; private set; }
public string PlayerNote;
private Player TurnPlayer;
private Player Enemy;
public Turn(Map map, Player player, Player enemy, int turnNum)
{
TurnPlayer = player;
GameMap = map;
Enemy = enemy;
TurnNumber = turnNum;
IsPlayerDead = false;
IsEnemyDead = false;
IsTurnDone = false;
}
public bool IsEnemyInRange{ get => Enemy != null; }
public bool Attack()
{
if(!IsTurnDone && IsEnemyInRange)
{
// Temp coin flip for winner
bool Win = (new Random()).Next(0,2) == 1;
if(Win)
{
Action = TurnPlayer.Name + " defeats " + Enemy.Name;
IsEnemyDead = true;
IsTurnDone = true;
return true;
}
else
{
Action = TurnPlayer.Name + " dies attacking " + Enemy.Name;
IsPlayerDead = true;
IsTurnDone = true;
return false;
}
}
return false;
}
public int EnemyX
{ get{
if(IsEnemyInRange)
{
return Enemy.X;
}
return -1;
}}
public int EnemyY
{ get{
if(IsEnemyInRange)
{
return Enemy.Y;
}
return -1;
}}
public int EnemyDefense{ get => GameMap.Tiles[Enemy.X, Enemy.Y].DefenseBonus; }
public void Move(int x, int y)
{
if(!IsTurnDone)
{
// Allow only one move point in each axis
x = x == 0 ? 0 : x / Math.Abs(x);
y = y == 0 ? 0 : y / Math.Abs(y);
TurnPlayer.X = Mod((TurnPlayer.X + x), GameMap.Width);
TurnPlayer.Y = Mod((TurnPlayer.Y + y), GameMap.Height);
IsTurnDone = true;
Action = TurnPlayer.Name + " moves to " + TurnPlayer.X.ToString() +", " + TurnPlayer.Y.ToString();
}
}
private int Mod(int n, int m) => ((n % m) + m) % m;
}
}