@@ -14,7 +14,7 @@ A cross-platform library that makes it easy to create your own Match 3 game.
14
14
- [ Create fill strategy] ( #create-fill-strategy )
15
15
- [ Create level goal] ( #create-level-goal )
16
16
- [ Create sequence detector] ( #create-sequence-detector )
17
- - [ Create special block ] ( #create-special-block )
17
+ - [ Create special item ] ( #create-special-item )
18
18
- [ ToDo] ( #dart-todo )
19
19
- [ Contributing] ( #bookmark_tabs-contributing )
20
20
- [ Report a bug] ( #report-a-bug )
@@ -51,7 +51,7 @@ A Match 3 game sample with three implementations to fill the playing field.
51
51
52
52
> ** Note:** The ` FallDownFillStrategy ` & ` SlideDownFillStrategy ` are given as an example. Consider to implement an object pooling technique for the ` ItemMoveData ` to reduce memory pressure.
53
53
54
- <details ><summary >< b > Gameplay Demonstration</ b > </summary >
54
+ <details ><summary >Gameplay Demonstration</summary >
55
55
<br />
56
56
57
57
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-
62
62
63
63
A Match 3 game sample designed for text terminals.
64
64
65
- <details ><summary >< b > Gameplay Demonstration</ b > </summary >
65
+ <details ><summary >Gameplay Demonstration</summary >
66
66
<br />
67
67
68
68
https://user-images.githubusercontent.com/28132516/164049550-467590dc-bbf8-4109-a1bb-38dfe6674cd6.mp4
@@ -482,9 +482,9 @@ public class AppContext : MonoBehaviour, IAppContext
482
482
}
483
483
```
484
484
485
- ### Create special block
485
+ ### Create special item
486
486
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.
488
488
489
489
Add a ` Stone ` value to the ` TileGroup ` enum.
490
490
@@ -505,6 +505,7 @@ public class StoneState : StatefulGridTile
505
505
{
506
506
private bool _isLocked = true ;
507
507
private bool _canContainItem ;
508
+ private TileGroup _group = TileGroup .Stone ;
508
509
509
510
// Prevents the block from move.
510
511
public override bool IsLocked => _isLocked ;
@@ -513,33 +514,35 @@ public class StoneState : StatefulGridTile
513
514
public override bool CanContainItem => _canContainItem ;
514
515
515
516
// Defines the tile group.
516
- public override TileGroup Group => TileGroup . Stone ;
517
+ public override TileGroup Group => _group ;
517
518
518
519
// Occurs when all block states have completed.
519
520
protected override void OnComplete ()
520
521
{
521
522
_isLocked = false ;
522
523
_canContainItem = true ;
524
+ _group = TileGroup .Available ;
523
525
}
524
526
525
527
// Occurs when the block state is reset.
526
528
protected override void OnReset ()
527
529
{
528
530
_isLocked = true ;
529
531
_canContainItem = false ;
532
+ _group = TileGroup .Stone ;
530
533
}
531
534
}
532
535
```
533
536
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> ` .
535
538
536
539
``` csharp
537
- public class StoneTileDetector : ITileDetector
540
+ public class StoneItemDetector : ISpecialItemDetector < IUnityGridSlot >
538
541
{
539
542
private readonly GridPosition [] _lookupDirections ;
540
543
private readonly IUnityGameBoardRenderer _gameBoardRenderer ;
541
544
542
- public StoneTileDetector (IUnityGameBoardRenderer gameBoardRenderer )
545
+ public StoneItemDetector (IUnityGameBoardRenderer gameBoardRenderer )
543
546
{
544
547
_gameBoardRenderer = gameBoardRenderer ;
545
548
_lookupDirections = new []
@@ -551,38 +554,52 @@ public class StoneTileDetector : ITileDetector
551
554
};
552
555
}
553
556
554
- public void CheckGridSlot (IUnityGridSlot gridSlot )
557
+ public IEnumerable <IUnityGridSlot > GetSpecialItemGridSlots (IGameBoard <IUnityGridSlot > gameBoard ,
558
+ IUnityGridSlot gridSlot )
555
559
{
560
+ if (gridSlot .IsMovable == false )
561
+ {
562
+ yield break ;
563
+ }
564
+
556
565
foreach (var lookupDirection in _lookupDirections )
557
566
{
558
567
var position = gridSlot .GridPosition + lookupDirection ;
559
568
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 )
562
577
{
563
- _gameBoardRenderer . TrySetNextTileState ( position ) ;
578
+ continue ;
564
579
}
580
+
581
+ yield return gameBoard [position ];
565
582
}
566
583
}
567
584
}
568
585
```
569
586
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.
571
588
572
589
``` csharp
573
- public class TileGroupDetector : ISolvedSequencesConsumer < IUnityGridSlot >
590
+ public class AppContext : MonoBehaviour , IAppContext
574
591
{
575
592
...
576
593
577
- public TileGroupDetector (IUnityGameBoardRenderer gameBoardRenderer )
594
+ private ISpecialItemDetector < IUnityGridSlot >[] GetSpecialItemDetectors (IUnityGameBoardRenderer gameBoardRenderer )
578
595
{
579
- _tileDetectors = new ITileDetector []
596
+ return new ISpecialItemDetector < IUnityGridSlot > []
580
597
{
581
598
.. .
582
- new StoneTileDetector (gameBoardRenderer )
599
+ new StoneItemDetector (gameBoardRenderer )
583
600
};
584
601
}
585
-
602
+
586
603
...
587
604
}
588
605
```
@@ -618,7 +635,7 @@ https://user-images.githubusercontent.com/28132516/164196506-80ebe446-7a7a-4ae6-
618
635
Here are some features which are either under way or planned:
619
636
620
637
- [ ] Add tests
621
- - [x] Add special block support
638
+ - [x] Add special item support
622
639
- [ ] Build .unitypackage
623
640
- [ ] Publish on Asset Store
624
641
- [ ] Optimize ` ItemsDrop ` & ` ItemsRollDown ` fill strategies
0 commit comments