public AddShipsWindow(Game GameState)
        {
            this.gameState = GameState;

            //Load Hulls
            gameState.ExistingHulls.Clear();
            XDocument hullDoc = XDocument.Load("ShipHulls.xml");
            gameState.ExistingHulls = ShipHull.GetShipHulls(hullDoc);

            //Load ShipParts
            gameState.ExistingParts.Clear();
            XDocument partDoc = XDocument.Load("ShipParts.xml");
            foreach (var part in ShipPart.GetShipPartList(partDoc, new Ship()))
                gameState.ExistingParts.Add(part);

            //Load Ships
            //gameState.ExistingShips.Clear();
            //XDocument xdoc = XDocument.Load("Ships.xml");
            //foreach (XElement shipElement in xdoc.Descendants("ship"))
            //{
            //    Ship ship = new Ship(shipElement, gameState.ExistingParts, gameState.ExistingHulls);
            //    gameState.ExistingShips.Add(ship);
            //}

            initAddShipsWindow();
        }
Beispiel #2
0
        private static void AddWarpPointToSystem(Game result, StarSystem system)
        {
            StarSystem targetSystem = new StarSystem();
            int counter = 0;
            while (targetSystem.GalacticCoordinates.X == -1 && counter<25)
            {
                targetSystem = NearestSystemNotConnected(result, system);
                counter++;
            }
            if (targetSystem.GalacticCoordinates.X != -1)
            {
                // create points and assign opposite systems
                WarpPoint thisSide = new WarpPoint();
                WarpPoint thatSide = new WarpPoint();

                // This side of the Warp Point
                thisSide.StrategicPosition = WarpPointLocation(system);
                thisSide.Name = targetSystem.Name;
                thisSide.StrategicSystem = system;
                thisSide.LinkedSystem = targetSystem;
                thisSide.LinkedWarpPoint = thatSide;
                system.StrategicLocations[thisSide.StrategicPosition.X, thisSide.StrategicPosition.Y].Stellars.Add(thisSide);

                // Other side of the Warp Point
                thatSide.StrategicPosition = WarpPointLocation(targetSystem);
                thatSide.Name = system.Name;
                thatSide.StrategicSystem = targetSystem;
                thatSide.LinkedSystem = system;
                thatSide.LinkedWarpPoint = thisSide;
                targetSystem.StrategicLocations[thatSide.StrategicPosition.X, thatSide.StrategicPosition.Y].Stellars.Add(thatSide);
            }
        }
Beispiel #3
0
 public AddPlayers(Game gameState)
 {
     this.GameState = gameState;
     GameState.Players = new PlayerCollection();
     Player one = new Player("Frank", "Furters", "Necrons", false, 0);
     GameState.Players.Add(one);
     Player two = new Player("Joe (AI:4)", "Shmoes", "Orks", true, 4);
     GameState.Players.Add(two);
     InitializeComponent();
     initIconSets();
     lbxPlayerList.ItemsSource = GameState.Players;
     lbxPlayerList.UpdateLayout();
 }
Beispiel #4
0
 public Form1()
 {
     InitializeComponent();
     //initGame();
     GameState = initNewGame();
     List<StarSystem> sourceStart = new List<StarSystem>();
     foreach (var system in GameState.StarSystems)
         sourceStart.Add(system);
     List<StarSystem> sourceEnd = new List<StarSystem>();
     foreach (var system in GameState.StarSystems)
         sourceEnd.Add(system);
     ddlEnd.DataSource = sourceEnd;
     ddlEnd.DisplayMember = "Name";
     ddlStart.DataSource = sourceStart;
     ddlStart.DisplayMember = "Name";
 }
        public AddStartingShips(Game gameState)
        {
            this.GameState = gameState;
            InitializeComponent();

            //Load Hulls
            GameState.ExistingHulls.Clear();
            XDocument hullDoc = XDocument.Load("ShipHulls.xml");
            GameState.ExistingHulls = ShipHull.GetShipHulls(hullDoc);

            //Load ShipParts
            GameState.ExistingParts.Clear();
            XDocument partDoc = XDocument.Load("ShipParts.xml");
            foreach (var part in ShipPart.GetShipPartList(partDoc, new Ship()))
                GameState.ExistingParts.Add(part);

            initAddShipsWindow();
        }
        public StrategicWindow(Game gameState, Player currentPlayer = null, StarSystem currentSystem = null, System.Drawing.Point currentSystemLoc = new System.Drawing.Point(), Ship currentShip = null)
        {
            InitializeComponent();
            #region Bindings
            lbxTargetShips.ItemsSource = SelectedShipList;
            #endregion
            initImages();
            this.GameState = gameState;
            this.currentPlayer = currentPlayer;
            this.currentSystem = currentSystem;
            this.currentShip = currentShip;

            initGalaxyMap();
            ShowSystemMap(currentSystem);
            scrollGalaxyGridToSystem(currentSystem);
            highlightSelectedSystem(currentSystem);
            selectSystemCoordinates(currentSystemLoc);
        }
Beispiel #7
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;
        }
Beispiel #8
0
        private static StarSystem NearestSystemNotConnected(Game result, StarSystem system)
        {
            // get top 10% of systems ordered by distance
            int topTenPercent = Convert.ToInt32(0.1 * StartingWarpPointsMax * result.StarSystems.Count());
            List<StarSystem> NearbySystems = result.StarSystems.Where(f => f != system).OrderBy(r => RelativeDistance(system.GalacticCoordinates, r.GalacticCoordinates)).Take(topTenPercent).ToList<StarSystem>();

            // from top, find next not connected
            for (int i = 0; i < NearbySystems.Count; i++)
            {
                if (!StarSystemsAreConnected(system, NearbySystems[i]) && NearbySystems[i].GetCountOfWarpPoints() < StartingWarpPointsMax)
                    return NearbySystems[i];
            }
            return new StarSystem();
        }
Beispiel #9
0
 public void UtilizeState(object state)
 {
     this.GameState = (Game)state;
 }
Beispiel #10
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;
        }
Beispiel #11
0
        private static void AddWarpPointToSystem(Game result, StarSystem system)
        {
            StarSystem targetSystem = new StarSystem();
            targetSystem = NearestSystemNotConnected(result, system);

            // create points and assign opposite systems
            WarpPoint thisSide = new WarpPoint();
            WarpPoint thatSide = new WarpPoint();

            // This side of the Warp Point
            thisSide.StrategicPosition = WarpPointLocation(system);
            thisSide.Name = targetSystem.Name;
            thisSide.StrategicSystem = system;
            thisSide.LinkedSystem = targetSystem;
            thisSide.LinkedWarpPoint = thatSide;
            system.StrategicLocations[thisSide.StrategicPosition.X, thisSide.StrategicPosition.Y].Stellars.Add(thisSide);

            // Other side of the Warp Point
            thatSide.StrategicPosition = WarpPointLocation(targetSystem);
            thatSide.Name = system.Name;
            thatSide.StrategicSystem = targetSystem;
            thatSide.LinkedSystem = system;
            thatSide.LinkedWarpPoint = thisSide;
            targetSystem.StrategicLocations[thatSide.StrategicPosition.X, thatSide.StrategicPosition.Y].Stellars.Add(thatSide);
        }
Beispiel #12
0
        private void btnLoadGame_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            try
            {
                Border b = (Border)sender;
                b.Background = buttondown;
                Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
                ofd.CheckFileExists = true;
                ofd.CheckPathExists = true;
                ofd.FileName = "NewGame";
                ofd.DefaultExt = ".sav";
                ofd.Filter = "Save Games (.sav)|*.sav";
                Nullable<bool> result = ofd.ShowDialog();
                if (result == true)
                {
                    try
                    {
                        string fileName = ofd.FileName;
                        System.Diagnostics.Debug.WriteLine(fileName);
                        IFormatter formatter = new BinaryFormatter();
                        Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                        stream.Position = 0;
                        MessageBox.Show(string.Format("size: {0}, Filename: {1}", stream.Length, ((FileStream)stream).Name));
                        GameState = (Game)formatter.Deserialize(stream);
                        stream.Close();

                        initImages();
                        initButtons();
                        initGameState();
                    }
                    catch (Exception ex)
                    {
                        if (LogEverything)
                            Logger(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                if (LogEverything)
                    Logger(ex);
            }
        }