Skip to content

Commit ad7e4f8

Browse files
author
RUBIUS\chebanovdd
committed
Added IsLocked property to GridSlot.
1 parent 3f19a4e commit ad7e4f8

17 files changed

+110
-28
lines changed

Assets/Plugins/Match3/Core/Models/GridSlot.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Match3.Core.Models
77
{
88
public class GridSlot<TItem> where TItem : IItem
99
{
10+
public bool IsLocked { get; private set; }
1011
public TItem Item { get; private set; }
1112
public GridPosition GridPosition { get; }
1213
public GridSlotState State { get; private set; }
@@ -17,6 +18,16 @@ internal GridSlot(GridSlotState state, GridPosition gridPosition)
1718
GridPosition = gridPosition;
1819
}
1920

21+
public void Lock()
22+
{
23+
IsLocked = true;
24+
}
25+
26+
public void Unlock()
27+
{
28+
IsLocked = false;
29+
}
30+
2031
public void SetItem(TItem item)
2132
{
2233
EnsureItemIsNotNull(item);

Assets/Prefabs/Tiles/IceTilePrefab.prefab

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Prefabs/Tiles/StoneTilePrefab.prefab

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scenes/MainScene.unity

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/Common/Extensions/ItemsSequenceExtensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ namespace Common.Extensions
88
public static class ItemsSequenceExtensions
99
{
1010
public static IEnumerable<GridSlot<TItem>> GetUniqueGridSlots<TItem>(
11-
this IEnumerable<ItemSequence<TItem>> sequences) where TItem : IItem
11+
this IEnumerable<ItemSequence<TItem>> sequences, bool includeLocked = true) where TItem : IItem
1212
{
1313
var solvedGridSlots = new HashSet<GridSlot<TItem>>();
1414

1515
foreach (var sequence in sequences)
1616
{
1717
foreach (var solvedGridSlot in sequence.SolvedGridSlots)
1818
{
19+
if (includeLocked == false && solvedGridSlot.IsLocked)
20+
{
21+
continue;
22+
}
23+
1924
if (solvedGridSlots.Add(solvedGridSlot) == false)
2025
{
2126
continue;

Assets/Scripts/Common/GameBoardAgreements.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ public bool CanSetItem(GridSlot<IUnityItem> gridSlot, TileGroup tileGroup)
1313
return isAvailableTile && gridSlot.State == GridSlotState.Empty;
1414
}
1515

16+
public bool IsBlocker(TileGroup tileGroup)
17+
{
18+
return tileGroup == TileGroup.Ice;
19+
}
20+
1621
public bool IsLockedSlot(TileGroup tileGroup)
1722
{
1823
return tileGroup != TileGroup.Available;

Assets/Scripts/Common/GridTiles/StatefulGridTile.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,40 @@ public class StatefulGridTile : SpriteGridTile, IStatefulTile
77
{
88
[Space]
99
[SerializeField] private SpriteRenderer _stateSpriteRenderer;
10-
[SerializeField] private string _stateSpriteName;
10+
[SerializeField] private string[] _stateSpriteNames;
11+
12+
private int _currentStateIndex;
1113

1214
protected override void Start()
1315
{
1416
base.Start();
15-
_stateSpriteRenderer.sprite = GetSprite(_stateSpriteName);
17+
_stateSpriteRenderer.sprite = GetStateSprite(_currentStateIndex);
1618
}
1719

1820
public bool NextState()
1921
{
20-
if (_stateSpriteRenderer.enabled)
22+
_currentStateIndex++;
23+
24+
if (_currentStateIndex >= _stateSpriteNames.Length)
2125
{
2226
_stateSpriteRenderer.enabled = false;
27+
return false;
2328
}
2429

25-
return false;
30+
_stateSpriteRenderer.sprite = GetStateSprite(_currentStateIndex);
31+
return true;
2632
}
2733

2834
public void ResetState()
2935
{
36+
_currentStateIndex = 0;
3037
_stateSpriteRenderer.enabled = true;
38+
_stateSpriteRenderer.sprite = GetStateSprite(0);
39+
}
40+
41+
private Sprite GetStateSprite(int index)
42+
{
43+
return GetSprite(_stateSpriteNames[index]);
3144
}
3245
}
3346
}

Assets/Scripts/Common/Interfaces/IGameBoardAgreements.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace Common.Interfaces
66
public interface IGameBoardAgreements
77
{
88
bool CanSetItem(GridSlot<IUnityItem> gridSlot, TileGroup tileGroup);
9+
bool IsBlocker(TileGroup tileGroup);
910
bool IsLockedSlot(TileGroup tileGroup);
1011
bool IsMovableSlot(GridSlot<IUnityItem> gridSlot, TileGroup tileGroup);
1112
bool IsAvailableSlot(GridSlot<IUnityItem> gridSlot, TileGroup tileGroup);

Assets/Scripts/Common/Interfaces/IUnityGameBoardRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface IUnityGameBoardRenderer : IGameBoardRenderer
1515
bool IsPositionOnGrid(GridPosition gridPosition);
1616

1717
void SetNextGridTileGroup(GridPosition gridPosition);
18-
void TrySetNextTileState(GridPosition gridPosition);
18+
bool TrySetNextTileState(GridPosition gridPosition);
1919
TileGroup GetTileGroup(GridPosition gridPosition);
2020
}
2121
}

Assets/Scripts/Common/TileGroupDetectors/IceTileDetector.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Common.Enums;
12
using Common.Interfaces;
23
using Match3.Core.Models;
34

@@ -14,7 +15,16 @@ public IceTileDetector(IUnityGameBoardRenderer gameBoardRenderer)
1415

1516
public void CheckGridSlot(GridSlot<IUnityItem> gridSlot)
1617
{
17-
_gameBoardRenderer.TrySetNextTileState(gridSlot.GridPosition);
18+
if (_gameBoardRenderer.GetTileGroup(gridSlot.GridPosition) != TileGroup.Ice)
19+
{
20+
return;
21+
}
22+
23+
var hasNewState = _gameBoardRenderer.TrySetNextTileState(gridSlot.GridPosition);
24+
if (hasNewState == false)
25+
{
26+
gridSlot.Unlock();
27+
}
1828
}
1929
}
2030
}

0 commit comments

Comments
 (0)