-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatchChecker.cs
More file actions
61 lines (53 loc) · 2.05 KB
/
MatchChecker.cs
File metadata and controls
61 lines (53 loc) · 2.05 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
using System;
using UnityEngine;
public class MatchChecker : MonoBehaviour
{
private Cell[,] cellArray;
private int rows, collumns;
public static event Action<int> OnMatchMade;
private void OnEnable() => FirstMatchCheck.SetCheck += SetCheck;
private void OnDisable() => FirstMatchCheck.SetCheck -= SetCheck;
private void Start()
{
cellArray = Cell_Setup.cellArray;
rows = cellArray.GetLength(0);
collumns = cellArray.GetLength(1);
}
public void SetCheck()
{
if (collumns >= 3) HorizontalCheck();
if (rows >= 3) VerticalCheck();
}
private void HorizontalCheck()
{
for (int row = 0; row < rows; row++)
{
for (int col = 0; col < collumns - 2; col++)
{
if (cellArray[row, col].cellItem.ID == cellArray[row, col + 1].cellItem.ID && cellArray[row, col].cellItem.ID == cellArray[row, col + 2].cellItem.ID)
{
cellArray[row, col].isEmpty = true;
cellArray[row, col + 1].isEmpty = true;
cellArray[row, col + 2].isEmpty = true;
OnMatchMade?.Invoke(cellArray[row, col].cellItem.ID * 10);
}
}
}
}
private void VerticalCheck()
{
for (int col = 0; col < collumns; col++)
{
for (int row = 0; row < rows - 2; row++)
{
if (cellArray[row, col].cellItem.ID == cellArray[row + 1, col].cellItem.ID && cellArray[row, col].cellItem.ID == cellArray[row + 2, col].cellItem.ID)
{
cellArray[row, col].isEmpty = true;
cellArray[row + 1, col].isEmpty = true;
cellArray[row + 2, col].isEmpty = true;
OnMatchMade?.Invoke(cellArray[row, col].cellItem.ID * 10);
}
}
}
}
}