Example #1
0
        public Menu(StrategyGame game1, GraphicsDeviceManager Graphics, ContentManager theContent, System.EventHandler theScreenEvent, Account account, GraphicsDevice Device, System.EventHandler ExitGame)
            : base(theScreenEvent, theContent)
        {
            content = new ContentManager(theContent.ServiceProvider, theContent.RootDirectory);
            graphics = Graphics;
            device = Device;

            user = account;
            game = game1;

            newGame = theScreenEvent;
            exitGame = ExitGame;
        }
Example #2
0
 static void Main()
 {
     using (var game = new StrategyGame())
         game.Run();
 }
Example #3
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;
        }
Example #4
0
        public void Init(StrategyGame game, Point cameraCentre, bool first = false)
        {
            model = new UIViewModel();
            font = content.Load<SpriteFont>("Segoe_UI_9_Regular");

            if (first)
            {
                ServiceManager.Instance.AddService<ILocalizationService>(new LocalizationService());
                ServiceManager.Instance.AddService<UIlib.UIViewModel.IGameService>(new GameServiceMainGame(this));                       
            }
            FontManager.DefaultFont = Engine.Instance.Renderer.CreateFont(font);

            Viewport viewport = game.GraphicsDevice.Viewport;
            UserInterface = new Root(viewport.Width, viewport.Height);
            UserInterface.DataContext = model;
            debug = new DebugViewModel(UserInterface);

            RelayCommand command = new RelayCommand(new Action<object>(OnEscEvent));
            KeyBinding escapeBinding = new KeyBinding(command, KeyCode.Escape, ModifierKeys.None);
            UserInterface.InputBindings.Add(escapeBinding);

            FontManager.Instance.LoadFonts(content);

            ImageManager.Instance.LoadImages(content);
            SoundManager.Instance.LoadSounds(content);

            centre = new Vector2(cameraCentre.X - Graphics.PreferredBackBufferWidth / 2,
                                cameraCentre.Y - Graphics.PreferredBackBufferHeight / 2);
            zoom = 0.99f;
            oldScrollValue = 0;
            pause = false;
            model.SetUp(StrategyGame.DayLengthHours);
            background = content.Load<Texture2D>("galaxyBackground");
            BackgroundRec = new Rectangle(-500, -500, background.Width, background.Height);
            BackgroundPosition = new Vector2(-500f, -500f);
            zoomedIn = needZoomIn = NeedZoomOut = false;
            currentSector = 1;
        }