public Game(Map Map) { this.Map = Map; this.Rounds = 1; }
public void RefreshMap(Map Map) { /* RefreshMap routine does the following for every map field * - unit positions * - building fraction * - unit health * - unit move-range remaining * - events */ HideRecruitmentMenu(); if (Fields == null) // first time { Canvas_Outer.Height = Map.Dimensions.Y * FieldSize; Canvas_Outer.Width = Map.Dimensions.X * FieldSize; Image_Map.Height = Map.Dimensions.Y * FieldSize; Image_Map.Width = Map.Dimensions.X * FieldSize; Fields = new Canvas[Map.Dimensions.X][]; for (int i = 0; i < Map.Dimensions.X; i++) { Fields[i] = new Canvas[Map.Dimensions.Y]; } } for (int Rows = 0; Rows < Map.Dimensions.Y; Rows++) // Y { for (int Columns = 0; Columns < Map.Dimensions.X; Columns++) // X { Canvas OldCanvas = Fields[Columns][Rows]; Canvas NewCanvas = new Canvas(); NewCanvas.Margin = new Thickness(FieldSize * Columns, FieldSize * Rows, Map.Dimensions.X * FieldSize - FieldSize * Columns, Map.Dimensions.Y * FieldSize - FieldSize * Rows); // check for building in current field Building BuildingInCurrentField = Map.GetBuildingByCoord(new Coord(Columns, Rows)); string BuildingNameString = ""; if (BuildingInCurrentField != null) { BuildingNameString = "\n" + R.String(BuildingInCurrentField.GetName()); if (BuildingInCurrentField.Fraction != Fraction.Neutral) { // fraction flag Image Flag = new Image(); string FractionFlagName = "Saracens"; if (BuildingInCurrentField.Fraction == Fraction.Crusaders) FractionFlagName = "Crusaders"; Flag.Source = new BitmapImage(new Uri(@"Resources\Flags\" + FractionFlagName + ".jpg", UriKind.Relative)); Flag.Margin = new Thickness(FieldSize - 16 - 1, 1, 1, FieldSize - 12 - 1); Flag.Width = 16; Flag.Height = 12; NewCanvas.Children.Add(Flag); } } // unit on coord // hp label and unit icon Image UnitIcon = null; if (GameControl.Game.UnitOnCoord(new Coord(Columns, Rows))) { Unit UnitOnCoord = GameControl.Game.GetUnitByCoord(new Coord(Columns, Rows)); if (UnitOnCoord.AnimatedMovesRemaining.Count == 0) { // not animated at the moment Label HealthPoints, RangeLeft, RangeUsed; GetUnitCanvasContent(UnitOnCoord, out HealthPoints, out RangeLeft, out RangeUsed, out UnitIcon); NewCanvas.Children.Add(HealthPoints); NewCanvas.Children.Add(RangeLeft); NewCanvas.Children.Add(RangeUsed); if (UnitIcon != null) NewCanvas.Children.Add(UnitIcon); } } // name label Label Name = new Label(); Name.Name = "Label_Name"; string UnitNameString = ""; if (GameControl.Game.UnitOnCoord(new Coord(Columns, Rows))) UnitNameString = "\n" + GameControl.Game.GetUnitByCoord(new Coord(Columns, Rows)).GetType().Name; // Name.Content = /*BuildingNameString + */UnitNameString; Name.Width = FieldSize; Name.Height = FieldSize; Name.HorizontalContentAlignment = HorizontalAlignment.Center; Name.VerticalAlignment = VerticalAlignment.Top; Name.Background = new SolidColorBrush(Map.Ground[Columns][Rows].GetColor()); Name.Background.Opacity = 0; Name.BorderBrush = new SolidColorBrush(Color.FromRgb(80, 80, 80)); NewCanvas.Children.Add(Name); // events Name.MouseLeftButtonUp += new MouseButtonEventHandler(MapSegmentClicked); Name.MouseEnter += new MouseEventHandler(MapSegmentHovered); Name.MouseLeave += new MouseEventHandler(MapSegmentLeft); Canvas_Map.Children.Remove(OldCanvas); Canvas_Map.Children.Add(NewCanvas); Fields[Columns][Rows] = NewCanvas; } } DisplayClickedFieldInfo(ShownUnit); DisplayClickedFieldInfo(ShownBuilding); }