Beispiel #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            server       = new WebServer();
            renderTarget = new RenderTarget2D(GraphicsDevice, 1280, 720);
            Screen.InitScreen(renderTarget);
            this.graphics.PreferredBackBufferWidth = 1280;
            graphics.PreferredBackBufferHeight     = 720;
            graphics.ApplyChanges();
            _game = new Desktop.Online.Game(server, Content, GraphicsDevice);
            _game.Start();

            server.Subscribe(ClientToServerStatus.Join, (a) =>
            {
                if (_game.PlayersConnected.Count >= 4)
                {
                    DropConnection(a);
                    return;
                }

                Console.WriteLine(a.ID);
                ConnectionInfo info = server.AddUser(a.ID, a.ServerStatus);
                int playerNum       = _game.PlayerJoin(new Player(info, a.Data["name"].ToString()));
                var joinInfo        = new ServerStatusHandler.JoinInfo(playerNum, a.ID);

                var joinMessage = new
                                  ServerMessage <ServerStatusHandler.JoinInfo>
                                      (ServerToClientStatuses.JoinInfo, joinInfo);

                a.ServerStatus.Send(joinMessage);
            });

            base.Initialize();
        }
Beispiel #2
0
 public SceneManager(ContentManager content,
                     GraphicsDevice graphicsDevice,
                     SpriteBatch spriteBatch,
                     Desktop.Online.Game game,
                     WebServer Server)
 {
     Content        = content;
     GraphicsDevice = graphicsDevice;
     SpriteBatch    = spriteBatch;
     Games          = game;
     WebServer      = Server;
 }