private void SendFleet(SilverlightControlPlanet planetFrom, SilverlightControlPlanet planetTo, int ships) { if (planetFrom.ShipNum > 0) { int send_ships = Math.Min(ships, planetFrom.ShipNum); SilverlightControlFleet fleet = new SilverlightControlFleet(); fleet.SetPlanets(planetFrom, planetTo); fleet.ShipNum = send_ships; if (GameDifficulty == Difficulty.Hard && planetFrom.Owner == PlanetOwner.Enemy) { fleet.Speed *= GameParameters.HARD_LEVEL_SPEED_MODIFIER; } fleet.SetValue(Canvas.LeftProperty, planetFrom.GetValue(Canvas.LeftProperty)); fleet.SetValue(Canvas.TopProperty, planetFrom.GetValue(Canvas.TopProperty)); fleets.Add(fleet); CanvasGame.Children.Add(fleet); planetFrom.ShipNum -= send_ships; } }
// Distance of two planets public double Distance(SilverlightControlPlanet planet) { double x1 = (double)this.GetValue(Canvas.LeftProperty); double y1 = (double)this.GetValue(Canvas.TopProperty); double x2 = (double)planet.GetValue(Canvas.LeftProperty); double y2 = (double)planet.GetValue(Canvas.TopProperty); return(PlanetMath.Distance(x1, y1, x2, y2)); }
private void SetFrame(SilverlightControlPlanet planet) { double x = (double)planet.GetValue(Canvas.LeftProperty) - 2; silverlightControlFrame.SetValue(Canvas.LeftProperty, x); double y = (double)planet.GetValue(Canvas.TopProperty) - 2; silverlightControlFrame.SetValue(Canvas.TopProperty, y); silverlightControlFrame.Width = planet.Width + 5; silverlightControlFrame.Height = planet.Height + 5; }
private void SetRadius(SilverlightControlPlanet planet) { if (planet.Owner == PlanetOwner.Player) { double x = (double)planet.GetValue(Canvas.LeftProperty) + planet.Width / 2.0 - silverlightControlRadius.Width / 2.0; silverlightControlRadius.SetValue(Canvas.LeftProperty, x); double y = (double)planet.GetValue(Canvas.TopProperty) + planet.Height / 2.0 - silverlightControlRadius.Height / 2.0; silverlightControlRadius.SetValue(Canvas.TopProperty, y); silverlightControlRadius.Visibility = Visibility.Visible; } else { silverlightControlRadius.Visibility = Visibility.Collapsed; } }
public void SetPlanets(SilverlightControlPlanet startplanet, SilverlightControlPlanet destplanet) { start = startplanet; destination = destplanet; double startx = (double)start.GetValue(Canvas.LeftProperty) + start.Width / 2.0 - this.Width / 2.0; double starty = (double)start.GetValue(Canvas.TopProperty) + start.Height / 2.0 - this.Height / 2.0; destx = (double)destination.GetValue(Canvas.LeftProperty) + destination.Width / 2.0 - this.Width / 2.0; desty = (double)destination.GetValue(Canvas.TopProperty) + destination.Height / 2.0 - this.Width / 2.0; xk = startx; yk = starty; double dx = destx - startx; double dy = desty - starty; double d = PlanetMath.Length(dx, dy); px = Speed * (dx / d); py = Speed * (dy / d); owner = start.Owner; if (owner == PlanetOwner.Player) { ImageFleet.Source = ship_player; } else { ImageFleet.Source = ship_enemy; } FleetRotate.Angle = PlanetMath.RotationAngle(startx, starty, destx, desty); IsActive = true; }