From 3436e3365b10079729f9b273da822b123fa14d2f Mon Sep 17 00:00:00 2001 From: ninetailsrabbit Date: Sun, 9 Jun 2024 09:18:32 +0100 Subject: [PATCH] more helper methods to manage pieces and the actions they can do --- Match3Maker/Match3Maker.csproj | 2 +- Match3Maker/src/components/GridCell.cs | 5 +++-- Match3Maker/src/interfaces/IPieceType.cs | 4 ++++ Match3Maker/src/pieces/NormalPieceType.cs | 3 +++ Match3Maker/src/pieces/ObstaclePieceType.cs | 3 +++ Match3Maker/src/pieces/SpecialPieceType.cs | 3 +++ 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Match3Maker/Match3Maker.csproj b/Match3Maker/Match3Maker.csproj index e50acba..77c3a44 100644 --- a/Match3Maker/Match3Maker.csproj +++ b/Match3Maker/Match3Maker.csproj @@ -14,7 +14,7 @@ Ninetailsrabbit.Match3Maker - 1.1.0 + 1.1.1 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 © 2024 Ninetailsrabbit Ninetailsrabbit diff --git a/Match3Maker/src/components/GridCell.cs b/Match3Maker/src/components/GridCell.cs index 5f52ae9..124c41b 100644 --- a/Match3Maker/src/components/GridCell.cs +++ b/Match3Maker/src/components/GridCell.cs @@ -54,7 +54,6 @@ public void AssignPiece(Piece piece) { return previousPiece; } - public bool SwapPieceWith(GridCell otherCell) { if (CanSwapPieceWith(otherCell)) { @@ -85,7 +84,9 @@ public bool CanSwapPieceWith(GridCell otherCell) { && !Piece.Locked && !otherCell.Piece.Locked && !Equals(otherCell) - && !Piece.Equals(otherCell.Piece); + && !Piece.Equals(otherCell.Piece) + && Piece.Type.CanBeSwapped() + && otherCell.Piece.Type.CanBeSwapped(); } public bool InSameRowAs(GridCell cell) => cell.Row.Equals(Row); diff --git a/Match3Maker/src/interfaces/IPieceType.cs b/Match3Maker/src/interfaces/IPieceType.cs index 9825a18..a89fc1d 100644 --- a/Match3Maker/src/interfaces/IPieceType.cs +++ b/Match3Maker/src/interfaces/IPieceType.cs @@ -7,5 +7,9 @@ public interface IPieceType { public bool MatchWith(Piece piece); public bool CanBeShuffled(); public bool CanBeMoved(); + public bool CanBeSwapped(); + public bool CanBeTriggered(); + public bool CanBeReplaced(); + } } diff --git a/Match3Maker/src/pieces/NormalPieceType.cs b/Match3Maker/src/pieces/NormalPieceType.cs index 35cc824..b95bcbb 100644 --- a/Match3Maker/src/pieces/NormalPieceType.cs +++ b/Match3Maker/src/pieces/NormalPieceType.cs @@ -21,5 +21,8 @@ public bool MatchWith(Piece piece) { public bool CanBeShuffled() => true; public bool CanBeMoved() => true; + public bool CanBeSwapped() => true; + public bool CanBeTriggered() => false; + public bool CanBeReplaced() => true; } } diff --git a/Match3Maker/src/pieces/ObstaclePieceType.cs b/Match3Maker/src/pieces/ObstaclePieceType.cs index 5aec138..a6ff7ae 100644 --- a/Match3Maker/src/pieces/ObstaclePieceType.cs +++ b/Match3Maker/src/pieces/ObstaclePieceType.cs @@ -16,6 +16,9 @@ public ObstaclePieceType(string shape, Color? color = null) { public bool MatchWith(Piece piece) => false; public bool CanBeShuffled() => false; public bool CanBeMoved() => false; + public bool CanBeSwapped() => false; + public bool CanBeTriggered() => false; + public bool CanBeReplaced() => false; } diff --git a/Match3Maker/src/pieces/SpecialPieceType.cs b/Match3Maker/src/pieces/SpecialPieceType.cs index 5181360..eacd4d7 100644 --- a/Match3Maker/src/pieces/SpecialPieceType.cs +++ b/Match3Maker/src/pieces/SpecialPieceType.cs @@ -24,6 +24,9 @@ public bool MatchWith(Piece piece) { public bool CanBeShuffled() => true; public bool CanBeMoved() => true; + public bool CanBeSwapped() => true; + public bool CanBeTriggered() => true; + public bool CanBeReplaced() => false; } } \ No newline at end of file