public static void SelectTile(int xPos, int yPos, TileTab tab, int clicks) { var ti = TileHandler.GetTileImage(tab); var tileSize = ti.TileSize; int originalIndex = TileHandler.GetTileIndex(xPos, yPos, tab); int index = ti.ColumnsPerRow * yPos + xPos; if (xPos >= ti.Image.Width / tileSize || yPos >= ti.Image.Height / tileSize) { return; } if (clicks == 1) { if (SelectedTiles.Contains(index)) { SelectedTiles.Remove(index); } else { SelectedTiles.Add(index); } } else { switch (tab) { case TileTab.Source: { TileHandler.SelectedTile = originalIndex; break; } case TileTab.Randomized: { TileHandler.SelectedTile = RandomizedMap[xPos, yPos]; break; } case TileTab.RuleTest: { TileHandler.SelectedTile = RuleTestMap[xPos, yPos]; break; } } } }
public static void SelectAll(TileTab tab) { DeselectAll(tab); for (int i = 0; i <= GetTileImage(tab).NumberOfTiles - 1; i++) { SelectedTiles.Add(i); } }
public void OnTileClicked(object sender, MahjongTile ClickedTile) { SelectedTiles.Add(ClickedTile); if (SelectedTiles.Count == 2) { if (SelectedTiles[0] == SelectedTiles[1]) { SelectedTiles.RemoveAt(1); return; } int x1 = SelectedTiles[0].TileVector.X; int y1 = SelectedTiles[0].TileVector.Y; int z1 = SelectedTiles[0].TileVector.Z; int x2 = SelectedTiles[1].TileVector.X; int y2 = SelectedTiles[1].TileVector.Y; int z2 = SelectedTiles[1].TileVector.Z; bool FirstTileAccessible = TileStore[x1 - 1, y1, z1] == null || TileStore[x1 + 1, y1, z1] == null; bool SecondTileAccessible = TileStore[x2 - 1, y2, z2] == null || TileStore[x2 + 1, y2, z2] == null; bool SameTile = SelectedTiles[0].GetTileIndex() == SelectedTiles[1].GetTileIndex(); if (FirstTileAccessible && SecondTileAccessible && SameTile) { Console.WriteLine("Tile able to destroy"); } else { SelectedTiles[0].IsHovered = false; SelectedTiles[0].IsClicked = false; SelectedTiles[0].TileCanvas.Invalidate(); SelectedTiles[1].IsHovered = false; SelectedTiles[1].IsClicked = false; SelectedTiles[1].TileCanvas.Invalidate(); SelectedTiles.Clear(); return; } WindowHandle.Controls.Remove(SelectedTiles[0].TileCanvas); WindowHandle.Controls.Remove(SelectedTiles[1].TileCanvas); TileStore[x1, y1, z1] = null; TileStore[x2, y2, z2] = null; SelectedTiles.Clear(); if (!CheckForCompletition()) { WindowHandle.PopulateBoard(WindowHandle); } } }
/// <summary> /// Adds selection icon to tile and stores reference to it /// </summary> /// <param name="selection"></param> void AddSelection(Transform selection) { //Dequeue inactive object from queue GameObject newSelectionIcon = InactiveSelectionObjects.Dequeue(); //Set object to active in scene newSelectionIcon.SetActive(true); //Sets new object to correct position newSelectionIcon.transform.position = selection.position; //Add new object to dictionary SelectedObjects.Add(selection, newSelectionIcon); //Add to active selection list ActiveSelectionIconObjects.Add(newSelectionIcon); //Add tile to current tiles selected SelectedTiles.Add(selection.gameObject); }