Exemple #1
0
        public TitleScene(GraphicsDevice graphicsDevice,
                          IContentProvider content,
                          IMouseEvents mouse,
                          IGameStateFactory gameStateFactory,
                          CImage img,
                          CSound snd,
                          WorldCollection worlds,
                          HighscoreCollection highscores,
                          BBXConfig config)
        {
            this.graphicsDevice   = graphicsDevice;
            this.content          = content;
            this.gameStateFactory = gameStateFactory;
            this.img         = img;
            this.snd         = snd;
            this.config      = config;
            this.spriteBatch = new SpriteBatch(graphicsDevice);

            this.random = new Random();

            this.worlds     = worlds;
            this.highscores = highscores;
            this.worlds.LoadWorlds(content);

            this.mouse = mouse;

            mouse.MouseMove += Mouse_MouseMove;
            mouse.MouseUp   += Mouse_MouseUp;

            keyboard          = new KeyboardEvents();
            keyboard.KeyDown += Keyboard_KeyDown;
            font              = new Font(img.Fonts.Default);
        }
Exemple #2
0
 public Main(CoroutineProvider coroutineProvider, IGameStateFactory gameStateFactory, SignalBus signalBus)
 {
     _coroutineProvider = coroutineProvider;
     _gameStateFactory  = gameStateFactory;
     _signalBus         = signalBus;
     _initGameState     = _gameStateFactory.Create <InitGameState>();
     _signalBus.Subscribe <GameSignals.GotoStateSignal>(m => TriggerStateSwitch(m));
 }
        public HiveHostGame(
            string gameName,
            RoomCacheBase roomCache,
            IGameStateFactory gameStateFactory = null,
            int maxEmptyRoomTTL = 0,
            IPluginManager pluginManager = null,
            string pluginName = "",
            Dictionary<string, object> environment = null,
            int lastTouchLimitMilliseconds = 0,
            int lastTouchCheckIntervalMilliseconds = 0,
            HttpRequestQueueOptions httpRequestQueueOptions = null,
            ExtendedPoolFiber executionFiber = null
            )
            : base(gameName, roomCache, gameStateFactory, maxEmptyRoomTTL, lastTouchLimitMilliseconds, lastTouchCheckIntervalMilliseconds, executionFiber)
        {
            this.pluginManager = pluginManager;

            if (httpRequestQueueOptions == null)
            {
                httpRequestQueueOptions = new HttpRequestQueueOptions();
            }

            this.httpRequestQueue.MaxErrorRequests = httpRequestQueueOptions.HttpQueueMaxTimeouts;
            this.httpRequestQueue.MaxTimedOutRequests = httpRequestQueueOptions.HttpQueueMaxErrors;
            this.httpRequestQueue.ReconnectInterval = TimeSpan.FromMilliseconds(httpRequestQueueOptions.HttpQueueReconnectInterval);
            this.httpRequestQueue.QueueTimeout = TimeSpan.FromMilliseconds(httpRequestQueueOptions.HttpQueueQueueTimeout);
            this.httpRequestQueue.MaxQueuedRequests = httpRequestQueueOptions.HttpQueueMaxQueuedRequests;
            this.httpRequestQueue.MaxBackoffInMilliseconds = httpRequestQueueOptions.HttpQueueMaxBackoffTime;
            this.httpRequestQueue.MaxConcurrentRequests = httpRequestQueueOptions.HttpQueueMaxConcurrentRequests;

            this.httpQueueRequestTimeout = httpRequestQueueOptions.HttpQueueRequestTimeout;

            this.httpRequestQueue.SetCounters(this);

            this.Environment = environment ?? new Dictionary<string, object>
                                       {
                                           {"AppId", GetHwId()},
                                           {"AppVersion", ""},
                                           {"Region", ""},
                                           {"Cloud", ""},
                                       };
            this.InitPlugin(pluginName);
            if (this.Plugin == null)
            {
                throw new Exception(string.Format("Failed to craete plugin '{0}'", pluginName));
            }

            var errorPlugin = this.Plugin as ErrorPlugin;
            if (errorPlugin != null)
            {
                Log.ErrorFormat("Game {0} is created with ErrorPlugin. message:{1}", this.Name, errorPlugin.Message);
            }

            this.customTypeCache.TypeMapper = this;
            this.callEnv = new CallEnv(this.Plugin, this.Name);
        }
Exemple #4
0
        /// <summary>
        ///   Initializes a new instance of the <see cref = "Room" /> class.
        /// </summary>
        /// <param name = "name">
        ///   The room name.
        /// </param>
        /// <param name = "executionFiber">
        ///   The execution fiber used to synchronize access to this instance.
        /// </param>
        /// <param name="roomCache">
        ///   The <see cref="RoomCacheBase"/> instance to which the room belongs.
        /// </param>
        /// <param name="gameStateFactory">Fatory for game state</param>
        /// <param name="maxEmptyRoomTTL">
        ///   A value indicating how long the room instance will be keeped alive
        ///   in the room cache after all peers have left the room.
        /// </param>
        protected Room(string name, ExtendedPoolFiber executionFiber, RoomCacheBase roomCache, IGameStateFactory gameStateFactory = null, int maxEmptyRoomTTL = 0)
        {
            this.name = name;

            this.gameStateFactory = gameStateFactory ?? defaultFactory;
            this.roomState        = this.gameStateFactory.Create();
            this.ExecutionFiber   = executionFiber ?? new ExtendedPoolFiber();

            this.roomCache       = roomCache;
            this.MaxEmptyRoomTTL = maxEmptyRoomTTL;
        }
Exemple #5
0
        /// <summary>
        ///   Initializes a new instance of the <see cref = "Room" /> class.
        /// </summary>
        /// <param name = "name">
        ///   The room name.
        /// </param>
        /// <param name = "executionFiber">
        ///   The execution fiber used to synchronize access to this instance.
        /// </param>
        /// <param name="roomCache">
        ///   The <see cref="RoomCacheBase"/> instance to which the room belongs.
        /// </param>
        /// <param name="gameStateFactory">Fatory for game state</param>
        /// <param name="maxEmptyRoomTTL">
        ///   A value indicating how long the room instance will be keeped alive
        ///   in the room cache after all peers have left the room.
        /// </param>
        protected Room(string name, ExtendedPoolFiber executionFiber, RoomCacheBase roomCache, IGameStateFactory gameStateFactory = null, int maxEmptyRoomTTL = 0)
        {
            this.name = name;

            this.gameStateFactory = gameStateFactory ?? defaultFactory;
            this.roomState        = this.gameStateFactory.Create();
            this.ExecutionFiber   = executionFiber ?? new ExtendedPoolFiber();

            this.roomCache       = roomCache;
            this.MaxEmptyRoomTTL = maxEmptyRoomTTL;
            this.UtcCreated      = DateTime.UtcNow;

            this.RoomCreationTS = Stopwatch.GetTimestamp();
        }
Exemple #6
0
 public GameCreateOptions(string gameName,
                          RoomCacheBase roomCache,
                          IPluginManager pluginManager,
                          int maxEmptyRoomTtl = 0, IGameStateFactory gameStateFactory = null)
     : this()
 {
     this.logMessagesCounter      = NullPluginLogMessageCounter.Instance;
     this.GameName                = gameName;
     this.RoomCache               = roomCache;
     this.PluginManager           = pluginManager;
     this.MaxEmptyRoomTTL         = maxEmptyRoomTtl;
     this.GameStateFactory        = gameStateFactory;
     this.Environment             = null;
     this.HttpRequestQueueOptions = new HttpRequestQueueOptions();
     this.ExecutionFiber          = null;
 }
Exemple #7
0
        /// <summary>
        ///   Initializes a new instance of the <see cref = "HiveGame" /> class.
        /// </summary>
        /// <param name = "gameName">
        ///     The name of the game.
        /// </param>
        /// <param name="roomCache">
        ///     The <see cref="RoomCacheBase"/> instance to which the room belongs.
        /// </param>
        /// <param name="gameStateFactory">Custom factory for GameState. if null is set, default factory is used</param>
        /// <param name="maxEmptyRoomTTL">
        ///     A value indicating how long the room instance will be kept alive 
        ///     in the room cache after all peers have left the room.
        /// </param>
        /// <param name="lastTouchLimitMilliseconds">
        ///     Specifies to maximum value for a peers GetLastTouch in milliseconds before a peer will removed from the room.
        ///     If set to zero no check will bew performed.
        /// </param>
        /// <param name="lastTouchCheckIntervalMilliseconds">
        ///     Specifies the in interval in milliseconds to check peer in the room for the GetLastTouched value.
        ///     If set to zero no check will be performed.
        /// </param>
        /// <param name="executionFiber"></param>
        public HiveGame(string gameName, RoomCacheBase roomCache, IGameStateFactory gameStateFactory = null, 
            int maxEmptyRoomTTL = 0, int lastTouchLimitMilliseconds = 0, int lastTouchCheckIntervalMilliseconds = 0, ExtendedPoolFiber executionFiber = null)
            : base(gameName, executionFiber, roomCache, gameStateFactory, maxEmptyRoomTTL)
        {
            this.ExecutionFiber.Start();

            this.MasterClientId = 0;
            this.IsOpen = true;
            this.IsVisible = true;
            this.LastTouchLimitMilliseconds = lastTouchLimitMilliseconds;
            this.LastTouchCheckIntervalMilliseconds = lastTouchCheckIntervalMilliseconds;

            if (this.LastTouchLimitMilliseconds > 0 && this.LastTouchCheckIntervalMilliseconds > 0)
            {
                this.ExecutionFiber.ScheduleOnInterval(this.CheckPeerStates, this.LastTouchCheckIntervalMilliseconds, this.LastTouchCheckIntervalMilliseconds);
            }

            this.EventCache.SetGameAppCounters(NullHiveGameAppCounters.Instance);
            this.EventCache.Slice = 0;

            this.LogQueue = new LogQueue("Game " + gameName, LogQueue.DefaultCapacity);
        }
Exemple #8
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "Room" /> class without a room name.
 /// </summary>
 /// <param name = "name">
 ///   The room name.
 /// </param>
 /// <param name="roomCache">
 ///   The <see cref="RoomCacheBase"/> instance to which the room belongs.
 /// </param>
 /// <param name="gameStateFactory">Fatory for game state</param>
 /// <param name="maxEmptyRoomTTL">
 ///   A value indicating how long the room instance will be keeped alive
 ///   in the room cache after all peers have left the room.
 /// </param>
 /// <param name="executionFiber">Fiber which will execute rooms actions</param>
 public Room(string name, RoomCacheBase roomCache = null, IGameStateFactory gameStateFactory = null, int maxEmptyRoomTTL = 0, ExtendedPoolFiber executionFiber = null)
     : this(name, executionFiber, roomCache, gameStateFactory, maxEmptyRoomTTL)
 {
     this.ExecutionFiber.Start();
     RemoveRoomPath = RemoveState.Alive;
 }
Exemple #9
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "Room" /> class without a room name.
 /// </summary>
 /// <param name = "name">
 ///   The room name.
 /// </param>
 /// <param name="roomCache">
 ///   The <see cref="RoomCacheBase"/> instance to which the room belongs.
 /// </param>
 /// <param name="gameStateFactory">Fatory for game state</param>
 /// <param name="maxEmptyRoomTTL">
 ///   A value indicating how long the room instance will be keeped alive 
 ///   in the room cache after all peers have left the room.
 /// </param>
 /// <param name="executionFiber">Fiber which will execute rooms actions</param>
 public Room(string name, RoomCacheBase roomCache = null, IGameStateFactory gameStateFactory = null, int maxEmptyRoomTTL = 0, ExtendedPoolFiber executionFiber = null)
     : this(name, executionFiber, roomCache, gameStateFactory, maxEmptyRoomTTL)
 {
     this.ExecutionFiber.Start();
     RemoveRoomPath = RemoveState.Alive;
 }
Exemple #10
0
        /// <summary>
        ///   Initializes a new instance of the <see cref = "Room" /> class.
        /// </summary>
        /// <param name = "name">
        ///   The room name.
        /// </param>
        /// <param name = "executionFiber">
        ///   The execution fiber used to synchronize access to this instance.
        /// </param>
        /// <param name="roomCache">
        ///   The <see cref="RoomCacheBase"/> instance to which the room belongs.
        /// </param>
        /// <param name="gameStateFactory">Fatory for game state</param>
        /// <param name="maxEmptyRoomTTL">
        ///   A value indicating how long the room instance will be keeped alive 
        ///   in the room cache after all peers have left the room.
        /// </param>
        protected Room(string name, ExtendedPoolFiber executionFiber, RoomCacheBase roomCache, IGameStateFactory gameStateFactory = null, int maxEmptyRoomTTL = 0)
        {
            this.name = name;

            this.gameStateFactory = gameStateFactory ?? defaultFactory;
            this.roomState = this.gameStateFactory.Create();
            this.ExecutionFiber = executionFiber ?? new ExtendedPoolFiber();

            this.roomCache = roomCache;
            this.MaxEmptyRoomTTL = maxEmptyRoomTTL;
        }
 public AdventureGame(IGameStateFactory gameStateFactory)
 {
     factory = gameStateFactory;
 }