示例#1
0
        /*
         * Draws the waiting room
         */
        void DrawWR()
        {
            GraphicsDevice.Clear(new Color(16, 16, 16, 255));

            string message = "Waiting for players to join game...\n\nCurrent Players:\n";
            String status  = "Status (Press 'r')\n";
            GamerCollection <NetworkGamer> players = networkSession.AllGamers;

            for (int i = 0; i < players.Count; i++)
            {
                message += players[i].ToString() + "\n";
                if (players[i].IsReady)
                {
                    status += "Ready" + "\n";
                }
                else
                {
                    status += "Not Ready" + "\n";
                }
            }
            if (isHost)
            {
                message += "\nPress 's' to force start game";
            }

            spriteBatch.Begin();

            spriteBatch.DrawString(lobbyFont, "Press 't' to talk", new Vector2(160, 430), Color.White);
            spriteBatch.DrawString(lobbyFont, status, new Vector2(350, 207), Color.White);
            spriteBatch.DrawString(lobbyFont, message, new Vector2(160, 160), Color.White);
            spriteBatch.DrawString(lobbyFont, chatText, new Vector2(160, 460), Color.White);

            spriteBatch.End();
        }
示例#2
0
 private NetworkSession(NetworkSessionType sessionType, int maxGamers, int privateGamerSlots, NetworkSessionProperties sessionProperties, bool isHost, int hostGamer, AvailableNetworkSession availableSession)
     : this()
 {
     if (sessionProperties == null)
     {
         throw new ArgumentNullException("sessionProperties");
     }
     this._allGamers        = new GamerCollection <NetworkGamer>();
     this._localGamers      = new GamerCollection <LocalNetworkGamer>();
     this._remoteGamers     = new GamerCollection <NetworkGamer>();
     this._previousGamers   = new GamerCollection <NetworkGamer>();
     this.hostingGamer      = (NetworkGamer)null;
     this.commandQueue      = new Queue <CommandEvent>();
     this.sessionType       = sessionType;
     this.maxGamers         = maxGamers;
     this.privateGamerSlots = privateGamerSlots;
     this.sessionProperties = sessionProperties;
     this.isHost            = isHost;
     this.hostGamerIndex    = hostGamer;
     if (isHost)
     {
         this.networkPeer = new MonoGamerPeer(this, (AvailableNetworkSession)null);
     }
     else if (this.networkPeer == null)
     {
         this.networkPeer = new MonoGamerPeer(this, availableSession);
     }
     this.commandQueue.Enqueue(new CommandEvent((ICommand) new CommandGamerJoined(hostGamer, this.isHost, true)));
 }
示例#3
0
        /*
         * Draws the lobby screen
         */
        void DrawLobby()
        {
            string message = "A = Host Game\n" +
                             "\nGames( 'r' to refresh )";
            string players = "Players\n";

            if (Gamer.SignedInGamers.Count != 0 && games == null)
            {
                // Search for Games
                games = NetworkSession.Find(NetworkSessionType.SystemLink, 1, null);
            }
            if (games != null)
            {
                for (int i = 0; i < games.Count(); i++)
                {
                    message += "\n" + i + ") " + games[i].HostGamertag + "'s Game";
                    players += games[i].CurrentGamerCount.ToString() + "\n";
                }
            }

            spriteBatch.Begin();

            spriteBatch.Draw(background_lobby, mainFrame, Color.White);

            spriteBatch.DrawString(lobbyFont, players, new Vector2(500, 270), Color.Black);
            spriteBatch.DrawString(lobbyFont, "Lobby", new Vector2(100, 250), Color.Black);
            spriteBatch.DrawString(lobbyFont, message, new Vector2(100, 270), Color.Black);

            spriteBatch.End();
        }
示例#4
0
        /// <summary>
        /// Collect Changes from the host
        /// </summary>
        /// <param name="gamers">Clients.</param>
        public void clientReadPackets(GamerCollection <LocalNetworkGamer> gamers)
        {
            UInt64[] data = new UInt64[2];
            Command  command;

            foreach (LocalNetworkGamer gamer in gamers)
            {
                while (gamer.IsDataAvailable)
                {
                    NetworkGamer sender;

                    gamer.ReceiveData(_reader, out sender);

                    if (sender.IsLocal)
                    {
                        return;
                    }

                    data[0] = (UInt64)_reader.ReadInt64();
                    data[1] = (UInt64)_reader.ReadInt64();

                    command = new Command(data);
                    if (command.CmdType == Command.T_COMMAND.ADD)
                    {
                    }
                    else if (command.CmdType == Command.T_COMMAND.SET)
                    {
                    }
                }
            }
        }
示例#5
0
        /// <summary>
        /// Collect requests from clients.
        /// </summary>
        /// <param name="gamers">List of Clients.</param>
        public void serverReadPackets(GamerCollection <LocalNetworkGamer> gamers, GameTime time)
        {
            UInt64[] data = new UInt64[2];

            foreach (LocalNetworkGamer gamer in gamers)
            {
                while (gamer.IsDataAvailable)
                {
                    NetworkGamer sender;
                    gamer.ReceiveData(_reader, out sender);

                    if (sender.IsLocal)
                    {
                        return;
                    }

                    data[0] = (UInt64)_reader.ReadInt64();
                    data[1] = (UInt64)_reader.ReadInt64();
                    Command command = new Command(data);
                    // TODO: Get Player from PlayerList
                    if (NewCommandEvent != null)
                    {
                        NewCommandEvent.Invoke(this, new NewCommandEventArgs(command, time.TotalGameTime, new Player()));
                    }
                }
            }
        }
示例#6
0
        /*
         * Updates the wating room
         */
        void UpdateWR()
        {
            KeyboardState keyState = Keyboard.GetState();

            if (networkSession.SessionState == NetworkSessionState.Playing)
            {
                beginGame();
            }


            //startgame if host
            if (keyState.IsKeyDown(Keys.S) && isHost && !isChatting)
            {
                beginGame();
            }
            //chat
            if (keyState.IsKeyDown(Keys.T) && !isChatting)
            {
                chat();
            }
            if (keyState.IsKeyDown(Keys.R) && !isChatting)
            {
                networkSession.LocalGamers[0].IsReady = true;
            }

            if (isHost)
            {
                bool start = true;
                GamerCollection <NetworkGamer> players = networkSession.AllGamers;
                for (int i = 0; i < players.Count; i++)
                {
                    if (!players[i].IsReady)
                    {
                        start = false;
                    }
                }
                if (start)
                {
                    beginGame();
                }
            }

            recievePacket();

            String inputString;

            if (KeyboardResult != null && KeyboardResult.IsCompleted)
            {
                inputString = Guide.EndShowKeyboardInput(KeyboardResult);
                if (inputString == null)
                {
                    inputString = "";
                }
                KeyboardResult = null;

                sendChatPacket(inputString);
            }
        }
示例#7
0
 /// <summary>
 /// Broadcast all changes to Clients.
 /// </summary>
 /// <param name="gamers">List of Clients.</param>
 public void serverWritePackets(GamerCollection <LocalNetworkGamer> gamers)
 {
     foreach (LocalNetworkGamer gamer in gamers)
     {
         // TODO: Re-impliment
         if (_writer.Length > 0)
         {
             gamer.SendData(_writer, SendDataOptions.ReliableInOrder);
         }
     }
 }
        private NetworkSession(NetworkSessionType sessionType, int maxGamers, int privateGamerSlots, NetworkSessionProperties sessionProperties, bool isHost, int hostGamer, AvailableNetworkSession availableSession) : this()
        {
            if (sessionProperties == null)
            {
                throw new ArgumentNullException("sessionProperties");
            }

            _allGamers   = new GamerCollection <NetworkGamer>();
            _localGamers = new GamerCollection <LocalNetworkGamer>();
//			for (int x = 0; x < Gamer.SignedInGamers.Count; x++) {
//				GamerStates states = GamerStates.Local;
//				if (x == 0)
//					states |= GamerStates.Host;
//				LocalNetworkGamer localGamer = new LocalNetworkGamer(this, (byte)x, states);
//				localGamer.SignedInGamer = Gamer.SignedInGamers[x];
//				_allGamers.AddGamer(localGamer);
//				_localGamers.AddGamer(localGamer);
//
//				// We will attach a property change handler to local gamers
//				//  se that we can broadcast the change to other peers.
//				localGamer.PropertyChanged += HandleGamerPropertyChanged;
//
//			}

            _remoteGamers   = new GamerCollection <NetworkGamer>();
            _previousGamers = new GamerCollection <NetworkGamer>();
            hostingGamer    = null;

            commandQueue = new Queue <CommandEvent>();

            this.sessionType       = sessionType;
            this.maxGamers         = maxGamers;
            this.privateGamerSlots = privateGamerSlots;
            this.sessionProperties = sessionProperties;
            this.isHost            = isHost;
            this.hostGamerIndex    = hostGamer;
            if (isHost)
            {
                networkPeer = new MonoGamerPeer(this, null);
            }
            else
            {
                if (networkPeer == null)
                {
                    networkPeer = new MonoGamerPeer(this, availableSession);
                }
            }

            CommandGamerJoined gj = new CommandGamerJoined(hostGamer, this.isHost, true);

            commandQueue.Enqueue(new CommandEvent(gj));
        }
示例#9
0
        /// <summary>
        /// Write requests to the host.
        /// </summary>
        /// <param name="gamers">Clients</param>
        /// <param name="host">Host</param>
        public void clientWritePackets(GamerCollection <LocalNetworkGamer> gamers, NetworkGamer host)
        {
            Command cmd;

            foreach (LocalNetworkGamer gamer in gamers)
            {
                // TODO: Reimpliment.
                if (_writer.Length > 0)
                {
                    gamer.SendData(_writer, SendDataOptions.ReliableInOrder, host);
                }
            }
        }
示例#10
0
        /*
         * Called when game should begin
         */
        void beginGame()
        {
            graphics.PreferredBackBufferHeight = 800;
            graphics.PreferredBackBufferWidth  = 600;
            graphics.ApplyChanges();

            deterministicGame.Initialize();
            latency     = 1;
            lrFrame     = 1;
            previousLRF = 0;
            secondLRF   = 0;
            frames      = new Dictionary <int, frame>();

            frameNumber  = 0;
            stallCounter = 0;
            gameStarted  = true;
            if (isHost)
            {
                networkSession.StartGame();
            }

            players      = networkSession.AllGamers;
            pid          = new int[4];
            myIdentifier = getIdentifier(networkSession.LocalGamers[0].Id);

            others = new player[players.Count];

            for (int i = 0; i < players.Count; i++)
            {
                pid[i] = (int)players[i].Id;

                others[i] = new player(players[i], getIdentifier(players[i].Id), deterministicGame);
            }

            Array.Sort(pid);

            myPlayer = null;
            for (int i = 0; i < others.Length; i++)
            {
                if (others[i].me == myIdentifier)
                {
                    myPlayer = others[i];
                }
            }
        }
示例#11
0
        public void update(GameTime elps, GamerCollection <LocalNetworkGamer> Gamers)
        {
            if (HostSession)
            {
                NetworkController.serverReadPackets(Gamers, elps);
                Queue <Command> commandsToDo = new Queue <Command>(2);
                Command         nextCommand  = new Command();
                //needs to be outvalue
                monirator.UpdateSchedule(elps);
                while (monirator.GetNextScheduledCommand(ref nextCommand))
                {
                    commandsToDo.Enqueue(nextCommand);
                }

                simulator.dispatchCommands(commandsToDo);
                simulator.step(elps);
            }
            else
            {
            }
        }
示例#12
0
        public void update(GameTime elps, GamerCollection<LocalNetworkGamer> Gamers)
        {
            if (HostSession)
            {
                NetworkController.serverReadPackets(Gamers, elps);
                Queue<Command> commandsToDo = new Queue<Command>(2);
                Command nextCommand = new Command();
                //needs to be outvalue
                monirator.UpdateSchedule(elps);
                while (monirator.GetNextScheduledCommand(ref nextCommand))
                {
                    commandsToDo.Enqueue(nextCommand);
                }

                simulator.dispatchCommands(commandsToDo);
                simulator.step(elps);
            }
            else
            {

            }
        }
示例#13
0
        protected virtual SmuckPlayer CreatePlayer(int gamerIndex)
        {
            NetworkGamer g = null;
            GamerCollection <LocalNetworkGamer> lngc = NetworkManager.Session.LocalGamers;

            for (int i = 0; i < lngc.Count; i++)
            {
                if (lngc[i].SignedInGamer != null && (int)lngc[i].SignedInGamer.PlayerIndex == gamerIndex)
                {
                    g = lngc[i];
                    break;
                }
            }

            SmuckPlayer result = players[gamerIndex];

            if (result != null)
            {
                //result.manualPlayerDestroy = true;
                //result.ReplaceView(playerDefinitionName + gamerIndex);
                result.Stop();
                if (result.body != null)
                {
                    result.body.SetLinearVelocity(Vector2.Zero);
                }

                if (!this.Contains(result))
                {
                    AddChild(result);
                }

                stage.audio.PlaySound(Sfx.respawn);
                //result.manualPlayerDestroy = false;
            }
            else
            {
                //PlayerIndex gamePadIndex = (PlayerIndex)(players.FindAll(p => p.isLocal).Count);
                result = (SmuckPlayer)CreateInstanceAt("player" + gamerIndex, "players" + gamerIndex,
                                                       startLocations[gamerIndex, 0],
                                                       0,
                                                       startLocations[gamerIndex, 2],
                                                       playerDepthCount++);

                //result.isLocal = g.IsLocal;
                //result.NetworkGamer = g;
                //result.NetworkId = g.Id;
                result.Depth        = playerDepthCount;
                result.gamePadIndex = (PlayerIndex)gamerIndex;
                if (g is LocalNetworkGamer)
                {
                    result.gamePadIndex = ((LocalNetworkGamer)g).SignedInGamer.PlayerIndex;

                    // sometimes that isn't right, or even connected it seems, so find a connected controller
                    if (!GamePad.GetState(result.gamePadIndex).IsConnected)
                    {
                        for (PlayerIndex pi = PlayerIndex.One; pi < PlayerIndex.Four; pi++)
                        {
                            if (GamePad.GetState(pi).IsConnected)
                            {
                                result.gamePadIndex = pi;
                                break;
                            }
                        }
                        GamePadCapabilities gpt = GamePad.GetCapabilities(result.gamePadIndex);
                    }
                    g.Tag = result;
                }



                // compact framework doesn't support Array.Find
                // InputManager im = Array.Find(inputManagers, m => (m != null) && (m.NetworkGamer == g));
                InputManager im = inputManagers[gamerIndex];
                im.Player = result;
            }

            result.laneCount = lanes.Length;
            int startLane = startLocations[gamerIndex, 1] == 0 ? 0 : result.laneCount - 1;

            result.snapLaneY = lanes[startLane].yLocation + lanes[startLane].laneHeight / 2;
            result.Reset(startLocations[gamerIndex, 0], result.snapLaneY, startLocations[gamerIndex, 2]);
            result.Lane = lanes[GetLaneFromY((int)result.Y)];

            gameOverlay.SetPlayer(result);

            return(result);
        }
示例#14
0
 private NetworkSession(NetworkSessionType sessionType, int maxGamers, int privateGamerSlots, NetworkSessionProperties sessionProperties, bool isHost, int hostGamer, AvailableNetworkSession availableSession)
   : this()
 {
   if (sessionProperties == null)
     throw new ArgumentNullException("sessionProperties");
   this._allGamers = new GamerCollection<NetworkGamer>();
   this._localGamers = new GamerCollection<LocalNetworkGamer>();
   this._remoteGamers = new GamerCollection<NetworkGamer>();
   this._previousGamers = new GamerCollection<NetworkGamer>();
   this.hostingGamer = (NetworkGamer) null;
   this.commandQueue = new Queue<CommandEvent>();
   this.sessionType = sessionType;
   this.maxGamers = maxGamers;
   this.privateGamerSlots = privateGamerSlots;
   this.sessionProperties = sessionProperties;
   this.isHost = isHost;
   this.hostGamerIndex = hostGamer;
   this.commandQueue.Enqueue(new CommandEvent((ICommand) new CommandGamerJoined(hostGamer, this.isHost, true)));
 }
示例#15
0
        internal NetworkSession(
            NetworkSessionProperties properties,
            NetworkSessionType type,
            int maxGamers,
            int privateGamerSlots,
            int maxLocal,
            IEnumerable <SignedInGamer> localGamers
            )
        {
            SessionProperties = properties;
            SessionType       = type;
            MaxGamers         = maxGamers;
            PrivateGamerSlots = privateGamerSlots;

            // Create Gamer lists

            List <LocalNetworkGamer> locals = new List <LocalNetworkGamer>();

            if (localGamers == null)
            {
                // FIXME: Check for mismatch in SignedInGamers Count -flibit
                maxLocalGamers = maxLocal;
                for (int i = 0; i < Gamer.SignedInGamers.Count && i < maxLocalGamers; i += 1)
                {
                    // FIXME: Guests are fake! -flibit
                    if (!Gamer.SignedInGamers[i].IsGuest)
                    {
                        locals.Add(new LocalNetworkGamer(
                                       Gamer.SignedInGamers[i],
                                       this
                                       ));
                    }
                }
            }
            else
            {
                maxLocalGamers = 0;
                foreach (SignedInGamer gamer in localGamers)
                {
                    locals.Add(new LocalNetworkGamer(gamer, this));
                    maxLocalGamers += 1;
                }
            }
            LocalGamers = new GamerCollection <LocalNetworkGamer>(locals);

            List <NetworkGamer> remoteGamers = new List <NetworkGamer>();

            RemoteGamers = new GamerCollection <NetworkGamer>(remoteGamers);

            List <NetworkGamer> allGamers = new List <NetworkGamer>();

            allGamers.AddRange(remoteGamers);
            allGamers.AddRange(locals);
            AllGamers = new GamerCollection <NetworkGamer>(allGamers);

            PreviousGamers = new GamerCollection <NetworkGamer>(
                new List <NetworkGamer>()
                );

            // Create host data

            Host = LocalGamers[0];

            if (IsHost)
            {
                AllowHostMigration  = false;
                AllowJoinInProgress = false;
                SessionState        = NetworkSessionState.Lobby;
            }

            // Event hookups
            networkEvents = new Queue <NetworkEvent>();
            foreach (NetworkGamer gamer in AllGamers)
            {
                NetworkSession.NetworkEvent evt = new NetworkEvent()
                {
                    Type  = NetworkEventType.GamerJoin,
                    Gamer = gamer
                };
                SendNetworkEvent(evt);
            }

            // Other defaults

            SimulatedLatency    = TimeSpan.Zero;
            SimulatedPacketLoss = 0.0f;
            IsDisposed          = false;

            // TODO: Everything below
            BytesPerSecondReceived = 0;
            BytesPerSecondSent     = 0;
        }
示例#16
0
 public void Update(Microsoft.Xna.Framework.GameTime time, GamerCollection<LocalNetworkGamer> Gamers)
 {
     replayer.updateBuffer(time);
     GameController.update(time, Gamers);
 }
示例#17
0
		public NetworkMachine ()
		{
			gamers = new GamerCollection<NetworkGamer>();
		}
示例#18
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            //IN MENU
            if (inMenu)
            {
                GraphicsDevice.Clear(Color.CornflowerBlue);

                // TODO: Add your drawing code here
                spriteBatch.Begin(SpriteBlendMode.AlphaBlend);

                //spriteBatch.Draw(crosshair, new Vector2(Mouse.GetState().X - 5, Mouse.GetState().Y - 5), Color.White);
                base.Draw(gameTime);
                //activeS.Draw(gameTime);
                spriteBatch.End();
            }
            else
            {
                //IN LOBBY
                if (networkSession == null)
                {
                    GraphicsDevice.Clear(new Color(16, 16, 16, 255));
                    // If we are in the lobby
                    DrawLobby();
                }

                //IN GAME
                else //Draw the game
                {
                    if (gameStarted)
                    {
                        GraphicsDevice.Clear(Color.CornflowerBlue);

                        spriteBatch.Begin();


                        // Draw a few instructions.

                        if (paused && gameTime.TotalRealTime.Milliseconds < 500)
                        {
                            spriteBatch.DrawString(font, "-=> Paused <=-", new Vector2(10, 130), Color.White);
                        }

                        // Let the game draw itself.

                        deterministicGame.Draw(spriteBatch);


                        //Begin transition music.
                        if (deterministicGame.currentLevel.levelTransition && deterministicGame.currentLevel.count > 600)
                        {
                            musicControl.changeToAwesomeMusic();
                        }
                        if (musicControl.gameplayStarted &&
                            !deterministicGame.currentLevel.levelTransition)
                        {
                            musicControl.changeToGameplayMusic();
                        }

                        //Draw level stats
                        if (deterministicGame.currentLevel.levelTransition && deterministicGame.currentLevel.count > 600)
                        {
                            spriteBatch.DrawString(lobbyFont, "CURRENT STATS", new Vector2(220, 415), Color.Black);

                            string players = this.players[0].ToString().ToUpper();
                            string points  = "POINTS:        " + deterministicGame.playerOnePoints;


                            if (this.players.Count == 2)
                            {
                                players += "                         " + this.players[1].ToString().ToUpper();
                                points  += "                                      " + deterministicGame.playerTwoPoints;
                            }

                            spriteBatch.DrawString(lobbyFont, players, new Vector2(110, 440), Color.Black);
                            spriteBatch.DrawString(lobbyFont, points, new Vector2(50, 465), Color.Black);
                        }


                        spriteBatch.End();
                    }
                    //IN Waiting Room
                    else
                    {
                        DrawWR();
                    }
                }

                //base.Draw(gameTime);
            }
        }
示例#19
0
 public void Update(Microsoft.Xna.Framework.GameTime time, GamerCollection<LocalNetworkGamer> Gamers)
 {
     replayer.updateBuffer(time);
     GameController.update(time, Gamers);
 }
示例#20
0
 public NetworkMachine()
 {
     this.gamers = new GamerCollection <NetworkGamer>();
 }
示例#21
0
        /// <summary>
        /// Collect Changes from the host
        /// </summary>
        /// <param name="gamers">Clients.</param>
        public void clientReadPackets(GamerCollection<LocalNetworkGamer> gamers)
        {
            UInt64[] data = new UInt64[2];
            Command command;

            foreach (LocalNetworkGamer gamer in gamers)
            {
                while (gamer.IsDataAvailable)
                {
                    NetworkGamer sender;

                    gamer.ReceiveData(_reader, out sender);

                    if (sender.IsLocal)
                        return;

                    data[0] = (UInt64)_reader.ReadInt64();
                    data[1] = (UInt64)_reader.ReadInt64();

                    command = new Command(data);
                    if (command.CmdType == Command.T_COMMAND.ADD)
                    {

                    }
                    else if (command.CmdType == Command.T_COMMAND.SET)
                    {

                    }
                }
            }
        }
示例#22
0
 public void Update(Microsoft.Xna.Framework.GameTime time, GamerCollection <LocalNetworkGamer> Gamers)
 {
     _frame.update(time);
 }
示例#23
0
 /// <summary>
 /// Broadcast all changes to Clients.
 /// </summary>
 /// <param name="gamers">List of Clients.</param>
 public void serverWritePackets(GamerCollection<LocalNetworkGamer> gamers)
 {
     foreach (LocalNetworkGamer gamer in gamers)
     {
         // TODO: Re-impliment
         if(_writer.Length > 0)
             gamer.SendData(_writer, SendDataOptions.ReliableInOrder);
     }
 }
示例#24
0
        private NetworkSession(NetworkSessionType sessionType, int maxGamers, int privateGamerSlots, NetworkSessionProperties sessionProperties, bool isHost, int hostGamer, AvailableNetworkSession availableSession)
            : this()
        {
            if (sessionProperties == null) {
                throw new ArgumentNullException ("sessionProperties");
            }

            _allGamers = new GamerCollection<NetworkGamer>();
            _localGamers = new GamerCollection<LocalNetworkGamer>();
            _remoteGamers = new GamerCollection<NetworkGamer>();
            _previousGamers = new GamerCollection<NetworkGamer>();
            hostingGamer = null;

            commandQueue = new Queue<CommandEvent>();

            this.sessionType = sessionType;
            this.maxGamers = maxGamers;
            this.privateGamerSlots = privateGamerSlots;
            this.sessionProperties = sessionProperties;
            this.isHost = isHost;
            this.hostGamerIndex = hostGamer;
            if (isHost)
                networkPeer = new MonoGamerPeer(this, null);
            else
            {
                if (networkPeer == null)
                    networkPeer = new MonoGamerPeer(this, availableSession);
            }

            CommandGamerJoined gj = new CommandGamerJoined(hostGamer, this.isHost, true);
            commandQueue.Enqueue(new CommandEvent(gj));
        }
示例#25
0
        /*
         * Draws the lobby screen
         */
        void DrawLobby()
        {
            string message = "A = Host Game\n" +
                       "\nGames( 'r' to refresh )";
            string players = "Players\n";
            if (Gamer.SignedInGamers.Count != 0 && games == null)
            {
                // Search for Games
                games = NetworkSession.Find(NetworkSessionType.SystemLink, 1, null);
            }
            if (games != null)
            {
                for (int i = 0; i < games.Count(); i++)
                {

                    message += "\n" + i + ") " + games[i].HostGamertag + "'s Game";
                    players += games[i].CurrentGamerCount.ToString() + "\n";
                }
            }

            spriteBatch.Begin();

            spriteBatch.Draw(background_lobby, mainFrame, Color.White);

            spriteBatch.DrawString(lobbyFont, players, new Vector2(500, 270), Color.Black);
            spriteBatch.DrawString(lobbyFont, "Lobby", new Vector2(100, 250), Color.Black);
            spriteBatch.DrawString(lobbyFont, message, new Vector2(100, 270), Color.Black);

            spriteBatch.End();
        }
示例#26
0
		private NetworkSession (NetworkSessionType sessionType, int maxGamers, int privateGamerSlots, NetworkSessionProperties sessionProperties, bool isHost, int hostGamer, AvailableNetworkSession availableSession) : this()
		{
			if (sessionProperties == null) {
				throw new ArgumentNullException ("sessionProperties");
			}
			
			_allGamers = new GamerCollection<NetworkGamer>();
			_localGamers = new GamerCollection<LocalNetworkGamer>();
//			for (int x = 0; x < Gamer.SignedInGamers.Count; x++) {
//				GamerStates states = GamerStates.Local;
//				if (x == 0)
//					states |= GamerStates.Host;
//				LocalNetworkGamer localGamer = new LocalNetworkGamer(this, (byte)x, states);
//				localGamer.SignedInGamer = Gamer.SignedInGamers[x];
//				_allGamers.AddGamer(localGamer);
//				_localGamers.AddGamer(localGamer);
//				
//				// We will attach a property change handler to local gamers
//				//  se that we can broadcast the change to other peers.
//				localGamer.PropertyChanged += HandleGamerPropertyChanged;	
//				
//			}

			_remoteGamers = new GamerCollection<NetworkGamer>();
			_previousGamers = new GamerCollection<NetworkGamer>();
			hostingGamer = null;
			
			commandQueue = new Queue<CommandEvent>();			
			
			this.sessionType = sessionType;
			this.maxGamers = maxGamers;
			this.privateGamerSlots = privateGamerSlots;
			this.sessionProperties = sessionProperties;
			this.isHost = isHost;
			this.hostGamerIndex = hostGamer;            
            if (isHost)
                networkPeer = new MonoGamerPeer(this, null);
            else
            {
                if (networkPeer == null)
                    networkPeer = new MonoGamerPeer(this, availableSession);
            }
            			
			CommandGamerJoined gj = new CommandGamerJoined(hostGamer, this.isHost, true);
			commandQueue.Enqueue(new CommandEvent(gj));
		}
示例#27
0
 public void Update(Microsoft.Xna.Framework.GameTime time, GamerCollection<LocalNetworkGamer> Gamers )
 {
     GameController.update(time, Gamers);
     _frame.update(time);
 }
示例#28
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            //IN MENU
            if (inMenu)
            {

                GraphicsDevice.Clear(Color.CornflowerBlue);

                // TODO: Add your drawing code here
                spriteBatch.Begin(SpriteBlendMode.AlphaBlend);

                //spriteBatch.Draw(crosshair, new Vector2(Mouse.GetState().X - 5, Mouse.GetState().Y - 5), Color.White);
                base.Draw(gameTime);
                //activeS.Draw(gameTime);
                spriteBatch.End();
            }
            else
            {
                //IN LOBBY
                if (networkSession == null)
                {
                    GraphicsDevice.Clear(new Color(16, 16, 16, 255));
                    // If we are in the lobby
                    DrawLobby();
                }

                //IN GAME
                else //Draw the game
                {
                    if (gameStarted)
                    {
                        GraphicsDevice.Clear(Color.CornflowerBlue);

                        spriteBatch.Begin();

                        
                        // Draw a few instructions.

                        if (paused && gameTime.TotalRealTime.Milliseconds < 500)
                            spriteBatch.DrawString(font, "-=> Paused <=-", new Vector2(10, 130), Color.White);

                        // Let the game draw itself.

                        deterministicGame.Draw(spriteBatch);

                        
                        //Begin transition music. 
                        if (deterministicGame.currentLevel.levelTransition && deterministicGame.currentLevel.count > 600)
                        {
                            musicControl.changeToAwesomeMusic();
                        }
                        if (musicControl.gameplayStarted &&
                            !deterministicGame.currentLevel.levelTransition)
                        {
                            musicControl.changeToGameplayMusic();
                        }

                        //Draw level stats
                        if (deterministicGame.currentLevel.levelTransition && deterministicGame.currentLevel.count > 600)
                        {
                            spriteBatch.DrawString(lobbyFont, "CURRENT STATS", new Vector2(220, 415), Color.Black);

                            string players = this.players[0].ToString().ToUpper();
                            string points  = "POINTS:        " + deterministicGame.playerOnePoints;
                            

                            if (this.players.Count == 2)
                            {
                                
                                players += "                         " + this.players[1].ToString().ToUpper();
                                points += "                                      " + deterministicGame.playerTwoPoints;
                                
                            }

                            spriteBatch.DrawString(lobbyFont, players, new Vector2(110, 440), Color.Black);
                            spriteBatch.DrawString(lobbyFont, points, new Vector2(50, 465), Color.Black);
                        }


                        spriteBatch.End();
                    }
                    //IN Waiting Room
                    else
                        DrawWR();
                }

                //base.Draw(gameTime);
            }

        }
示例#29
0
 /// <summary>
 /// Write requests to the host.
 /// </summary>
 /// <param name="gamers">Clients</param>
 /// <param name="host">Host</param>
 public void clientWritePackets(GamerCollection<LocalNetworkGamer> gamers, NetworkGamer host)
 {
     Command cmd;
     foreach (LocalNetworkGamer gamer in gamers)
     {
         // TODO: Reimpliment.
         if(_writer.Length > 0)
             gamer.SendData(_writer, SendDataOptions.ReliableInOrder, host);
     }
 }
示例#30
0
        /*
         * Called when game should begin
         */
        void beginGame()
        {

            graphics.PreferredBackBufferHeight = 800;
            graphics.PreferredBackBufferWidth = 600;
            graphics.ApplyChanges();

            deterministicGame.Initialize();
            latency = 1;
            lrFrame = 1;
            previousLRF = 0;
            secondLRF = 0;
            frames = new Dictionary<int, frame>();

            frameNumber = 0;
            stallCounter = 0;
            gameStarted = true;
            if (isHost)
                networkSession.StartGame();

            players = networkSession.AllGamers;
            pid = new int[4];
            myIdentifier = getIdentifier(networkSession.LocalGamers[0].Id);

            others = new player[players.Count];

            for (int i = 0; i < players.Count; i++)
            {
                pid[i] = (int)players[i].Id;

                others[i] = new player(players[i], getIdentifier(players[i].Id), deterministicGame);
            }

            Array.Sort(pid);

            myPlayer = null;
            for (int i = 0; i < others.Length; i++)
            {
                if (others[i].me == myIdentifier)
                    myPlayer = others[i];
            }

        }
示例#31
0
        /// <summary>
        /// Collect requests from clients.
        /// </summary>
        /// <param name="gamers">List of Clients.</param>
        public void serverReadPackets(GamerCollection<LocalNetworkGamer> gamers, GameTime time)
        {
            UInt64[] data = new UInt64[2];

            foreach (LocalNetworkGamer gamer in gamers)
            {
                while (gamer.IsDataAvailable)
                {
                    NetworkGamer sender;
                    gamer.ReceiveData(_reader, out sender);

                    if (sender.IsLocal)
                        return;

                    data[0] = (UInt64)_reader.ReadInt64();
                    data[1] = (UInt64)_reader.ReadInt64();
                    Command command = new Command(data);
                    // TODO: Get Player from PlayerList
                    if(NewCommandEvent != null)
                        NewCommandEvent.Invoke(this, new NewCommandEventArgs(command, time.TotalGameTime, new Player()));
                }
            }
        }