private StarSystem initGameState()
 {
     StarSystem result= GameState.StarSystems.First();
     List<StarSystem> StartingSystems = new List<StarSystem>();
     using(RNG rng = new RNG())
     foreach(Player p in GameState.Players)
     {
         StarSystem startingSystem = GameState.StarSystems[rng.d(GameState.StarSystems.Count()-1)];
         while(StartingSystems.Contains(startingSystem))
             startingSystem = GameState.StarSystems[rng.d(GameState.StarSystems.Count()-1)];
         StartingSystems.Add(startingSystem);
         p.HomeSystem = startingSystem;
         if (p == GameState.Players.First())
             result = startingSystem;
         Planet startingPlanet;
         if (startingSystem.Planets.Count < 2)
             startingPlanet = startingSystem.Planets.First();
         else
         {
             int index = rng.d(startingSystem.Planets.Count-1);
             startingPlanet = startingSystem.Planets[index];
         }
         startingPlanet.Owner = p;
         // init planet here later
         foreach(Ship s in p.Ships)
         {
             s.StrategicSystem = startingSystem;
             s.StrategicPosition = startingPlanet.StrategicPosition;
             startingSystem.StrategicLocations[startingPlanet.StrategicPosition.X, startingPlanet.StrategicPosition.Y].Ships.Add(s);
         }
     }
     return result;
 }
Example #2
0
        private void AddPlanetToSystem(StarSystem newSystem, int planetNumber)
        {
            using(RNG rng = new RNG())
            {
                int planetType = rng.d(6);
                string planetURL;
                switch(planetType)
                {
                    case 1:
                        planetURL = "Images\\Planets\\GreenPlanet.png";
                        break;
                    case 2:
                        planetURL = "Images\\Planets\\RedPlanet.png";
                        break;
                    case 3:
                        planetURL = "Images\\Planets\\PurplePlanet.png";
                        break;
                    case 4:
                        planetURL = "Images\\Planets\\BluePlanet.png";
                        break;
                    case 5:
                        planetURL = "Images\\Planets\\GasPlanet.png";
                        break;
                    case 6:
                        planetURL = "Images\\Planets\\GrayPlanet.png";
                        break;
                    default:
                        planetURL = "Images\\Planets\\IcePlanet.png";
                        break;
                }
                Planet newPlanet = new Planet(planetURL);
                newPlanet.Name=string.Format("{0} {1}",newSystem.Name,ToRoman(planetNumber));

                bool isOccupied = true;
                int x=1;
                int y = 1;
                while (isOccupied)
                {
                    //determine which edge
                    x = rng.d(StrategicGridDimension - 2);
                    y = rng.d(StrategicGridDimension - 2);

                    if (newSystem.StrategicLocations[x, y].Stellars.Count==0)
                        isOccupied = false;
                }

                newPlanet.StrategicPosition = new System.Drawing.Point(x, y);

                newSystem.StrategicLocations[x, y].Stellars.Add(newPlanet);
            }
        }
Example #3
0
        Game initNewGame()
        {
            Game result = new Game();
            result.StarSystems = new StarSystemCollection();

            // setup systems
            using (StreamReader reader = File.OpenText("Settings\\StarSystems.txt"))
            {
                using (RNG rng = new RNG())
                {
                    for (int i = 0; i < 20; i++)
                    {
                        StarSystem newSystem = new StarSystem(StrategicGridDimension,StrategicGridDimension);

                        // system name
                        newSystem.Name = reader.ReadLine();

                        // galactic location
                        int newX = Convert.ToInt32(rng.d(GalacticGridDimension - 1));
                        int newY = Convert.ToInt32(rng.d(GalacticGridDimension - 1));
                        newSystem.GalacticCoordinates = new System.Drawing.Point(newX, newY);

                        // Star
                        Star newStar = initStar(newSystem.Name);
                        newSystem.StrategicLocations[StrategicGridDimension / 2, StrategicGridDimension / 2].Stellars.Add(newStar);

                        // Planets
                        int numPlanets = rng.d(StartingPlanetsMax);
                        for (int np = 0; np < numPlanets; np++)
                        {
                            AddPlanetToSystem(newSystem,np+1);
                        }
                        result.StarSystems.Add(newSystem);
                    }
                }
            }

            // setup 1-N warp points per system
            foreach(StarSystem system in result.StarSystems)
            {
                int rand = 1;
                using (RNG rng = new RNG())
                {
                    rand = rng.d(StartingWarpPointsMax-1) + 1;
                }
                int attempts = 0;
                while(system.GetCountOfWarpPoints()<rand && attempts<StartingWarpPointsMax+1)
                {
                    AddWarpPointToSystem(result, system);
                    attempts++;
                }
            }

            return result;
        }
Example #4
0
 private static Star initStar(string name)
 {
     using (RNG rng = new RNG())
     {
         int starColor = rng.d(5);
         string starURL;
         switch (starColor)
         {
             case 1:
                 starURL = "Images\\Stars\\RedStar.png";
                 break;
             case 2:
                 starURL = "Images\\Stars\\YellowStar.png";
                 break;
             case 3:
                 starURL = "Images\\Stars\\PurpleStar.png";
                 break;
             case 4:
                 starURL = "Images\\Stars\\GreenStar.png";
                 break;
             case 5:
                 starURL = "Images\\Stars\\BlueStar.png";
                 break;
             default:
                 starURL = "Images\\Stars\\DarkStar.png";
                 break;
         }
         Star newStar = new Star(starURL);
         newStar.Name = name;
         return newStar;
     }
 }
Example #5
0
        private static System.Drawing.Point WarpPointLocation(StarSystem targetSystem)
        {
            int x = -1;
            int y = -1;
            using (RNG rng = new RNG())
            {
                bool isOccupied = true;
                while (isOccupied)
                {
                    //determine which edge
                    int side = rng.d(4);

                    switch (side)
                    {
                        case 1:
                            x = 0;
                            y = rng.d(StrategicGridDimension - 1);
                            break;
                        case 2:
                            x = rng.d(StrategicGridDimension - 1);
                            y = 0;
                            break;
                        case 3:
                            x = StrategicGridDimension - 1;
                            y = rng.d(StrategicGridDimension - 1);
                            break;
                        case 4:
                            x = rng.d(StrategicGridDimension - 1);
                            y = StrategicGridDimension - 1;
                            break;
                    }
                    if (!targetSystem.StrategicLocations[x, y].Stellars.Any(f => f is WarpPoint))
                        isOccupied = false;
                }
            }
            System.Drawing.Point result = new System.Drawing.Point(x, y);
            return result;
        }
        void ShowSystemMap(StarSystem system)
        {
            txbSelectedSystemName.Text = system.Name;
            txbSelectedSystemCoords.Text = "";
            initGrid(grdLocalSystem, StrategicGridDimension, StrategicGridDimension);
            SystemContextImages = new Image[StrategicGridDimension, StrategicGridDimension];
            txbSystemName.Text = system.Name;
            using (RNG rng = new RNG())
            {
                for (int x = 0; x < StrategicGridDimension; x++)
                {
                    for (int y = 0; y < StrategicGridDimension; y++)
                    {
                        AddBackgroundImage(grdLocalSystem, x, y, rng.d(4), true);
                        AddShipImages(system, x, y);
                        AddSystemContextMenuImage(x, y, LocalContextMenuImage_MouseDown);

                        if (system.StrategicLocations[x, y].Stellars.Count > 0)
                        {
                            try
                            {
                                AddStellars(system.StrategicLocations[x, y], x, y);
                            }
                            catch { MessageBox.Show("error in system images"); }
                        }

                    }
                }
            }
        }
        void initGalaxyMap()
        {
            initGrid(grdGalaxyView, GalacticGridDimension, GalacticGridDimension);
            using (RNG rng = new RNG())
            {
                for (int x = 0; x < GalacticGridDimension; x++)
                {
                    for (int y = 0; y < GalacticGridDimension; y++)
                    {
                        AddBackgroundImage(grdGalaxyView, x, y, rng.d(4),false);
                        AddGalaxyGridImage(x, y);
                        AddGalaxyContextMenuImage(x, y, GalaxyContextMenuImage_MouseDown);

                        if (GameState.StarSystems.Any(f=>f.GalacticCoordinates.X==x&&f.GalacticCoordinates.Y==y))
                        {
                            try
                            {
                                AddSystemImages(x, y);
                            }
                            catch { MessageBox.Show("error in system images"); }
                        }

                    }
                }
            }
            AddWarpPointPaths(grdGalaxyView);
        }
Example #8
0
        /// <summary>
        /// Handles incoming damage to teh Ship through any equipped DefenseParts, including resistance based on damage type
        /// </summary>
        /// <param name="Damage">Amount of damage to take</param>
        /// <param name="DamageType">Type of damage to take (Data Driven)</param>
        /// <returns>List of status results from DefenseParts</returns>
        public List<string> HitFor(int Damage, string DamageType)
        {
            List<string> result = new List<string>();

            foreach (DefensePart defense in Parts.Where(f => f is DefensePart && !f.IsDestroyed))
            {
                DefenseResult res = defense.TakeHit(Damage);
                Damage = res.Remainder;
                foreach (string message in res.Messages)
                    result.Add(string.Format(" ==> {0}",message));
                if (Damage <= 0)
                    break;
            }

            if (Damage > 0)
            {
                HP.Current -= Damage;
                result.Add(string.Format("{0} Damage made it through!", Damage));
                // chance to destroy ship part
                using (RNG rand = new RNG())
                {
                    int countOfEquipment = Parts.Count * 2;
                    int random = rand.d(countOfEquipment);
                    if (random <= Parts.Count)
                    {
                        if (!Parts[random - 1].IsDestroyed)
                        {
                            Parts[random - 1].IsDestroyed = true;
                            result.Add(string.Format("{0} is destroyed by the damage!", Parts[random - 1].Name));
                        }
                    }

                }
                if (HP.Current <= 0)
                {
                    if (OnShipDestroyed != null)
                    {
                        OnShipDestroyed(this, new EventArgs(), this);
                    }
                    _isDestroyed = true;
                }
            }

            return result;
        }
Example #9
0
        Game initNewGame()
        {
            Game result = new Game();
            result.StarSystems = new StarSystemCollection();

            // setup systems
            using (RNG rng = new RNG())
            {
                for (int i = 0; i < 10000; i++)
                {
                    StarSystem newSystem = new StarSystem(StrategicGridDimension, StrategicGridDimension);

                    // system name
                    newSystem.Name = (i + 1).ToString();

                    // galactic location
                    int newX = Convert.ToInt32(rng.d(GalacticGridDimension - 1));
                    int newY = Convert.ToInt32(rng.d(GalacticGridDimension - 1));
                    newSystem.GalacticCoordinates = new System.Drawing.Point(newX, newY);

                    result.StarSystems.Add(newSystem);
                    Debug.WriteLine(string.Format("Building system {0} complete...", newSystem.Name));
                }
            }

            // setup 1-N warp points per system
            foreach (StarSystem system in result.StarSystems)
            {
                int rand = 1;
                using (RNG rng = new RNG())
                {
                    rand = rng.d(StartingWarpPointsMax - 1) + 1;
                }
                Debug.WriteLine("Building {0} warp points in system {1}...", rand, system.Name);
                while (system.GetCountOfWarpPoints() < rand)
                {
                    AddWarpPointToSystem(result, system);
                }
            }

            return result;
        }
Example #10
0
 private void DrawShipFiringBeam(System.Drawing.Point sourceLoc, System.Drawing.Point targetLoc)
 {
     try
     {
         using (RNG rng = new RNG())
         {
             try
             {
                 // random origin and target (to offset beams)
                 Point origin = new Point(((sourceLoc.Y + 1) * 32) - (8 + rng.d(16)), ((sourceLoc.X + 1) * 32) + (rng.d(16)));
                 Point target = new Point(((targetLoc.Y + 1) * 32) - (8 + rng.d(16)), ((targetLoc.X + 1) * 32) + (rng.d(16)));
                 System.Windows.Shapes.Path beam = new System.Windows.Shapes.Path();
                 beam.Stroke = Brushes.Red;
                 beam.StrokeThickness = 1;
                 Point from = TransformToVisual(c).Transform(origin);
                 Point to = TransformToVisual(c).Transform(target);
                 beam.Data = new LineGeometry(from, to);
                 // add and remove actions
                 Action<System.Windows.Shapes.Path> addWeaponAction = new Action<System.Windows.Shapes.Path>(addWeaponPath);
                 Action<System.Windows.Shapes.Path> removeWeaponAction = new Action<System.Windows.Shapes.Path>(removeWeaponPath);
                 // random firing delay, 300-600ms
                 int firingdelay = 100 + rng.d(100);
                 DisplayBeamFiring(addWeaponAction, removeWeaponAction, beam, firingdelay);
             }
             catch (Exception ex)
             {
                 if (LogEverything)
                     Logger(ex);
             }
         }
     }
     catch (Exception ex)
     {
         if (LogEverything)
             Logger(ex);
     }
 }
Example #11
0
        void BuildMap()
        {
            try
            {
                g.Children.Clear();
                currentPlayer = GameState.Players[0];
                txbCurrentPlayer.Text = currentPlayer.Name;
                imgCurrentPlayerIcon.Source = currentPlayer.Icon.Source;
                currentShip = currentPlayer.Ships[0];

                using (RNG rng = new RNG())
                {
                    for (int x = 0; x < GridDimensionX; x++)
                    {
                        for (int y = 0; y < GridDimensionY; y++)
                        {
                            AddBackgroundImage(x, y, rng.d(4));
                            AddContextMenuImage(x, y);
                            AddShipImages(x, y);
                            //AddLabel(x, y);

                            if (GameState.CombatLocations[x, y].IsBlocked)
                            {
                                try
                                {
                                    AddBlockedImage(x, y);
                                }
                                catch { MessageBox.Show("error in blocked images"); }
                            }
                        }
                    }
                }

                // highlight next player's ship
                AddHighlightImage(currentShip.TacticalPosition.X, currentShip.TacticalPosition.Y);

                ShowShipStatus(currentShip, spCurrentShip);
                lbxTargetShips.ItemsSource = SelectedLocShips;
                lbxTargetShips.UpdateLayout();
            }
            catch (Exception ex)
            {
                if (LogEverything)
                    Logger(ex);
            }
        }
Example #12
0
        void initShipDetails()
        {
            try
            {
                int RangeSize = ((GridDimensionX - 1) / GameState.Players.Count);
                using (RNG rng = new RNG())
                {
                    for (int i = 0; i < GameState.Players.Count; i++)
                    {
                        Player player = GameState.Players[i];
                        int XRangeMin = RangeSize * i;
                        int XRangeMax = (RangeSize * (i + 1)) - 1;

                        foreach (Ship ship in player.Ships)
                        {
                            bool validLoc = false;
                            int x = 0;
                            int y = 0;
                            while (!validLoc)
                            {
                                x = rng.d(GridDimensionX - 1);
                                y = rng.d(GridDimensionY - 1);
                                if (!GameState.CombatLocations[x, y].IsBlocked && XRangeMin <= x && x <= XRangeMax)
                                    validLoc = true;
                            }
                            GameState.CombatLocations[x, y].Ships.Add(ship);
                            ship.Origin = new System.Drawing.Point(x, y);
                            ship.TacticalPosition = new System.Drawing.Point(x, y);

                            ship.OnShipDestroyed += new StarShips.Delegates.ShipDelegates.ShipDestroyedEvent(onShipDestroyedHandler);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (LogEverything)
                    Logger(ex);
            }
        }