Implement debug switching
This commit is contained in:
@@ -155,6 +155,52 @@ namespace Services {
|
||||
this.currentState = GameState.Move;
|
||||
return true;
|
||||
}
|
||||
|
||||
public async UniTask<bool> TrySwitch(Vector2Int position) {
|
||||
Gem gem = this.gameBoard.GetGemAt(position);
|
||||
if(gem == null)
|
||||
return false;
|
||||
|
||||
GemType[] normalTypes = Enum.GetValues(typeof(GemType))
|
||||
.Cast<GemType>()
|
||||
.Where(t => t != GemType.Bomb)
|
||||
.ToArray();
|
||||
|
||||
if (normalTypes.Length == 0)
|
||||
return false;
|
||||
|
||||
bool nextIsBomb;
|
||||
GemType nextTypeOrMatchColor;
|
||||
|
||||
if (gem.Type != GemType.Bomb) {
|
||||
int index = Array.IndexOf(normalTypes, gem.Type);
|
||||
if (index < 0) index = 0;
|
||||
|
||||
if (index < normalTypes.Length - 1) {
|
||||
nextIsBomb = false;
|
||||
nextTypeOrMatchColor = normalTypes[index + 1];
|
||||
} else {
|
||||
nextIsBomb = true;
|
||||
nextTypeOrMatchColor = normalTypes[0];
|
||||
}
|
||||
} else {
|
||||
int idx = Array.IndexOf(normalTypes, gem.MatchColor);
|
||||
if (idx < 0) idx = 0;
|
||||
|
||||
if (idx < normalTypes.Length - 1) {
|
||||
nextIsBomb = true;
|
||||
nextTypeOrMatchColor = normalTypes[idx + 1];
|
||||
} else {
|
||||
nextIsBomb = false;
|
||||
nextTypeOrMatchColor = normalTypes[0];
|
||||
}
|
||||
}
|
||||
|
||||
// Replace both model+view by releasing current and respawning at same position.
|
||||
ReleaseMatchedGems(position);
|
||||
SpawnGemGameObject(SetGemAt(position, nextTypeOrMatchColor, nextIsBomb), nextIsBomb);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ApplySwap(Vector2Int from, Vector2Int to) {
|
||||
Gem fromGem = this.gameBoard.GetGemAt(from);
|
||||
|
||||
Reference in New Issue
Block a user