示例#1
0
 public static void RemoveUnit(UnitControl uc)
 {
     uc.Visibility = Visibility.Hidden;
     GameField.Children.Remove(uc);
     uc.Content     = null;
     uc.DataContext = null;
     uc.Opacity     = 1;
     uc             = null;
 }
示例#2
0
        private void SetupGame()
        {
            GameField.Children.Clear();
            ViewModel.ViewModel.CreateBoard();
            List <List <HexField> > board = ViewModel.ViewModel.Board.HexGrid;

            foreach (List <HexField> row in board)
            {
                foreach (HexField field in row)
                {
                    if (!(field == null))
                    {
                        HexTileControl tile = new HexTileControl();
                        tile.DataContext = field;
                        GameField.Children.Add(tile);
                    }
                }
            }
            ViewModel.ViewModel.CreateUnits();

            /*List<Unit> p1Units = ViewModel.ViewModel.Units;
             * foreach (Unit unit in p1Units)
             * {
             *  UnitControl unitControl = new UnitControl();
             *  unitControl.DataContext = unit;
             *  GameField.Children.Add(unitControl);
             * }*/
            List <Player> players = ViewModel.ViewModel.Players;

            foreach (Player player in players)
            {
                foreach (Unit unit in player.Units)
                {
                    UnitControl unitControl = new UnitControl();
                    unitControl.DataContext = unit;
                    GameField.Children.Add(unitControl);
                }
            }
            foreach (List <Overlay> overlayTiles in ViewModel.ViewModel.OverlayTiles)
            {
                foreach (Overlay overlay in overlayTiles)
                {
                    if (overlay == null)
                    {
                        continue;
                    }
                    else
                    {
                        InterfaceOverlay interfaceOverlay = new InterfaceOverlay();
                        interfaceOverlay.DataContext = overlay;
                        GameField.Children.Add(interfaceOverlay);
                    }
                }
            }
        }