Exemplo n.º 1
0
 public void UpdateSquares(Board instanceBoard)
 {
     for (int i = 0; i < _allSquares.LongLength; i++)
     {
         int    y = i % 15; //rows
         int    x = i / 15; //columns
         Square s = instanceBoard.Get(x, y);
         //remove tile
         BoardSquare thisGuy = _allSquares[x, y];
         thisGuy.MySquare   = s;
         thisGuy.PlacedTile = null;
         //add tile if exists
         if (!s.IsEmpty)
         {
             Scrabble.Core.Types.Tile t = (Scrabble.Core.Types.Tile)s.Tile;
             _allSquares[x, y].PlacedTile = new Tile(t.Letter.ToString(), t.Score);
         }
         else if (s.WordMultiplier > 0 || s.LetterMultiplier > 0)
         {
             //special square, need to display accordingly
             thisGuy.SquareContainer.Background = ("#" + s.Gradient).ToBrush();
         }
     }
     Redraw();
 }
Exemplo n.º 2
0
 public DisplayBoard()
 {
     InitializeComponent();
     
     //create list o' squares
     _allSquares = new BoardSquare[15, 15];
     //initialize them to blank/not null
     for (int i = 0; i < _allSquares.Length; i++) _allSquares[i/15,i%15] = new BoardSquare();
     
     Redraw();
 }
Exemplo n.º 3
0
        public DisplayBoard()
        {
            InitializeComponent();

            //create list o' squares
            _allSquares = new BoardSquare[15, 15];
            //initialize them to blank/not null
            for (int i = 0; i < _allSquares.Length; i++)
            {
                _allSquares[i / 15, i % 15] = new BoardSquare();
            }

            Redraw();
        }
Exemplo n.º 4
0
        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();
            }
        }
Exemplo n.º 5
0
        //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();
        }
Exemplo n.º 6
0
        public void Redraw()
        {
            BoardGrid.Children.Clear();
            System.Windows.GridLength g = new GridLength(40);

            for (int v = 0; v < 15; v++)
            {
                BoardGrid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = g
                });
                for (int h = 0; h < 15; h++)
                {
                    BoardGrid.ColumnDefinitions.Add(new ColumnDefinition()
                    {
                        Width = g
                    });
                    BoardSquare square = _allSquares[h, v];
                    if (v == 7 && h == 7)
                    {
                        square.Background = this.Resources["CenterSquare"] as Brush;
                    }
                    if (square.PlacedTile != null)
                    {
                        square.Redraw();
                    }

                    square.MyCoords = new Point(h, v);

                    BoardGrid.Children.Add(square);

                    //horiz(x), vert(y)
                    Grid.SetColumn(square, h);
                    Grid.SetRow(square, v);
                }
            }
        }