//drag/drop protected override void OnMouseDown(MouseButtonEventArgs e) { Tiles t = UtilityFunctions.GetAncestorOfType <Tiles>(this); GameWindow w = UtilityFunctions.GetAncestorOfType <GameWindow>(this); if (t != null || ((w != null) && w.WordInPlay.ContainsValue(this))) { DataObject thisTileData = new DataObject("scTile", this); DragDrop.DoDragDrop(this, thisTileData, DragDropEffects.Move); } }
public bool Put(Tile sqToPlace) { if (PlacedTile == null) { PlacedTile = sqToPlace; UtilityFunctions.GetAncestorOfType <GameWindow>(this).WordInPlay.Add( this.MyCoords, sqToPlace); return(true); } else { MessageBox.Show("There's already a tile there. Wrong game, dude."); return(false); } }
void Tiles_Drop(object sender, DragEventArgs e) { Tile t = (Tile)e.Data.GetData("scTile"); if (UtilityFunctions.GetAncestorOfType <Canvas>(t) != null) { Canvas squareCnt = (Canvas)t.Parent; squareCnt.Children.Clear(); BoardSquare thisSquare = (BoardSquare)squareCnt.Parent; thisSquare.PlacedTile = null; UtilityFunctions.GetAncestorOfType <GameWindow>(thisSquare).WordInPlay.Remove(thisSquare.MyCoords); PlayerTiles.Add(t); Redraw(); } }
//drag/drop code void BoardSquare_Drop(object sender, DragEventArgs e) { Tile t = (Tile)e.Data.GetData("scTile"); if (UtilityFunctions.GetAncestorOfType <Tiles>(t) != null) { StackPanel letterTray = (StackPanel)t.Parent; Grid layout = (Grid)letterTray.Parent; Tiles these = (Tiles)layout.Parent; these.PlayerTiles.Remove(t); letterTray.Children.Remove(t); if (!Put(t)) { //put stuff back noob these.PlayerTiles.Add(t); letterTray.Children.Add(t); } } else if (UtilityFunctions.GetAncestorOfType <BoardSquare>(t) != null) { BoardSquare other = UtilityFunctions.GetAncestorOfType <BoardSquare>(t); other.PlacedTile = null; other.SquareContainer.Children.Clear(); if (!Put(t)) { other.PlacedTile = t; other.SquareContainer.Children.Add(t); } UtilityFunctions.GetAncestorOfType <GameWindow>(this).WordInPlay.Remove(other.MyCoords); } //change bg back SquareContainer.Background = ("#" + MySquare.Gradient).ToBrush(); Redraw(); }