-
Notifications
You must be signed in to change notification settings - Fork 0
/
LShapedTetrimino.cs
83 lines (78 loc) · 3.1 KB
/
LShapedTetrimino.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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MineTris {
public class LShapedTetrimino : Tetrimino, IRotatable{
/// <summary>
/// Indicates how many times the object has rotated.
/// </summary>
private int rotationIndex;
/// <summary>
/// Constructs a new L shaped tetrimino.
/// </summary>
/// <param name="matrix">Please pass the matrix field of the TetrisBoard object.</param>
public LShapedTetrimino (int rotationIndex, TetrisBlock[,] matrix, TetrisWindow form)
: base (matrix, form) {
blocks = new List<TetrisBlock> () {
new TetrisBlock (Color.Yellow, 7, 0, form),
new TetrisBlock (Color.Yellow, 7, 1, form),
new TetrisBlock (Color.Yellow, 7, 2, form),
new TetrisBlock (Color.Yellow, 8, 2, form)
};
RotationIndex = 0;
for (int i = 0 ; i < rotationIndex ; i++) {
Rotate ();
}
}
/// <summary>
/// Gets which side(s) of the tetrinimo can land on other tetrinimo or the ground.
/// </summary>
protected override TetrisBlock[] touchingSides {
get {
switch (RotationIndex) {
case 0:
return new TetrisBlock[] { blocks[2], blocks[3] };
case 1:
return new TetrisBlock[] { blocks[1], blocks[3], blocks[0] };
case 2:
return new TetrisBlock[] { blocks[0], blocks[3] };
case 3:
return new TetrisBlock[] { blocks[2], blocks[0], blocks[1] };
default:
throw new ArgumentException ("The tetrimino is not rotated properly.");
}
}
}
/// <summary>
/// Rotates the object clockwise.
/// </summary>
public void Rotate () {
if (TetrisUtility.TryRotateTetriminoClockwise (this, 0))
TetrisUtility.AddRotationIndex (this);
else if (TetrisUtility.TryRotateTetriminoClockwise (this, 1))
TetrisUtility.AddRotationIndex (this);
else if (TetrisUtility.TryRotateTetriminoClockwise (this, 2))
TetrisUtility.AddRotationIndex (this);
else if (TetrisUtility.TryRotateTetriminoClockwise (this, 3))
TetrisUtility.AddRotationIndex (this);
}
/// <summary>
/// Indicates how many times the object has rotated.
/// </summary>
public int RotationIndex {
get {
return rotationIndex;
}
set {
if (value >= 0 && value <= 3) {
rotationIndex = value;
} else {
throw new ArgumentException ("Rotation Index must be between 0 and 3 for a L shaped Tetrimino.", "rotationIndex");
}
}
}
}
}