private static BitmapImage GetSoldierImage(Spike spike) { string path = $"Images/{(spike.Black ? "Black" : "White")}Player.png"; BitmapImage image = new BitmapImage(); image.BeginInit(); image.UriSource = new Uri(path, UriKind.Relative); image.EndInit(); return(image); }
public MainWindow() { InitializeComponent(); LogicBoard = new Board(); UiBoard = new UiSpikeElement[2, 12]; Board.RollCubeEvent += BoardOnRollCubeEvent; for (int i = 0; i < 2; i++) { for (int j = 0; j < 12; j++) { Spike spike = LogicBoard[i, j]; UiBoard[i, j] = new UiSpikeElement(i, j); UiBoard[i, j].MouseDown += OnMouseDown; // UiBoard[i, j].MouseEnter += OnMouseEnter; // UiBoard[i, j].MouseLeave += OnMouseLeave; SetInGrid(UiBoard[i, j], i, j); UiBoard[i, j].Update(spike); } } }
public void Update(Spike spike) { StackPanel stackPanel = new StackPanel(); if (spike.SoldiersCount > 5) { if (Row == 1) { stackPanel.Children.Add(new Label { Content = spike.SoldiersCount, HorizontalAlignment = HorizontalAlignment.Center, FontSize = 25, Foreground = spike.Black ? Brushes.White : Brushes.Black, HorizontalContentAlignment = HorizontalAlignment.Center, Height = Size, Width = Size, Background = new ImageBrush { ImageSource = GetSoldierImage(spike), Stretch = Stretch.UniformToFill } }); } for (int i = 0; i < 4; i++) { stackPanel.Children.Add(new Image { Source = GetSoldierImage(spike), Height = Size, Width = Size }); } if (Row == 0) { stackPanel.Children.Add(new Label { Content = spike.SoldiersCount, HorizontalAlignment = HorizontalAlignment.Center, FontSize = 25, HorizontalContentAlignment = HorizontalAlignment.Center, Foreground = spike.Black ? Brushes.White : Brushes.Black, Height = Size, Width = Size, Background = new ImageBrush { ImageSource = GetSoldierImage(spike), Stretch = Stretch.UniformToFill } }); } } else { for (int i = 0; i < spike.SoldiersCount; i++) { stackPanel.Children.Add(new Image { Source = GetSoldierImage(spike), Height = Size, Width = Size }); } } Content = stackPanel; VerticalContentAlignment = Row == 0 ? VerticalAlignment.Top : VerticalAlignment.Bottom; BitmapImage image = new BitmapImage(); if (spike.Marked) { image = GetMarkedImage(Row, Column); } else if (spike.PreviewMode) { image = GetPreviewImage(Row, Column); } else if (spike.OutMode) { image = GetOutModeImage(Row, Column); } else { image = GetBackgroundImage(Row, Column); } Background = new ImageBrush { ImageSource = image }; }