/
Rook.cs
90 lines (81 loc) · 2.45 KB
/
Rook.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
using System.Collections.Generic;
class Rook : Figure
{
public Rook(string name, string color, Position position) : base(name, color, position)
{
this.firstMove = true;
}
public Rook(string name, string color, Position position, bool firstMove) : base(name, color, position)
{
this.firstMove = firstMove;
}
public override List<Position> PossibleMoves(IFigureInterface[,] matrix, int cell)
{
List<Position> list = new List<Position>();
for (int i = position.y + 1; i < cell; i++)
if (matrix[position.x, i] == null)
{
list.Add(new Position(position.x, i));
}
else
{
if (matrix[position.x, i].GetColor() != color)
{
list.Add(new Position(position.x, i));
break;
}
else
break;
}
for (int i = position.y - 1; i >= 0; i--)
if (matrix[position.x, i] == null)
{
list.Add(new Position(position.x, i));
}
else
{
if (matrix[position.x, i].GetColor() != color)
{
list.Add(new Position(position.x, i));
break;
}
else
break;
}
for (int i = position.x + 1; i < cell; i++)
if (matrix[i, position.y] == null)
{
list.Add(new Position(i, position.y));
}
else
{
if (matrix[i, position.y].GetColor() != color)
{
list.Add(new Position(i, position.y));
break;
}
else
break;
}
for (int i = position.x - 1; i >= 0; i--)
if (matrix[i, position.y] == null)
{
list.Add(new Position(i, position.y));
}
else
{
if (matrix[i, position.y].GetColor() != color)
{
list.Add(new Position(i, position.y));
break;
}
else
break;
}
return list;
}
public override IFigureInterface DeepCopy()
{
return new Rook(this.name, this.color, this.position, this.firstMove);
}
}