Skip to content

Commit e9f5063

Browse files
author
RUBIUS\chebanovdd
committed
Fixed special item issues.
1 parent ee857d8 commit e9f5063

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+404
-274
lines changed

samples/Terminal.Match3/DependencyInjection.cs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using Microsoft.Extensions.DependencyInjection;
77
using Terminal.Match3.FillStrategies;
88
using Terminal.Match3.Interfaces;
9-
using Terminal.Match3.TileGroupDetectors;
9+
using Terminal.Match3.SpecialItemDetectors;
1010

1111
namespace Terminal.Match3
1212
{
@@ -37,27 +37,39 @@ private static GameConfig<ITerminalGridSlot> GetGameConfig(TerminalGameBoardRend
3737
GameBoardDataProvider = gameBoardRenderer,
3838
LevelGoalsProvider = new LevelGoalsProvider(),
3939
ItemSwapper = new TerminalItemSwapper(gameBoardRenderer),
40-
GameBoardSolver = GetGameBoardSolver(),
41-
SolvedSequencesConsumers = GetSolvedSequencesConsumers(gameBoardRenderer)
40+
GameBoardSolver = GetGameBoardSolver(gameBoardRenderer),
41+
SolvedSequencesConsumers = GetSolvedSequencesConsumers()
4242
};
4343
}
4444

45-
private static IGameBoardSolver<ITerminalGridSlot> GetGameBoardSolver()
45+
private static IGameBoardSolver<ITerminalGridSlot> GetGameBoardSolver(
46+
ITerminalGameBoardRenderer gameBoardRenderer)
47+
{
48+
return new GameBoardSolver<ITerminalGridSlot>(GetSequenceDetectors(),
49+
GetSpecialItemDetectors(gameBoardRenderer));
50+
}
51+
52+
private static ISequenceDetector<ITerminalGridSlot>[] GetSequenceDetectors()
4653
{
47-
return new GameBoardSolver<ITerminalGridSlot>(new ISequenceDetector<ITerminalGridSlot>[]
54+
return new ISequenceDetector<ITerminalGridSlot>[]
4855
{
4956
new VerticalLineDetector<ITerminalGridSlot>(),
5057
new HorizontalLineDetector<ITerminalGridSlot>()
51-
});
58+
};
5259
}
5360

54-
private static ISolvedSequencesConsumer<ITerminalGridSlot>[] GetSolvedSequencesConsumers(
61+
private static ISpecialItemDetector<ITerminalGridSlot>[] GetSpecialItemDetectors(
5562
ITerminalGameBoardRenderer gameBoardRenderer)
5663
{
57-
return new ISolvedSequencesConsumer<ITerminalGridSlot>[]
64+
return new ISpecialItemDetector<ITerminalGridSlot>[]
5865
{
59-
new TileGroupDetector(gameBoardRenderer)
66+
new LockedItemDetector(gameBoardRenderer)
6067
};
6168
}
69+
70+
private static ISolvedSequencesConsumer<ITerminalGridSlot>[] GetSolvedSequencesConsumers()
71+
{
72+
return System.Array.Empty<ISolvedSequencesConsumer<ITerminalGridSlot>>();
73+
}
6274
}
6375
}

samples/Terminal.Match3/Extensions/ItemsSequenceExtensions.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,24 @@ namespace Terminal.Match3.Extensions
66
{
77
public static class ItemsSequenceExtensions
88
{
9-
public static IEnumerable<TGridSlot> GetUniqueGridSlots<TGridSlot>(
10-
this IEnumerable<ItemSequence<TGridSlot>> sequences, bool onlyMovable = false) where TGridSlot : IGridSlot
9+
public static IEnumerable<TGridSlot> GetUniqueSolvedGridSlots<TGridSlot>(this SolvedData<TGridSlot> solvedData,
10+
bool onlyMovable = false) where TGridSlot : IGridSlot
1111
{
1212
var solvedGridSlots = new HashSet<TGridSlot>();
1313

14-
foreach (var sequence in sequences)
14+
foreach (var solvedGridSlot in solvedData.GetSolvedGridSlots())
1515
{
16-
foreach (var solvedGridSlot in sequence.SolvedGridSlots)
16+
if (onlyMovable && solvedGridSlot.IsMovable == false)
1717
{
18-
if (onlyMovable && solvedGridSlot.IsMovable == false)
19-
{
20-
continue;
21-
}
22-
23-
if (solvedGridSlots.Add(solvedGridSlot) == false)
24-
{
25-
continue;
26-
}
18+
continue;
19+
}
2720

28-
yield return solvedGridSlot;
21+
if (solvedGridSlots.Add(solvedGridSlot) == false)
22+
{
23+
continue;
2924
}
25+
26+
yield return solvedGridSlot;
3027
}
3128

3229
solvedGridSlots.Clear();

samples/Terminal.Match3/FillStrategies/SimpleFillStrategy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public IEnumerable<IJob> GetFillJobs(IGameBoard<ITerminalGridSlot> gameBoard)
5454
}
5555

5656
public IEnumerable<IJob> GetSolveJobs(IGameBoard<ITerminalGridSlot> gameBoard,
57-
IEnumerable<ItemSequence<ITerminalGridSlot>> sequences)
57+
SolvedData<ITerminalGridSlot> solvedData)
5858
{
5959
var itemsToShow = new List<ITerminalItem>();
6060

61-
foreach (var solvedGridSlot in sequences.GetUniqueGridSlots(true))
61+
foreach (var solvedGridSlot in solvedData.GetUniqueSolvedGridSlots(true))
6262
{
6363
var newItem = _itemsPool.GetItem();
6464
var currentItem = solvedGridSlot.Item;

samples/Terminal.Match3/GridTiles/States/LockedState.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ namespace Terminal.Match3.GridTiles.States
66
public class LockedState : GridTile, IStatefulSlot
77
{
88
private bool _isLocked = true;
9+
private TileGroup _group = TileGroup.Locked;
910

1011
public override bool IsLocked => _isLocked;
1112
public override bool CanContainItem => true;
12-
public override TileGroup Group => TileGroup.Locked;
13+
public override TileGroup Group => _group;
1314

14-
public void NextState()
15+
public bool NextState()
1516
{
1617
_isLocked = false;
18+
_group = TileGroup.Available;
19+
20+
return false;
1721
}
1822
}
1923
}

samples/Terminal.Match3/Interfaces/IStatefulSlot.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
{
33
public interface IStatefulSlot
44
{
5-
void NextState();
5+
bool NextState();
66
}
77
}

samples/Terminal.Match3/Interfaces/ITerminalGameBoardRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public interface ITerminalGameBoardRenderer : IGameBoardRenderer
1515

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

samples/Terminal.Match3/Interfaces/ITileDetector.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Collections.Generic;
2+
using Match3.App.Interfaces;
3+
using Terminal.Match3.Enums;
4+
using Terminal.Match3.Interfaces;
5+
6+
namespace Terminal.Match3.SpecialItemDetectors
7+
{
8+
public class LockedItemDetector : ISpecialItemDetector<ITerminalGridSlot>
9+
{
10+
private readonly ITerminalGameBoardRenderer _gameBoardRenderer;
11+
12+
public LockedItemDetector(ITerminalGameBoardRenderer gameBoardRenderer)
13+
{
14+
_gameBoardRenderer = gameBoardRenderer;
15+
}
16+
17+
public IEnumerable<ITerminalGridSlot> GetSpecialItemGridSlots(IGameBoard<ITerminalGridSlot> gameBoard,
18+
ITerminalGridSlot gridSlot)
19+
{
20+
if (_gameBoardRenderer.GetTileGroup(gridSlot.GridPosition) != TileGroup.Locked)
21+
{
22+
yield break;
23+
}
24+
25+
var hasNextState = _gameBoardRenderer.TrySetNextTileState(gridSlot.GridPosition);
26+
if (hasNextState)
27+
{
28+
yield break;
29+
}
30+
31+
yield return gridSlot;
32+
}
33+
}
34+
}

samples/Terminal.Match3/TerminalGameBoardRenderer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ public TileGroup GetTileGroup(GridPosition gridPosition)
100100
return _gridSlotTiles[gridPosition.RowIndex, gridPosition.ColumnIndex].Group;
101101
}
102102

103-
public void TrySetNextTileState(GridPosition gridPosition)
103+
public bool TrySetNextTileState(GridPosition gridPosition)
104104
{
105-
((IStatefulSlot) _gridSlotTiles[gridPosition.RowIndex, gridPosition.ColumnIndex]).NextState();
105+
return ((IStatefulSlot) _gridSlotTiles[gridPosition.RowIndex, gridPosition.ColumnIndex]).NextState();
106106
}
107107

108108
public ITerminalGridSlot[,] GetGameBoardSlots(int level)

samples/Terminal.Match3/TileGroupDetectors/LockedTileDetector.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)