Example #1
0
        public ServerLoop(IHubContext <GameHub> hubContext, IMapLoader mapLoader)
        {
            _gameContextList = new List <GameContext>(MaxLobbyCount);

            for (var i = 0; i < MaxLobbyCount; i++)
            {
                _gameContextList.Add(new GameContext(id: i, maps: mapLoader.LoadMaps()));
            }

            var broadCastLoop = new Timer(BroadcastInterval);


            //Every set interval, send lobbies to clients
            broadCastLoop.Elapsed += (sender, args) =>
            {
                Parallel.ForEach(_gameContextList, async context =>
                {
                    GameContext valContext = null;

                    await context.Update();

                    //If blocks have not changed, then do not send to frontend to save bandwidth
                    if (!context.BlocksHaveChanged)
                    {
                        //Create new Object to avoid mutating properties
                        valContext = new GameContext(context.Players, context.Ball, new GameMap(), context.ScoreBoard, context.LobbyState);
                    }

                    await hubContext.Clients.Group($"lobby{context.Id}").SendAsync("ReceiveContextUpdate", context.BlocksHaveChanged ? context : valContext);//send to frontend
                });
            };


            broadCastLoop.Start();
        }
Example #2
0
 internal static void Unload()
 {
     Global.RunState = RunState.Init;
     _map            = null;
     _game           = null;
     Players         = null;
 }
Example #3
0
        public static CMap Create(IMapLoader loader)
        {
            Int32 width  = loader.GetWidth();
            Int32 height = loader.GetHeight();

            var map = new CMap(width, height);

            for (var x = 0; x < map.Width; x++)
            {
                for (var y = 0; y < map.Height; y++)
                {
                    var   position = new SPoint(x, y);
                    ICell cell     = loader.GetCell(position);
                    map.SetCell(cell);

                    IPositionable unit = loader.GetUnit(position);
                    if (unit != null)
                    {
                        unit.SetMap(map);
                        unit.SetPosition(new SPoint(x, y));
                        //map.Spawn(unit, position.X, position.Y);
                    }
                }
            }

            return(map);
        }
        public GenericOpenHeroesRunner(IMapLoader mapLoader, EntityWorld entityWorld = null)
        {
            _mapLoader   = mapLoader;
            EventBus     = JEventBus.GetDefault();
            GameCalendar = new GameCalendar();
            int?internalMapSize = mapLoader?.GetMapSize();

            if (!internalMapSize.HasValue)
            {
                internalMapSize = 512;
            }
            Grid grid = new Grid(internalMapSize.Value, internalMapSize.Value);

            EntitySystem.BlackBoard.SetEntry("EventBus", EventBus);
            EntitySystem.BlackBoard.SetEntry("Grid", grid);
            EntitySystem.BlackBoard.SetEntry("GameCalendar", GameCalendar);
            EntitySystem.BlackBoard.SetEntry("TerrainLayer", new TerrainLayer(grid));

            if (entityWorld == null)
            {
                EntityWorld = new EntityWorld(false, true, true)
                {
                    PoolCleanupDelay = 1
                };
                LoadMap();
            }
            else
            {
                EntityWorld = entityWorld;
            }
        }
 public static GenericOpenHeroesRunner CreateInstance(IMapLoader mapLoader = null, EntityWorld entityWorld = null)
 {
     if (mapLoader == null)
     {
         mapLoader = new ByteArrayMapLoader(ByteArrayHelper.CreateBase());
     }
     return(new GenericOpenHeroesRunner(mapLoader, entityWorld));
 }
Example #6
0
        public void Run(IMapLoader mapLoader = null)
        {
            _eventBus.Register(this);
            _eventBus.Register(JavityWebSocketServer.GetInstance());

            mapLoader ??= LoadClassicMap();
            GenerateMap(mapLoader);
            StartWebServer();
            RunGame();
        }
Example #7
0
    public MapHandler(IMapLoader mapLoader, AssetBundle mapAsset, MapSettings mapSettings, int mapLayer)
    {
        this.mapLoader = mapLoader;
        this.bundle = mapAsset;
        this.mapSettings = mapSettings;
        this.mapLayer = mapLayer;

        this.mapOffset = new Vector3(mapSettings.length / 2, HUDConstants.MAP_HEIGHT, mapSettings.width / 2);
        this.mapBounds = new Rect();
    }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Map"/> class.
        /// </summary>
        /// <param name="logger">A reference to the logger to use.</param>
        /// <param name="mapLoader">The map loader to use to load this map.</param>
        public Map(ILogger <Map> logger, IMapLoader mapLoader)
        {
            logger.ThrowIfNull(nameof(logger));
            mapLoader.ThrowIfNull(nameof(mapLoader));

            this.logger = logger;
            this.loader = mapLoader;

            this.tiles        = new ConcurrentDictionary <Location, ITile>();
            this.loadedHashes = new HashSet <string>();
        }
 public PacManGame(
     IEventSink eventSink,
     IMapLoader <ITilemap> mapLoader,
     ICollisionDetection collisionDetection,
     ISpriteRenderer renderer)
 {
     _eventSink          = eventSink;
     _mapLoader          = mapLoader;
     _gameState          = new GameState(3);
     _collisionDetection = collisionDetection;
     _renderer           = renderer;
 }
Example #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Map"/> class.
        /// </summary>
        /// <param name="logger">A reference to the logger to use.</param>
        /// <param name="mapLoader">The map loader to use to load this map.</param>
        /// <param name="creatureFinder">A reference to the creature finder.</param>
        public Map(ILogger logger, IMapLoader mapLoader, ICreatureFinder creatureFinder)
        {
            logger.ThrowIfNull(nameof(logger));
            mapLoader.ThrowIfNull(nameof(mapLoader));
            creatureFinder.ThrowIfNull(nameof(creatureFinder));

            this.Logger         = logger.ForContext <Map>();
            this.Loader         = mapLoader;
            this.CreatureFinder = creatureFinder;

            this.tiles = new ConcurrentDictionary <Location, ITile>();
        }
Example #11
0
        public static void LoadPrefabs(this Map map, string filename, IMapLoader mapLoader)
        {
            var mapPoints = mapLoader.LoadMapPoints(filename);

            if (mapPoints == null)
            {
                Console.WriteLine("LoadPrefabs: mapPoints == null");
                return;
            }

            map.Prefabs.Clear();
            map.Prefabs.AddRange(mapPoints);
        }
Example #12
0
        public Map(int[,] tilesMap, IMapSaver saver, IMapLoader loader, IMapFiller filler)
        {
            this._saver  = saver;
            this._loader = loader;
            this._filler = filler;

            _tilesMap    = tilesMap;
            _playerCount = 0;

            tileWidth  = _gameFieldWidth / tilesMap.GetLength(1);
            tileHeight = _gameFieldHeight / tilesMap.GetLength(0);

            FillTileMap();
            GetEmptySpaces();
        }
Example #13
0
        public Map(string mapPath, IMapSaver saver, IMapLoader loader, IMapFiller filler)
        {
            this._saver  = saver;
            this._loader = loader;
            this._filler = filler;

            _tilesMap    = loader.LoadMapFromBmp();
            _playerCount = 0;

            tileWidth  = _gameFieldWidth / _tilesMap.GetLength(1);
            tileHeight = _gameFieldHeight / _tilesMap.GetLength(0);

            FillTileMap();
            FillPoints();
        }
Example #14
0
 public MapChanger(
     GameState gameState,
     IXleScreen screen,
     IXleImages images,
     ITextArea textArea,
     ICommandList commands,
     IMapLoader mapLoader,
     IMuseumCoinSale museumCoinSale)
 {
     this.gameState      = gameState;
     this.screen         = screen;
     this.images         = images;
     this.textArea       = textArea;
     this.commands       = commands;
     this.mapLoader      = mapLoader;
     this.museumCoinSale = museumCoinSale;
 }
Example #15
0
 public XleRunner(
     XleSystemState systemState,
     ITextArea textArea,
     IXleInput input,
     ICommandExecutor commandExecutor,
     IMapLoader mapLoader,
     IMapChanger mapChanger,
     IXleGameFactory gameFactory,
     GameState gameState)
 {
     this.systemState     = systemState;
     this.textArea        = textArea;
     this.input           = input;
     this.commandExecutor = commandExecutor;
     this.mapLoader       = mapLoader;
     this.mapChanger      = mapChanger;
     this.gameFactory     = gameFactory;
     this.gameState       = gameState;
 }
Example #16
0
 public MapDisplayer()
 {
     _logger = GameServiceLocator.Instance.Get <Logger>();
     try
     {
         _mapLoader = GameServiceLocator.Instance.Get <IMapLoader>();
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
     _isUpdateting = true;
     _mapPaint     = new SKPaint()
     {
         Color = CreateColor(255, 255, 255)
     };
     _chunks = new List <Chunk>();
 }
Example #17
0
        internal static void Load(int index)
        {
            if (GameListLoader.Games.Count >= index)
            {
                _game = GameListLoader.Games[index];

                string map = _game.map.ToString();
                _map = MapLoaderFactory.CreateLoader(map);
                _map.LoadContent(Global.Content);

                var result = ApiReq.CreateReq()
                             .WithMethod("api/map/" + map, "get")
                             .GetResult(out string json);
                if (result == HttpStatusCode.OK)
                {
                    _map.SetMapData(DynamicJson.Parse(json));
                    Global.RunState = RunState.Run;
                }
            }
        }
Example #18
0
        private ServiceHost StartGame(CGame game)
        {
            Int32  usedPort   = _nextPort++;
            String serviceUrl = $"net.tcp://localhost:{usedPort}";
            var    urls       = new[] { new Uri(serviceUrl) };

            IMapLoader mapLoader = CXmlMapLoader.Create("C:\\Users\\Pavel\\Pavel.Ilushenko\\OwnProject\\BusinessLayer\\TestMap.xml");
            CMap       map       = CMap.Create(mapLoader);

            IGameService service = new GameService(map, game.GetPlayers().Select(p => p.PlayerInfo));

            var host    = new ServiceHost(service, urls);
            var binding = new NetTcpBinding(SecurityMode.None);

            host.AddServiceEndpoint(typeof(IGameService), binding, String.Empty);
            host.Opened += HostOnOpened;
            host.Open();
            _gameServiceHosts.Add(host);

            return(host);
        }
 public XlePlayerConsoleCommands(
     GameState gameState,
     ITextArea textArea,
     ICommandExecutor commandExecutor,
     IMapLoader mapLoader,
     IXleGameControl gameControl,
     IMapChanger mapChanger,
     XleSystemState systemState,
     XleOptions options,
     XleData data)
 {
     this.mapLoader       = mapLoader;
     this.GameState       = gameState;
     this.TextArea        = textArea;
     this.commandExecutor = commandExecutor;
     this.gameControl     = gameControl;
     this.systemState     = systemState;
     this.options         = options;
     this.Data            = data;
     this.mapChanger      = mapChanger;
 }
Example #20
0
 public FieldMapController(IMapLoader mapLoader, ScreenConstants screenConstants)
 {
     this.mapLoader = mapLoader;
     this.screenConstants = screenConstants;
 }
Example #21
0
 public Game(IInputHandler inputHandler, IGameRender gameRender, IMapLoader mapLoader)
 {
     _inputHandler = inputHandler;
     _gameRender = gameRender;
     _mapLoader = mapLoader;
 }
Example #22
0
 public void AddWorker(IMapLoader worker)
 {
     mapWorkers.Add(worker);
 }
Example #23
0
 public NewMapKeybind(IMapLoader mapLoader, ANewWorld Game1)
 {
     this.mapLoader = mapLoader;
     this.Game1     = Game1;
 }
Example #24
0
 public LevelMgr(IMapLoader loader)
 {
     this.MapLoader = loader;
 }
Example #25
0
 private void GenerateMap(IMapLoader mapLoader)
 {
     _runner = GenericOpenHeroesRunner.CreateInstance(mapLoader);
 }
Example #26
0
        public void RunAsynch(IMapLoader mapLoader = null)
        {
            Thread thread1 = new Thread(() => Run(mapLoader));

            thread1.Start();
        }
 public EnvironmentSetup(IMapLoader mapLoader, IEnvironmentFactory environmentFactory, ITroopLoader troopLoader)
 {
     _mapLoader          = mapLoader;
     _environmentFactory = environmentFactory;
     _troopLoader        = troopLoader;
 }
Example #28
0
 public NewMapKeybind(IMapLoader mapLoader, Form1 form1)
 {
     this.mapLoader = mapLoader;
     this.form1     = form1;
 }
Example #29
0
 public Map(IMapLoader mapLoader)
 {
     _loader = mapLoader;
 }
Example #30
0
 public SaveKeybind(IMapLoader mapLoader)
 {
     this.mapLoader = mapLoader;
 }
Example #31
0
 public Game(IInputHandler inputHandler, IGameRender gameRender, IMapLoader mapLoader)
 {
     _inputHandler = inputHandler;
     _gameRender   = gameRender;
     _mapLoader    = mapLoader;
 }