コード例 #1
0
        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;
            }
        }
コード例 #2
0
        private void silverlightControlPlanet_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (IsGameFinished())
            {
                return;
            }

            if (currentPlanet.Owner == PlanetOwner.Player)
            {
                SilverlightControlPlanet dest = sender as SilverlightControlPlanet;

                if (currentPlanet.Distance(dest) <= GameParameters.PLANET_RADIUS)
                {
                    int ships = (int)(currentPlanet.ShipNum * gameData.FleetPercent / 100.0);

                    SendFleet(currentPlanet, dest, ships);

                    SoundStart.Position = TimeSpan.Zero;
                    SoundStart.Play();
                }
                else
                {
                    SoundTooFar.Position = TimeSpan.Zero;
                    SoundTooFar.Play();
                }
            }

            e.Handled = true;
        }
コード例 #3
0
        private void CreateEdges()
        {
            for (int i = 0; i < galaxy.Planets.Count; i++)
            {
                SilverlightControlPlanet planet1 = galaxy.Planets[i];

                for (int j = i + 1; j < galaxy.Planets.Count; j++)
                {
                    SilverlightControlPlanet planet2 = galaxy.Planets[j];

                    if (planet1.Distance(planet2) <= GameParameters.PLANET_RADIUS)
                    {
                        Line l = new Line();

                        l.X1 = planet1.CenterX;
                        l.Y1 = planet1.CenterY;

                        l.X2 = planet2.CenterX;
                        l.Y2 = planet2.CenterY;

                        l.Stroke          = new SolidColorBrush(Colors.White);
                        l.StrokeThickness = 1.0;

                        l.StrokeDashArray = new DoubleCollection()
                        {
                            1, 5
                        };

                        CanvasGame.Children.Add(l);
                    }
                }
            }
        }
コード例 #4
0
        // 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));
        }
コード例 #5
0
        private void silverlightControlPlanet_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            currentPlanet = sender as SilverlightControlPlanet;
            SetFrame(currentPlanet);
            SetRadius(currentPlanet);
            SetFace(currentPlanet);
            SetEdges(currentPlanet);

            silverlightControlInfoPanel.DataContext = sender;

            SoundClick.Position = TimeSpan.Zero;
            SoundClick.Play();
        }
コード例 #6
0
        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;
        }
コード例 #7
0
        void NewGame()
        {
            if (timerGame != null)
            {
                timerGame.Stop();
            }

            if (timerTime != null)
            {
                timerTime.Stop();
            }

            RemoveGameElements();

            gameData = new GameData();
            gameData.FleetPercent = 50;

            galaxy = new Galaxy(CanvasGame);
            galaxy.MouseLeftButtonDown  = silverlightControlPlanet_MouseLeftButtonDown;
            galaxy.MouseRightButtonDown = silverlightControlPlanet_MouseRightButtonDown;

            galaxy.Generate();

            // Hard level: more enemy planets
            if (GameDifficulty == Difficulty.Hard)
            {
                galaxy.AddEnemyPlanets(GameParameters.HARD_LEVEL_PLANET_NUM);
            }

            // Ez a SetEdges ele kell!
            currentPlanet = galaxy.GetFirstPlanet();

            CreateEdges();
            SetEdges(currentPlanet);

            fleets = new Fleets();

            SetFrame(currentPlanet);
            SetRadius(currentPlanet);
            SetFace(currentPlanet);
            silverlightControlInfoPanel.DataContext = currentPlanet;

            silverlightControlGameInfo.DataContext = gameData;

            gameTime           = new DateTime(2011, 01, 01, 0, 0, 0);
            TextBlockTime.Text = gameTime.ToString("HH:mm:ss");

            silverlightControlFrame.Visibility = Visibility.Visible;
        }
コード例 #8
0
        private void SetFace(SilverlightControlPlanet planet)
        {
            switch (planet.Owner)
            {
            case PlanetOwner.Player:
                ImageFace.Source = face_player;
                break;

            case PlanetOwner.Enemy:
                ImageFace.Source = face_enemy;
                break;

            case PlanetOwner.Neutral:
                ImageFace.Source = face_neutral;
                break;
            }
        }
コード例 #9
0
        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;
            }
        }
コード例 #10
0
        private void SetEdges(SilverlightControlPlanet planet)
        {
            foreach (UIElement item in CanvasGame.Children)
            {
                if (item is Line)
                {
                    try
                    {
                        Line l = item as Line;

                        if ((l.X1 == planet.CenterX && l.Y1 == planet.CenterY) ||
                            (l.X2 == planet.CenterX && l.Y2 == planet.CenterY))
                        {
                            // Kikenyszeritjuk az ujrarajzolast
                            l.Visibility = Visibility.Collapsed;

                            if (edgeShowType != 0)
                            {
                                l.Visibility = Visibility.Visible;
                            }
                        }
                        else
                        {
                            l.Visibility = Visibility.Collapsed;

                            if (edgeShowType == 2)
                            {
                                l.Visibility = Visibility.Visible;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            }
        }
コード例 #11
0
        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;
        }