Пример #1
0
 /// <summary>
 /// Switches to gameplay mode
 /// </summary>
 public void GoToGameplay()
 {
     MenuModel.Disable();
     MenuView.Hide();
     GameplayModel.Enable();
     GameplayView.Show();
     Audio.startMusic();
     Controller.Model = GameplayModel;
 }
Пример #2
0
 /// <summary>
 /// Go to the menu. Which menu is shown, depends on the menuState parameter.
 /// </summary>
 /// <param name="menuState"></param>
 public void GoToMenu(MenuState menuState)
 {
     GameplayModel.Disable();
     GameplayView.Hide();
     MenuModel.Enable();
     MenuView.Show();
     MenuModel.setMenuState(menuState);
     Audio.stopMusic();
     Controller.Model = MenuModel;
 }
Пример #3
0
        public GameplayView(Game game, GameplayModel model)
            : base(game)
        {
            /*
             * graphics = (GraphicsDeviceManager)Game.Services.GetService(typeof(GraphicsDeviceManager));
             * device = graphics.GraphicsDevice;
             * spriteBatch = (SpriteBatch)Game.Services.GetService(typeof(SpriteBatch));
             * LineBatch.Init(device);
             */

            Camera     = new Camera2D(800, 600); //default, will be changed later
            Model      = model;
            Model.View = this;
        }
Пример #4
0
        public JsonResult ExecuteAction(String action, int heroId)
        {
            Hero          hero       = Db.Hero.Find(heroId);
            Gameplay      gameplay   = RedisContext.GetByKey <Gameplay>($"hero-gamesave-{heroId}") ?? new Gameplay(hero);
            JsonResult    jsonResult = new JsonResult();
            GameplayModel gameplayModel;

            gameplay.Player = hero;
            try
            {
                List <string> result = new GameplayActions(gameplay).ExecuteAction(action).ToList();
                if (0 == gameplay.Monsters.Count)
                {
                    gameplay.Monsters = gameplay.CurrentLocation.AmbushPlayer();
                    result.AddRange(gameplay.Monsters.Select(m => $"You have been attacked by {m.Name}"));
                }
                gameplayModel = new GameplayModel(hero, result.ToArray());
                if (!RedisContext.Save($"hero-gamesave-{gameplay.Player.ID}", gameplay))
                {
                    gameplayModel.Messages = new String[] { "There was an error while saving game." };
                }
                else
                {
                    hero.Pockets.ToList().ForEach(x => {
                        Db.Entry(x.Item.ItemInfo).State = EntityState.Modified;
                    });
                    hero.LastPlayedAt    = DateTime.UtcNow;
                    Db.Entry(hero).State = EntityState.Modified;
                    Db.SaveChanges();
                }
            }
            catch (InvalidActionException e)
            {
                gameplayModel = new GameplayModel(hero, new string[] { e.Message });
            }
            jsonResult.Data = StringHelper.SerializeObject(gameplayModel);

            return(jsonResult);
        }
 public void Construct(GameplayModel gameplayModel)
 {
     _gameplayModel = gameplayModel;
 }
Пример #6
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public BunnyGame()
        {
            Content.RootDirectory = "Content";

            IsFixedTimeStep = false;

            // Initialize a GraphicsDeviceManager and add it as a Service
            graphics = new GraphicsDeviceManager(this);
            Services.AddService(typeof(GraphicsDeviceManager), graphics);

            // Read settings from settings.ini
            List <string> settingValues = new List <string>();
            List <string> settingsFromFile;

            try { settingsFromFile = Utility.ReadFromFile("settings.ini"); } catch (FileNotFoundException e) {
                settingsFromFile = new List <string>();
            }
            if (settingsFromFile.Count < 4) // Settings read from file are wrong. Use standard settings and create new settings.ini file
            {
                Settings.Resolution  = Resolution.Res_800x600;
                Settings.FullScreen  = false;
                Settings.EntityLimit = Setting.Medium;
                Settings.GoreLevel   = Setting.Medium;
                Settings.writeSettingsToIniFile();
            }
            else
            {
                for (int i = 0; i < settingsFromFile.Count; i++)
                {
                    settingValues.Add(settingsFromFile.ElementAt(i).Split('=')[1].Trim());
                }

                // Apply settings
                Settings.Resolution  = (Resolution)Enum.Parse(typeof(Resolution), settingValues[0], true);
                Settings.FullScreen  = Boolean.Parse(settingValues[1]);
                Settings.EntityLimit = (Setting)Enum.Parse(typeof(Setting), settingValues[2], true);
                Settings.GoreLevel   = (Setting)Enum.Parse(typeof(Setting), settingValues[3], true);
            }

            // Initialize model
            MenuModel     = new MenuModel(this);
            GameplayModel = new GameplayModel(this);

            // Initialize view
            MenuView     = new MenuView(this, MenuModel);
            GameplayView = new GameplayView(this, GameplayModel);

            // Initialize controller
            Controller = new Controller(this, MenuModel);

            // Add model components
            Components.Add(MenuModel);
            Components.Add(GameplayModel);

            // Add view components
            Components.Add(MenuView);
            Components.Add(GameplayView);

            // Add controller component
            Components.Add(Controller);
        }
Пример #7
0
 /// <summary>
 /// Creates a new game
 /// </summary>
 /// <param name="mapType">Type of map (simple or complex)</param>
 /// <param name="mapSize">Size of map (various preset dimensions</param>
 /// <param name="numberPlayers">Number of players (2-4)</param>
 /// <param name="killLimit">Number of kills needed to win the game</param>
 /// <param name="numberPlanets">Number of randomly generated planets in the map</param>
 /// <param name="numberBlackHoles">Number of randomly generated black holes in the map</param>
 public void CreateNewGame(MapType mapType, MapSize mapSize, int numberPlayers, int killLimit, int numberPlanets, int numberBlackHoles)
 {
     GameplayModel.CreateNewGame(mapType, mapSize, numberPlayers, killLimit, numberPlanets, numberBlackHoles);
 }