Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
0
        public MahjongTile CreateTile(int X, int Y, int Z, int TileIndex)
        {
            MahjongTile Tile = new MahjongTile(TileIndex);

            TileStore[X, Y, Z]       = Tile;
            Tile.TileVector          = new Vector(X, Y, Z);
            Tile.TileCanvas.Location = new Point(X * 43 - (Z * 5), Y * 61 - (Z * 5));
            Tile.OnTileClicked      += OnTileClicked;
            WindowHandle.Controls.Add(Tile.TileCanvas);
            WindowHandle.Controls.SetChildIndex(Tile.TileCanvas, 0);

            return(Tile);
        }