public LifeDisplay(Canvas canvas, Game game) { this.canvas = canvas; this.game = game; int healthBarY = 15; int healthBarWidth = 280; int healthBarHeight = 40; int playerHealthX = 22; Canvas.SetLeft(playerBarBG, playerHealthX); Canvas.SetTop(playerBarBG, healthBarY); playerBarBG.Width = healthBarWidth; playerBarBG.Height = healthBarHeight; playerBarBG.Fill = new SolidColorBrush(Color.FromArgb(128, 255, 0, 0)); canvas.Children.Add(playerBarBG); Canvas.SetLeft(playerBarFG, playerHealthX); Canvas.SetTop(playerBarFG, healthBarY); playerBarFG.Width = healthBarWidth; playerBarFG.Height = healthBarHeight; playerBarFG.Fill = new SolidColorBrush(Color.FromArgb(255, 0, 0, 255)); canvas.Children.Add(playerBarFG); Canvas.SetLeft(playerLife, playerHealthX + 10); Canvas.SetTop(playerLife, healthBarY); playerLife.Text = "Player Life"; playerLife.Width = healthBarWidth; playerLife.Height = healthBarHeight; playerLife.FontSize = 28; playerLife.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)); canvas.Children.Add(playerLife); int enemyHealthX = 338; Canvas.SetLeft(enemyBarBG, enemyHealthX); Canvas.SetTop(enemyBarBG, healthBarY); enemyBarBG.Width = healthBarWidth; enemyBarBG.Height = healthBarHeight; enemyBarBG.Fill = new SolidColorBrush(Color.FromArgb(128, 255, 0, 0)); canvas.Children.Add(enemyBarBG); Canvas.SetRight(enemyBarFG, playerHealthX); Canvas.SetTop(enemyBarFG, healthBarY); enemyBarFG.Width = healthBarWidth; enemyBarFG.Height = healthBarHeight; enemyBarFG.Fill = new SolidColorBrush(Color.FromArgb(255, 0, 0, 255)); canvas.Children.Add(enemyBarFG); Canvas.SetLeft(enemyLife, enemyHealthX + 10); Canvas.SetTop(enemyLife, healthBarY); enemyLife.Text = "Enemy Life"; enemyLife.Width = healthBarWidth; enemyLife.Height = healthBarHeight; enemyLife.FontSize = 28; enemyLife.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)); canvas.Children.Add(enemyLife); }
public MapDisplay(Canvas canvas, Game game) { this.canvas = canvas; this.game = game; // TODO don't know if this should be hardcoded or calculated by some other means int panelWidth = 300; int panelHeight = 300; // Calculate map position int panelLeftX = ((int)canvas.Width - panelWidth) >> 1; int panelTopY = ((int)canvas.Height - panelHeight) >> 1; mapBG = new Rectangle(); mapBG.Height = panelHeight; mapBG.Width = panelWidth; Canvas.SetTop(mapBG, panelTopY); Canvas.SetLeft(mapBG, panelLeftX); mapBG.Fill = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)); int titleHeight = 50; mapTitle = new TextBlock(); mapTitle.Text = "Map"; mapTitle.FontSize = 28; mapTitle.Width = panelWidth; mapTitle.Height = titleHeight; Canvas.SetTop(mapTitle, panelTopY); Canvas.SetLeft(mapTitle, panelLeftX); mapTitle.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; rooms = new Rectangle[Game.mapWidth, Game.mapHeight]; int gapWidth = 20; int cellWidth = (panelWidth - (gapWidth * (Game.mapWidth + 1))) / Game.mapWidth; int gapHeight = 20; int cellHeight = (panelHeight - (gapHeight * (Game.mapHeight + 1)) - titleHeight) / Game.mapHeight; for (int i = 0; i < Game.mapWidth; i++) { for (int j = 0; j < Game.mapHeight; j++) { rooms[i, j] = new Rectangle(); rooms[i, j].Height = cellHeight; rooms[i, j].Width = cellWidth; // y = 0 is map bottom Canvas.SetTop(rooms[i, j], panelTopY + panelHeight - j * (cellHeight + gapHeight) - gapHeight - cellHeight); Canvas.SetLeft(rooms[i, j], panelLeftX + i * (cellWidth + gapWidth) + gapWidth); } } }