예제 #1
0
        public HighscoreMenu(string id, string title, List <MenuElement> elements) : base(id, title, elements)
        {
            highscores = new List <KeyValuePair <string, int> >();
            scoresFile = SwinGame.AppPath() + "\\resources\\data\\scores.json";

            InitHighscores();
        }
예제 #2
0
        public override Component CreateFromReference(JObject engineObj, IHandlesEntities entHandler, BoundaryStrategy boundaryStrat, Team team, Point2D parentPos, float mod = 1)
        {
            string  path      = SwinGame.AppPath() + engineObj.Value <string>("path");
            Point2D offsetPos = engineObj["pos"].ToObject <Point2D>().Multiply(10);

            return(base.CreateFromReference(engineObj, entHandler, boundaryStrat, team, offsetPos));
        }
예제 #3
0
        public MenuModule Create(Bank bank, Dictionary <string, Shape> shipList,
                                 Dictionary <string, Level> levelList, IReceiveMenuData receiver, ExitGame exit)
        {
            //spawn asteroids
            Level           menuScene     = levelList["MenuScene"];
            EntityHandler   entityHandler = new EntityHandler(null, menuScene.PlayArea);
            AsteroidFactory asteroidFac   = new AsteroidFactory(entityHandler);
            string          asteroidPath  = SwinGame.AppPath() + "\\resources\\data\\asteroids\\asteroid.json";

            for (int i = 0; i < menuScene.AsteroidsToSpawn; i++)
            {
                Asteroid toSpawn = asteroidFac.Create(asteroidPath, menuScene.PlayArea);
                entityHandler.Track(toSpawn);
            }

            MenuModule result = new MenuModule(new MenuSendData(receiver), bank, shipList, levelList, menuScene, entityHandler, exit);

            MenuFactory menuFac = new MenuFactory(dirPath, result);

            result.AddMenu(menuFac.CreateNormalMenu("\\help.json"));
            result.AddMenu(menuFac.CreateHighscoreMenu("\\highscores.json"));
            result.AddMenu(menuFac.CreateNormalMenu("\\main.json"));
            result.AddMenu(menuFac.CreateNormalMenu("\\options.json"));
            result.AddMenu(menuFac.CreateNormalMenu("\\scorescreen.json"));
            result.AddMenu(menuFac.CreateSelectMenu("\\select.json", shipList, levelList));

            result.ChangeMenu("Main");

            return(result);
        }
예제 #4
0
        public GameController(string title, int width, int height, Color color)
        {
            SwinGame.OpenGraphicsWindow(title, width, height);
            windowColor  = color;
            resourcePath = SwinGame.AppPath() + "\\Resources";

            Init();
        }
예제 #5
0
        /// <summary>
        /// Create component from a filepath
        /// </summary>
        /// <param name="refObj">Json object containing the filepath</param>
        /// <param name="entHandler">entity handler</param>
        /// <param name="boundaryStrat">play area boundary behaviour</param>
        /// <param name="parentPos">position of object component is attached to</param>
        /// <param name="mod">modifier</param>
        /// <returns></returns>
        public virtual Component CreateFromReference(JObject refObj, IHandlesEntities entHandler, BoundaryStrategy boundaryStrat, Team team, Point2D parentPos, float mod = 1)
        {
            string path = SwinGame.AppPath() + refObj.Value <string>("path");

            //check that the path is valid
            if (!File.Exists(path))
            {
                Console.WriteLine($"INVALID filepath: {path}");
                return(null);
            }

            //load the full JObject from path
            refObj = JsonConvert.DeserializeObject <JObject>(File.ReadAllText(path));
            return(Create(refObj, path, entHandler, boundaryStrat, team, parentPos, mod));
        }
예제 #6
0
        public GameModule Create(string shipId, Difficulty diff, Level level, ShipFactory shipFac, GameSendData gameSendData)
        {
            Scoresheet       scoreSheet  = new Scoresheet();
            EntityHandler    entHandler  = new EntityHandler(scoreSheet, level.PlayArea);
            CollisionHandler collHandler = new CollisionHandler(level.PlayArea, entHandler);

            //create player's ship
            Ship p = shipFac.Create(shipId, Util.RandomPointInRect(level.PlayArea), new WrapBoundaryBehaviour(level.PlayArea), ControllerType.Player1, diff, entHandler);

            entHandler.Track(p);

            //camera
            CameraHandler camHandler = new CameraHandler(p, level.PlayArea);
            //ai spawner
            AISpawner aiSpawner = new AISpawner(diff, level.PlayArea, shipFac, entHandler);

            //spawn predefined ships from the level
            foreach (string enemyId in level.ShipsToSpawn)
            {
                Ship toSpawn = shipFac.Create(enemyId, Util.RandomPointInRect(level.PlayArea), new WrapBoundaryBehaviour(level.PlayArea), ControllerType.Computer, diff, entHandler);
                entHandler.Track(toSpawn);
            }

            //spawn asteroids
            AsteroidFactory asteroidFac  = new AsteroidFactory(entHandler);
            string          asteroidPath = SwinGame.AppPath() + "\\resources\\data\\asteroids\\asteroid.json";

            for (int i = 0; i < level.AsteroidsToSpawn; i++)
            {
                Asteroid toSpawn = asteroidFac.Create(asteroidPath, level.PlayArea);
                entHandler.Track(toSpawn);
            }

            InputController inpController;

            if (p is IControllable)
            {
                InputControllerFactory inpContFac = new InputControllerFactory();
                inpController = inpContFac.Create(p as IControllable, ControllerType.Player1);
            }
            else
            {
                inpController = null;
            }

            return(new GameModule(p, level, aiSpawner, entHandler, collHandler, camHandler, gameSendData, scoreSheet, inpController));
        }
예제 #7
0
        public InputController Create(IControllable controlled, ControllerType controller)
        {
            ActionBindingFactory actionBindingFac = new ActionBindingFactory(SwinGame.AppPath() + "\\resources\\data\\bindings");

            switch (controller)
            {
            case ControllerType.Player1:
                return(new InputController(controlled, actionBindingFac.Create(ControllerType.Player1)));

            case ControllerType.Player2:
                return(new InputController(controlled, actionBindingFac.Create(ControllerType.Player2)));

            case ControllerType.Player3:
                return(new InputController(controlled, actionBindingFac.Create(ControllerType.Player3)));

            case ControllerType.Player4:
                return(new InputController(controlled, actionBindingFac.Create(ControllerType.Player4)));

            default:
                return(new InputController(controlled, actionBindingFac.Create(ControllerType.Player1)));
            }
        }
예제 #8
0
        public HighscoreMenu CreateHighscoreMenu(string fileName)
        {
            JObject menuObj = Util.Deserialize(dirPath + fileName);
            string  id      = menuObj.Value <string>("id").ToLower();
            string  title   = menuObj.Value <string>("title");

            JArray textBoxesObj = menuObj.Value <JArray>("textBoxes");
            string pathname     = textBoxesObj[0].Value <string>("path");

            Console.WriteLine(pathname);

            JArray buttonsObj = menuObj.Value <JArray>("buttons");
            JArray colorsObj  = menuObj.Value <JArray>("elementColors");

            string buffer = File.ReadAllText(SwinGame.AppPath() + pathname);

            textBoxesObj = JsonConvert.DeserializeObject <JArray>(buffer);

            List <MenuElement> elements = menuElementFac.Create(textBoxesObj, buttonsObj, colorsObj, menuModule, id);

            return(new HighscoreMenu(id, title, elements));
        }
예제 #9
0
        public override Component CreateFromReference(JObject particleObj, IHandlesEntities entHandler, BoundaryStrategy boundaryStrat, Team team, Point2D parentPos, float mod = 1)
        {
            string path = SwinGame.AppPath() + particleObj.Value <string>("path");

            return(base.CreateFromReference(particleObj, entHandler, boundaryStrat, team, parentPos));
        }