Skip to content

Commit

Permalink
methods on Board to generate random pieces on selected cells
Browse files Browse the repository at this point in the history
  • Loading branch information
ninetailsrabbit committed Jun 12, 2024
1 parent 816c22c commit 3cbc45c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Match3Maker/Match3Maker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<PropertyGroup>
<Title>Ninetailsrabbit.Match3Maker</Title>
<Version>1.1.2</Version>
<Version>1.1.3</Version>
<Description>This lightweight library provides the core logic and functionality you need to build engaging match-3 games. Focus on game design and mechanics while leaving the complex logic to this library</Description>
<Copyright>© 2024 Ninetailsrabbit</Copyright>
<Authors>Ninetailsrabbit</Authors>
Expand Down
15 changes: 15 additions & 0 deletions Match3Maker/src/components/Board.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,21 @@ public void RemoveMatchesFromBoard() {
#endregion

#region Pieces

public void GenerateRandomPieceOnCells(IEnumerable<GridCell> cells, IEnumerable<Type>? only = null) {
foreach (GridCell cell in cells)
GenerateRandomPieceOnCell(cell, only);
}
public void GenerateRandomPieceOnCell(GridCell cell, IEnumerable<Type>? only = null) {
cell.AssignPiece(GenerateRandomPiece(only));
}
public Piece GenerateRandomPiece(IEnumerable<Type>? only = null) {
if (AvailablePieces.IsEmpty())
throw new InvalidOperationException("The available pieces on this board is empty, piece cannot be generated");

return PieceGenerator.Roll(AvailablePieces, only);
}

public Board AddAvailablePieces(IList<Piece> pieces) {
AvailablePieces.AddRange(pieces);
AvailablePieces = AvailablePieces.RemoveDuplicates().ToList();
Expand Down

0 comments on commit 3cbc45c

Please sign in to comment.