-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArmy.cs
129 lines (113 loc) · 3.9 KB
/
Army.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
namespace Advance
{
/// <summary>
/// Represents an army of pieces in the game.
/// </summary>
public class Army
{
/// <summary>
/// Gets the collection of pieces in the army.
/// </summary>
public IEnumerable<Piece> Pieces
{
get
{
return pieces;
}
}
/// <summary>
/// Adds a piece to the army.
/// </summary>
/// <param name="piece">The piece to add.</param>
public void AddPiece(Piece defected)
{
pieces.Add(defected);
}
/// <summary>
/// Removes a piece from the army.
/// </summary>
/// <param name="piece">The piece to remove.</param>
public void RemovePiece(Piece defected)
{
pieces.Remove(defected);
}
private List<Piece> pieces = new List<Piece>();
/// <summary>
/// Initializes a new instance of the <see cref="Army"/> class.
/// </summary>
/// <param name="player">The player that owns the army.</param>
/// <param name="board">The game board.</param>
public Army(Player player, Board board)
{
Player = player;
Board = board;
int baseRow = player.Colour == Colour.Black ? 0 : Board.Size - 1;
int direction = player.Direction;
}
/// <summary>
/// Gets the player that owns the army.
/// </summary>
public Player Player { get; }
/// <summary>
/// Gets the game board.
/// </summary>
public Board Board { get; }
/// <summary>
/// Removes all pieces from the army and clears the board.
/// </summary>
public void RemoveAllPieces()
{
foreach (var currentPiece in pieces)
{
if (currentPiece.OnBoard) currentPiece.LeaveBoard();
}
pieces.Clear();
}
/// <summary>
/// Recruits a new piece into the army and places it on the initial square.
/// </summary>
/// <param name="icon">The icon representing the piece.</param>
/// <param name="initialSquare">The initial square where the piece will be placed.</param>
public void Recruit(char icon, Square? initialSquare)
{
if (initialSquare == null)
throw new ArgumentException("initialSquare must not be null");
var symbol = Char.ToLower(icon);
Piece? newPiece = null;
switch (symbol)
{
case 'z':
newPiece = new Zombie(Player, initialSquare);
break;
case 'b':
newPiece = new Builder(Player, initialSquare);
break;
case 'm':
newPiece = new Miner(Player, initialSquare);
break;
case 'j':
newPiece = new Jester(Player, initialSquare);
break;
case 's':
newPiece = new Sentinel(Player, initialSquare);
break;
case 'c':
newPiece = new Catapult(Player, initialSquare);
break;
case 'd':
newPiece = new Dragon(Player, initialSquare);
break;
case 'g':
newPiece = new General(Player, initialSquare);
break;
case '#':
newPiece = new Wall(null, initialSquare);
break;
default:
throw new ArgumentException("Unrecognised icon");
}
pieces.Add(newPiece);
}
}
}