Skip to content

Commit 4cdd707

Browse files
author
RUBIUS\chebanovdd
committed
Merge branch 'match3_sdk' of https://github.com/ChebanovDD/Match3-SDK into match3_sdk
2 parents 4b8eabc + 7a1ca67 commit 4cdd707

File tree

1 file changed

+37
-20
lines changed

1 file changed

+37
-20
lines changed

README.md

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ A cross-platform library that makes it easy to create your own Match 3 game.
1414
- [Create fill strategy](#create-fill-strategy)
1515
- [Create level goal](#create-level-goal)
1616
- [Create sequence detector](#create-sequence-detector)
17-
- [Create special block](#create-special-block)
17+
- [Create special item](#create-special-item)
1818
- [ToDo](#dart-todo)
1919
- [Contributing](#bookmark_tabs-contributing)
2020
- [Report a bug](#report-a-bug)
@@ -51,7 +51,7 @@ A Match 3 game sample with three implementations to fill the playing field.
5151

5252
> **Note:** The `FallDownFillStrategy` & `SlideDownFillStrategy` are given as an example. Consider to implement an object pooling technique for the `ItemMoveData` to reduce memory pressure.
5353
54-
<details><summary><b>Gameplay Demonstration</b></summary>
54+
<details><summary>Gameplay Demonstration</summary>
5555
<br />
5656

5757
https://user-images.githubusercontent.com/28132516/164045071-e2038177-1bc2-475c-8dbc-4b4f77d6895b.mp4
@@ -62,7 +62,7 @@ https://user-images.githubusercontent.com/28132516/164045071-e2038177-1bc2-475c-
6262

6363
A Match 3 game sample designed for text terminals.
6464

65-
<details><summary><b>Gameplay Demonstration</b></summary>
65+
<details><summary>Gameplay Demonstration</summary>
6666
<br />
6767

6868
https://user-images.githubusercontent.com/28132516/164049550-467590dc-bbf8-4109-a1bb-38dfe6674cd6.mp4
@@ -482,9 +482,9 @@ public class AppContext : MonoBehaviour, IAppContext
482482
}
483483
```
484484

485-
### Create special block
485+
### Create special item
486486

487-
Let's create a stone block that is only destroyed when a match happens in one of the neighbour tiles.
487+
Let's create a stone item that is only destroyed when a match happens in one of the neighbour tiles.
488488

489489
Add a `Stone` value to the `TileGroup` enum.
490490

@@ -505,6 +505,7 @@ public class StoneState : StatefulGridTile
505505
{
506506
private bool _isLocked = true;
507507
private bool _canContainItem;
508+
private TileGroup _group = TileGroup.Stone;
508509

509510
// Prevents the block from move.
510511
public override bool IsLocked => _isLocked;
@@ -513,33 +514,35 @@ public class StoneState : StatefulGridTile
513514
public override bool CanContainItem => _canContainItem;
514515

515516
// Defines the tile group.
516-
public override TileGroup Group => TileGroup.Stone;
517+
public override TileGroup Group => _group;
517518

518519
// Occurs when all block states have completed.
519520
protected override void OnComplete()
520521
{
521522
_isLocked = false;
522523
_canContainItem = true;
524+
_group = TileGroup.Available;
523525
}
524526

525527
// Occurs when the block state is reset.
526528
protected override void OnReset()
527529
{
528530
_isLocked = true;
529531
_canContainItem = false;
532+
_group = TileGroup.Stone;
530533
}
531534
}
532535
```
533536

534-
To respond to any changes in one of the neighbour tiles, we have to implement an `ITileDetector` interface. Create a `StoneTileDetector` class and inherit from the `ITileDetector`.
537+
To respond to any changes in one of the neighbour tiles, we have to implement an `ISpecialItemDetector<TGridSlot>` interface. Create a `StoneItemDetector` class and inherit from the `ISpecialItemDetector<TGridSlot>`.
535538

536539
```csharp
537-
public class StoneTileDetector : ITileDetector
540+
public class StoneItemDetector : ISpecialItemDetector<IUnityGridSlot>
538541
{
539542
private readonly GridPosition[] _lookupDirections;
540543
private readonly IUnityGameBoardRenderer _gameBoardRenderer;
541544

542-
public StoneTileDetector(IUnityGameBoardRenderer gameBoardRenderer)
545+
public StoneItemDetector(IUnityGameBoardRenderer gameBoardRenderer)
543546
{
544547
_gameBoardRenderer = gameBoardRenderer;
545548
_lookupDirections = new[]
@@ -551,38 +554,52 @@ public class StoneTileDetector : ITileDetector
551554
};
552555
}
553556

554-
public void CheckGridSlot(IUnityGridSlot gridSlot)
557+
public IEnumerable<IUnityGridSlot> GetSpecialItemGridSlots(IGameBoard<IUnityGridSlot> gameBoard,
558+
IUnityGridSlot gridSlot)
555559
{
560+
if (gridSlot.IsMovable == false)
561+
{
562+
yield break;
563+
}
564+
556565
foreach (var lookupDirection in _lookupDirections)
557566
{
558567
var position = gridSlot.GridPosition + lookupDirection;
559568

560-
if (_gameBoardRenderer.IsPositionOnGrid(position) &&
561-
_gameBoardRenderer.GetTileGroup(position) == TileGroup.Stone)
569+
if (!_gameBoardRenderer.IsPositionOnGrid(position) ||
570+
_gameBoardRenderer.GetTileGroup(position) != TileGroup.Stone)
571+
{
572+
continue;
573+
}
574+
575+
var hasNextState = _gameBoardRenderer.TrySetNextTileState(position);
576+
if (hasNextState)
562577
{
563-
_gameBoardRenderer.TrySetNextTileState(position);
578+
continue;
564579
}
580+
581+
yield return gameBoard[position];
565582
}
566583
}
567584
}
568585
```
569586

570-
Once the `StoneTileDetector` is implemented, add it to the list of tile detectors in the `TileGroupDetector` class.
587+
Once the `StoneItemDetector` is implemented. Register it in the `AppContext` class.
571588

572589
```csharp
573-
public class TileGroupDetector : ISolvedSequencesConsumer<IUnityGridSlot>
590+
public class AppContext : MonoBehaviour, IAppContext
574591
{
575592
...
576593

577-
public TileGroupDetector(IUnityGameBoardRenderer gameBoardRenderer)
594+
private ISpecialItemDetector<IUnityGridSlot>[] GetSpecialItemDetectors(IUnityGameBoardRenderer gameBoardRenderer)
578595
{
579-
_tileDetectors = new ITileDetector[]
596+
return new ISpecialItemDetector<IUnityGridSlot>[]
580597
{
581598
...
582-
new StoneTileDetector(gameBoardRenderer)
599+
new StoneItemDetector(gameBoardRenderer)
583600
};
584601
}
585-
602+
586603
...
587604
}
588605
```
@@ -618,7 +635,7 @@ https://user-images.githubusercontent.com/28132516/164196506-80ebe446-7a7a-4ae6-
618635
Here are some features which are either under way or planned:
619636

620637
- [ ] Add tests
621-
- [x] Add special block support
638+
- [x] Add special item support
622639
- [ ] Build .unitypackage
623640
- [ ] Publish on Asset Store
624641
- [ ] Optimize `ItemsDrop` & `ItemsRollDown` fill strategies

0 commit comments

Comments
 (0)