Exemplo n.º 1
0
 public SaveGameData newData(NewGameDetails details)
 {
     SaveData = new SaveGameData();
     SaveData.Score = 1;
     SaveData.numAIPlayers = details.NumAI;
     return SaveData;
 }
Exemplo n.º 2
0
        public void DoSave(SaveGameData data, PlanetsSystem[] systems, Player[] players)
        {
            fileName = "SAVE" + data.Slot + ".sav";
            fullpath = "C:\\Users\\" + username + "\\Documents\\Saves\\";
            Directory.CreateDirectory(Path.GetDirectoryName(fullpath + fileName));
            
            if (File.Exists(fullpath + fileName))
            {
                File.Delete(fullpath + fileName); //If there's already a file in that slot, delete it first! or..
                //...if the new file is shorter than the original, junk characters get added to the end of the xml file!
            }

            FileStream stream = File.Open(fullpath + fileName, FileMode.OpenOrCreate);
            XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData), extratypes);
            
            //Player[] playerArray = new Player[1];
            //playerArray[0] = player; //Have to put the player object into an array because Info is an array of object arrays :/

            object[][] info = new object[2][];
            info[0] = systems;
            info[1] = players;

            data.Info = info;

            try
            {               
                serializer.Serialize(stream, data);
            }
            finally
            {
                stream.Close();
            }
            
        }
Exemplo n.º 3
0
        public Account()
        {
            SaveData = new SaveGameData();
            SaveData.DateT = DateTime.Now;
            player = new Player();

            saveGame = new SaveGame(SaveData);
        }
Exemplo n.º 4
0
 public SaveGame(SaveGameData data) 
 {
     Data = data;
     username = Environment.UserName;
     extratypes[0] = typeof(PlanetsSystem);
     extratypes[1] = typeof(Player);
     fullpath = "C:\\Users\\" + username + "\\Documents\\Saves"; 
 }
Exemplo n.º 5
0
        public void SaveAccount(SaveGameData data, PlanetsSystem[] systems, Player[] AIPlayers)
        {
            Player[] players = new Player[AIPlayers.Length + 1];

            for (int i = 0; i < players.Length; i++)
            {
                if (i < players.Length - 1)
                {
                    players[i] = AIPlayers[i];
                }
                else players[i] = player;
            }
            SaveData.Score = data.Score;
            if (SaveData.Score != 0)
            {
                saveGame.DoSave(SaveData, systems, players);
            }
            else return;
        }
Exemplo n.º 6
0
 public SaveGameData LoadAccount(SaveGameData data, int Slot, ref PlanetsSystem[] systems, ref Player player, ref AIPlayer[] aiplayers)
 {
     slot = Slot;
     data = saveGame.LoadData(slot, ref systems, ref player, ref aiplayers);
     return data;
 }
Exemplo n.º 7
0
        public SaveGameData LoadData(int slot, ref PlanetsSystem[] systems, ref Player player, ref AIPlayer[] AIPlayers)
        {
            object[][] info = new object[2][];
            SaveGameData data;
            data = new SaveGameData();
            string Fullpath = "C:\\Users\\" + username + "\\Documents\\Saves\\SAVE" + slot + ".sav";
          
            if (File.Exists(Fullpath))
            {
                FileStream stream = File.Open(Fullpath, FileMode.Open, FileAccess.Read);
                XmlReader reader = new XmlTextReader(stream);

                try
                {
                    if (File.Exists(Fullpath))
                    {
                        // Read the data from the file
                        XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData), extratypes);
                        if (serializer.CanDeserialize(reader))
                        {
                            data = (SaveGameData)serializer.Deserialize(reader); // 
                            info[0] = (object[])data.Info[0]; //array of additional objects
                            systems = new PlanetsSystem[data.Info[0].Length]; // 

                            for (int i = 0; i < data.Info[0].Length; i++)
                            {
                                systems[i] = (PlanetsSystem)info[0][i];
                            }

                            Player[] playerArray = (Player[])data.Info[1][0];
                            List<Player> playerList = playerArray.ToList();
                            player = playerList[playerList.Count - 1];
                            playerList.RemoveAt(playerList.Count - 1);
                            for (int i = 0; i < playerList.Count; i++)
                            {
                                AIPlayers[i] = (AIPlayer)playerList[i];
                            }

                        }
                    }
                }
                finally
                {
                    // Close the file
                    stream.Close();
                }
            }

            return data;
        }
Exemplo n.º 8
0
        public Overview(GraphicsDeviceManager graphics, ContentManager theContent, 
            EventHandler theScreenEvent, EventHandler paused, Account account, 
            Vector2 Centre, EventHandler systemSelected, EventHandler DayPassed, 
            EventHandler SystemHovered, EventHandler RemoveSystemHovered,
            EventHandler UpdateBuildQueue, EventHandler UpdateResourceDetails, 
            GraphicsDevice graphicsDevice, SpriteBatch spriteBatch)
            : base(theScreenEvent, theContent)
        {
            content = new ContentManager(theContent.ServiceProvider, theContent.RootDirectory);
            this.device = graphicsDevice;
            this.spriteBatch = spriteBatch;
            this.graphics = graphics;
            var presParams = graphicsDevice.PresentationParameters.Clone();
            // Configure parameters for secondary graphics device
            device = new GraphicsDevice(graphicsDevice.Adapter, GraphicsProfile.HiDef, presParams);


            dayPassed = DayPassed;
            systemHovered = SystemHovered;
            removeSystemHovered = RemoveSystemHovered;
            updateBuildQueue = UpdateBuildQueue;
            updateResources = UpdateResourceDetails;
            this.systemSelected = systemSelected;

            Paused = paused;
            EscapeToMenu = theScreenEvent;
            user = account;
            data = account.SaveData;
            centre = Centre;
            map = new Map(new EventHandler(SystemSelected), new EventHandler(OnSystemHovered),
                new EventHandler(OnRemoveSystemHovered), new EventHandler(UpdateResources));
            AllPlayers = new List<Player>();
        }
Exemplo n.º 9
0
        public override void LoadContent(Account acc, NewGameDetails details)
        {
            user = acc;
            SysTex = content.Load<Texture2D>("sun");
            RingTex = content.Load<Texture2D>("ring");
            background = content.Load<Texture2D>("galaxyBackground");
            Font = content.Load<SpriteFont>("Font");
            ShipTex = content.Load<Texture2D>("Ship1");
            base.sf = content.Load<SpriteFont>("Font");
            Texture2D sectorOutline = content.Load<Texture2D>("outline");

            for (int i = 1; i <= 20; i++)
            {
                planetTextures[i - 1] = content.Load<Texture2D>("Planets/planet" + i);
            }

            HumanPlayer = new Player(details.playerFaction, 1);
            AllPlayers.Add(HumanPlayer);
            HumanPlayer.playerListPosition = AllPlayers.Count - 1;
            screentitle = "OVERVIEW SCREEN";
            data = user.SaveData;
            prev = new SaveGameData();
            aiPlayers = new AIPlayer[details.NumAI]; //plus 1 so the player can be added to the array when serializing 
            for (int i = 0; i < details.NumAI; i++)
            {
                aiPlayers[i] = new AIPlayer();
                aiPlayers[i].playerNumber = i;
                AllPlayers.Add(aiPlayers[i]);
                aiPlayers[i].playerListPosition = AllPlayers.Count - 1;
            }
            map.Initialize(details.NumSystems, SysTex, RingTex, details.MapSizeVector, 
                planetTextures, ref aiPlayers, ref humanPlayer, sectorOutline, Font,
                device, graphics, spriteBatch);
            zoom = 1.0f;
            Systems = map.AllSystems;
            selectedSystem = map.AllSystems[map.selectedSystem];

            BackgroundRec = new Rectangle(
                0 - (graphics.PreferredBackBufferWidth / 3),
                0 - (graphics.PreferredBackBufferHeight / 3),
                background.Width, background.Height);
            UpdateResourcesDetails();
            UpdateEndDayResources();
            gameSpeed = 1f;
            CurrentView = ViewType.MapView;
            elapsedDays = 0;
            elapsedHours = 0;
            paused = false;
            planetsTaxChange.Clear();
            planetsTaxChangeNames.Clear();
        }
Exemplo n.º 10
0
        public GUIManager(GraphicsDeviceManager graphics, ContentManager theContent, System.EventHandler gameExit,
            System.EventHandler returnToMenu, System.EventHandler gameSave, System.EventHandler gameLoad,
            System.EventHandler buildPressed, System.EventHandler zoomIn, System.EventHandler zoomOut,
            System.EventHandler gamePaused, System.EventHandler planetHighlighted, System.EventHandler comboboxToggled,
            System.EventHandler sectorChanged, System.EventHandler planetInfoPressed, SaveGameData Data,
            System.EventHandler systemSelected, System.EventHandler jumpToSystem, System.EventHandler jumpToPlanet,
            System.EventHandler TaxRateChanged, System.EventHandler GameSpeedChangedEvent, 
            System.EventHandler BuildingUpgradedEvent, System.EventHandler BuildingDismantledEvent,
            System.EventHandler ConstructBuildingEvent, System.EventHandler RemoveBuildQueueItemEvent, GraphicsDevice device)
        {
            this.Graphics = graphics;
            content = new ContentManager(theContent.ServiceProvider, theContent.RootDirectory);
            data = Data;
            Device = device;


            #region EventHandlers
            GameExit = gameExit;
            BuildPressed = buildPressed;
            GameSave = gameSave;
            GameLoad = gameLoad;
            ReturnToMenu = returnToMenu;
            ZoomIn = zoomIn;
            ZoomOut = zoomOut;
            GamePaused = gamePaused;
            PlanetHighlightedEvent = planetHighlighted;
            ComboboxToggled = comboboxToggled;
            SectorChanged = sectorChanged;
            PlanetInfoPressedEvent = planetInfoPressed;
            SystemSelected = systemSelected;
            systemJumpEvent = jumpToSystem;
            planetJumpEvent = jumpToPlanet;
            taxRateChanged = TaxRateChanged;
            gameSpeedChangedEvent = GameSpeedChangedEvent;
            buildingUpgradedEvent = BuildingUpgradedEvent;
            buildingDismantledEvent = BuildingDismantledEvent;
            constructBuildingEvent = ConstructBuildingEvent;
            removeBuildQueueItemEvent = RemoveBuildQueueItemEvent;
            #endregion

            #region Load Content

            cursor = content.Load<Texture2D>("cursor");
            //pp = graphics.GraphicsDevice.PresentationParameters;
            //renderTarget = new RenderTarget2D(graphics.GraphicsDevice,
            //                          pp.BackBufferWidth, pp.BackBufferHeight,
            //                          true, SurfaceFormat.Color, DepthFormat.None);

            Engine engine = new MonoGameEngine(Device, Graphics.PreferredBackBufferWidth, Graphics.PreferredBackBufferHeight);
            engine.InputDevice.MouseState.IsVisible = false;
            #endregion

            #region Assign Rectangles
            cursorRec = new Rectangle(0, 0, cursor.Width, cursor.Height);
            #endregion

            mouseScale = 0.5f;    //Scale of the mouse texture  
            moveEnabled = true;
        }
Exemplo n.º 11
0
        public void Update(GameTime theTime, SaveGameData Data, StrategyGame game, ResourceManager manager,
            Overview overview, int elapsedHours, int elapsedDays)
        {
            model.UpdateUI(manager.money, manager.income, manager.deductions, manager.net,
                elapsedHours, elapsedDays);

            mouseOverHUD = IsMouseOver();

            if (needZoomIn)
            {
                ZoomIn.Invoke(this, new EventArgs());
                zoom = systemZoom;
                needZoomIn = false;
            }

            if (NeedZoomOut)
            {
                ZoomOut.Invoke(this, new EventArgs());
                model.OnSystemZoomedOut();
                NeedZoomOut = false;
            }

            data = Data;

            mousePos = mouseState.X.ToString() + " " + mouseState.Y.ToString();
            keyboardState = Microsoft.Xna.Framework.Input.Keyboard.GetState();

            UserInterface.UpdateInput(theTime.ElapsedGameTime.TotalMilliseconds);

            debug.Update();

            UserInterface.UpdateLayout(theTime.ElapsedGameTime.TotalMilliseconds);

            if (!pause)
            {
                #region Map Move & Zoom Controls

                if (moveEnabled)
                {
                    if (keyboardState.IsKeyDown(Keys.Left))
                    {
                        TempCentre = new Vector2(centre.X - cameraSpeed, centre.Y);
                        if (ValidMove(TempCentre, data.MapSize, 'L'))
                        {
                            centre = TempCentre;
                            BackgroundPosition.X += (cameraSpeed / 50f);
                        }
                    }
                    if (keyboardState.IsKeyDown(Keys.Right))
                    {
                        TempCentre = new Vector2(centre.X + cameraSpeed, centre.Y);
                        if (ValidMove(TempCentre, data.MapSize, 'R'))
                        {
                            centre = TempCentre;
                            BackgroundPosition.X -= (cameraSpeed / 50f);
                        }
                    }

                    if (keyboardState.IsKeyDown(Keys.Up))
                    {
                        TempCentre = new Vector2(centre.X, centre.Y - cameraSpeed);
                        if (ValidMove(TempCentre, data.MapSize, 'U'))
                        {
                            centre = TempCentre;
                            BackgroundPosition.Y += (cameraSpeed / 50f);
                        }
                    }
                    if (keyboardState.IsKeyDown(Keys.Down))
                    {
                        TempCentre = new Vector2(centre.X, centre.Y + cameraSpeed);
                        if (ValidMove(TempCentre, data.MapSize, 'D'))
                        {
                            centre = TempCentre;
                            BackgroundPosition.Y -= (cameraSpeed / 50f);
                        }
                    }
                }

                if (!mouseOverHUD)
                {

                    if (oldScrollValue != mouseState.ScrollWheelValue)
                    {
                        if (mouseState.ScrollWheelValue > oldScrollValue)
                        {
                            if (zoom >= 0.95 && zoomedIn == false)
                            {
                                zoomedIn = true;
                                needZoomIn = true;
                                systemZoom = 1;
                            }
                        }

                        if (mouseState.ScrollWheelValue > oldScrollValue)
                        {
                            if (zoom < 0.95)
                            {
                                zoom += 0.1;
                            }
                        }

                        if (mouseState.ScrollWheelValue < oldScrollValue)
                        {
                            if (zoom > 0.55)
                            {
                                zoom -= 0.1;
                                if (zoom > 0.5)
                                {
                                    if (centre.X > (data.MapSize.X - Graphics.PreferredBackBufferWidth * 1.5))
                                    {
                                        centre = new Vector2(centre.X - (Graphics.PreferredBackBufferWidth / 2f), centre.Y);
                                    }
                                }
                            }

                            if (zoomedIn)
                            {
                                zoomedIn = false;
                                NeedZoomOut = true;
                            }
                        }
                    }
                }



                currentTime += (float)theTime.ElapsedGameTime.TotalSeconds; //Time passed since last Update() 

                if (keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.Right))
                {
                    if (currentTime >= countDuration)
                    {
                        currentTime -= countDuration; // "use up" the time
                        cameraSpeed = 5;
                    }
                }
                else if (keyboardState.IsKeyUp(Keys.Down) || keyboardState.IsKeyUp(Keys.Up) || keyboardState.IsKeyUp(Keys.Left) || keyboardState.IsKeyUp(Keys.Right))
                {
                    cameraSpeed = 1;
                }
                #endregion
            }

            oldMouseState = mouseState;
            oldKeyboardState = keyboardState;
            oldScrollValue = mouseState.ScrollWheelValue;
        }
Exemplo n.º 12
0
        public void viewSaveData(SaveGameData data)
        {

        }