Hello, I’m trying to figure out a good design for my problem: I have a match 3-like game, similar to candy crush but instead of moving the tiles you select them, you have different types of tiles: Health, Damage and Gold.
The problem i’m facing is how should I collect the values from the tiles? I have a list of selected tiles, damage tiles have a “damage” value and a multiplier (if you select 5+ tiles there’s a multiplied value) and the sum of the damages needs to be applied to the player.
Currently, when the user releases the touch screen I loop all tiles and pass to a method in the TileController the BoardController and the tile applies the damage to the player, this doesn’t sound like a great idea since I’m basically playing the “Hurt” animation of the player multiple times instead of one.
My other idea was to simply put a switch in the BoardController and check the tile type and there I have access to all fields and I can simply count the number of tiles and sum the damages and then multiply the multiplier. What do you think? Is there any other good way?
public override void Apply(RoomController room, bool isLast) {
base.Apply(room, isLast);
var enemy = room.GetSelectedEnemy();
if (enemy != null) {
room.accumulators["Damage"] += enemy.damage;
if (isLast) {
enemy.EditHealth(-room.accumulators["Damage"]);
room.accumulators["Damage"] = 0;
}
}
}
This is part of my DamageTileController, the RoomController is what I’ve called the BoardController in the previous comment
While this is the part in my RoomController where I apply the effect of the tile
for (int i = 0; i < selectedTiles.Count; i++) {
var tile = selectedTiles[i];
tile.Apply(room, i == selectedTiles.Count - 1);
tiles[tile.y, tile.x] = null;
Destroy(tile.gameObject);
}
I’m not sure I understand your question. Traditionally for any grid-based game (such as Match3) you make the entire game played inside a 2D array in your code, and whatever you like to use for each cell, such as an integer constant, or string, or whatever you like.
Then the actual Unity3D side of things (GameObjects, etc.) would only show the current state of the internal logic board, the current state of the partially-dragged object, and of course any animations you would do for matches or misses. The actual logic of “did these two tiles match?” would only be called at the very instant the user lifts his finger to complete the slide-move.