Ejemplo n.º 1
0
        public string Fire()
        {
            string result = string.Empty;
            using (RNG rng = new RNG())
            {
                int hitNum = rng.d100();

                if (hitNum >= 96) // 96-100 is crit
                    result = "Crit! " + string.Join(", ", Target.HitFor(_weaponDamage * _critMultiplier));
                else if (hitNum >= 11) // 11-95 is hit
                    result = string.Join(", ", Target.HitFor(_weaponDamage));
                else // 0-10 is miss
                    result = "Missed!";
            }
            return result;
        }
Ejemplo n.º 2
0
        private string repair(Ship target)
        {
            List<string> repaired = new List<string>();
            string result = string.Empty;
            using(RNG rand = new RNG())
            {
                foreach (ShipPart part in target.Equipment.Where(f => f.IsDestroyed))
                    if (rand.d100() > 50)
                    {
                        result = part.Repair(_repairAmount);
                        repaired.Add(part.Name+(!string.IsNullOrEmpty(result)?string.Format(" ({0} HPs)",result):string.Empty));
                    }
            }
            result = string.Format("Repaired {0} for {1} HPs", target.Name, target.HP.Add(_repairAmount).ToString());
            if(repaired.Count>0)
                result = result+string.Format(", and Repaired {0}", string.Join(", ",repaired.ToArray()));

            return result;
        }
Ejemplo n.º 3
0
 public override string DoAction(EidosPart targetPart)
 {
     Eidos target = targetPart.Target;
     List<string> repaired = new List<string>();
     string result = string.Empty;
     using (RNG rand = new RNG())
     {
         foreach (EidosPart part in target.Parts.Where(f => f.IsDestroyed))
             if (rand.d100() > 50)
             {
                 result = part.Repair((int)ActionValues[0]);
                 repaired.Add(part.Name + (!string.IsNullOrEmpty(result) ? string.Format(" ({0} HPs)", result) : string.Empty));
             }
     }
     if (target is Ship)
     {
         result = string.Format("Repaired {0} for {1} HPs", target.Name, ((Ship)target).HP.Add((int)ActionValues[0]).ToString());
         if (repaired.Count > 0)
             result = result + string.Format(", and Repaired {0}", string.Join(", ", repaired.ToArray()));
     }
     else
         result = string.Format("Repaired {0}", string.Join(", ", repaired.ToArray()));
     return result;
 }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
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;
     }
 }
Ejemplo n.º 8
0
        private void FightRound()
        {
            List<string> roundResults = new List<string>();
            roundResults.Add(string.Format("-=-=-=-=-=-=-=-=Round {0}: COMBAT=-=-=-=-=-=-=-=-", Round));
            using (RNG rand = new RNG())
            {
                if (rand.d100() > 50)
                {
                    roundResults.Add(string.Format("## Firing {0} ##", Ship1.ClassName));
                    roundResults.AddRange(Ship1.FireWeapons(Ship2));
                    roundResults.Add(string.Format("## Firing {0} ##", Ship2.ClassName));
                    roundResults.AddRange(Ship2.FireWeapons(Ship1));
                    roundResults.Add(string.Format("%% Recovering {0} %%", Ship1.ClassName));
                    roundResults.AddRange(Ship1.EndOfTurn());
                    roundResults.Add(string.Format("%% Recovering {0} %%", Ship2.ClassName));
                    roundResults.AddRange(Ship2.EndOfTurn());
                }
                else
                {
                    roundResults.Add(string.Format("## Firing {0} ##", Ship2.ClassName));
                    roundResults.AddRange(Ship2.FireWeapons(Ship1));
                    roundResults.Add(string.Format("## Firing {0} ##", Ship1.ClassName));
                    roundResults.AddRange(Ship1.FireWeapons(Ship2));
                    roundResults.Add(string.Format("%% Recovering {0} %%", Ship2.ClassName));
                    roundResults.AddRange(Ship2.EndOfTurn());
                    roundResults.Add(string.Format("%% Recovering {0} %%", Ship1.ClassName));
                    roundResults.AddRange(Ship1.EndOfTurn());
                }
            }

            roundResults.AddRange(results);
            results = roundResults;
            GridBind(results);

            if (Ship1.HP.Current <= 0 && Ship2.HP.Current <= 0)
            {
                MessageBox.Show(string.Format("Stalemate in {0} rounds!", Round.ToString()));
                victory = true;
                btnFight.Enabled = false;
                btnToTheDeath.Enabled = false;
                btnResetShips.Enabled = true;
            }
            else if (Ship1.HP.Current <= 0)
            {
                MessageBox.Show(string.Format("{0} (Ship 2) Wins in {1} rounds!",Ship2.ClassName, Round.ToString()));
                victory = true;
                btnFight.Enabled = false;
                btnToTheDeath.Enabled = false;
                btnResetShips.Enabled = true;
            }
            else if (Ship2.HP.Current <= 0)
            {
                MessageBox.Show(string.Format("{0} (Ship 1) Wins in {1} rounds!",Ship1.ClassName, Round.ToString()));
                victory = true;
                btnFight.Enabled = false;
                btnToTheDeath.Enabled = false;
                btnResetShips.Enabled = true;
            }

            Round++;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Fires the weapon at its existing target with specific hit/crit chances
        /// </summary>
        /// <param name="hitAbove">Minimum number needed (out of 100) to hit the target</param>
        /// <param name="critAbove">Minimum number needed (out of 100) to critically-hit the target</param>
        /// <returns>Status result</returns>
        public List<string> Fire(int hitAbove, int critAbove)
        {
            Ship targetShip = (Ship)Target;
            List<string> result = new List<string>();
            _currentReload = _reloadTime;
            using (RNG rng = new RNG())
            {
                int hitNum = rng.d100();

                if (hitNum >= critAbove)
                {
                    result.Add(string.Format("{0} CRITS {1} for {2}",
                        this.Name,
                        targetShip.Name,
                        this.WeaponDamage
                        ));
                    result = result.Concat(targetShip.HitFor(_weaponDamage * _critMultiplier)).ToList<string>();
                }
                else if (hitNum >= hitAbove)
                {
                    result.Add(string.Format("{0} hits {1} for {2}",
                        this.Name,
                        targetShip.Name,
                        this.WeaponDamage
                        ));
                    result = result.Concat(targetShip.HitFor(_weaponDamage)).ToList<string>();
                }
                else
                    result.Add(string.Format("{0} Missed!", this.Name));
            }

            return result;
        }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
0
        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"); }
                        }

                    }
                }
            }
        }
Ejemplo n.º 12
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;
        }
Ejemplo n.º 13
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;
        }
Ejemplo n.º 14
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);
     }
 }
Ejemplo n.º 15
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);
            }
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
 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;
 }
Ejemplo n.º 18
0
 void initLocations()
 {
     try
     {
         Location newLoc;
         for (int x = 0; x < GridDimensionX; x++)
         {
             for (int y = 0; y < GridDimensionY; y++)
             {
                 using (RNG rng = new RNG())
                 {
                     newLoc = new Location();
                     if (rng.d100() > 95)
                         newLoc.IsBlocked = true;
                     newLoc.Name = string.Format("Loc {0},{1}{2}",
                         x.ToString(),
                         y.ToString(),
                         (newLoc.IsBlocked ? Environment.NewLine + " (Blocked)" : string.Empty));
                     GameState.CombatLocations[x, y] = newLoc;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         if (LogEverything)
             Logger(ex);
     }
 }