コード例 #1
0
ファイル: Main.cs プロジェクト: RobinLieson/ar-battle-boats
        /// <summary>
        /// Called when a gamer joins the game
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void session_GamerJoined(object sender, GamerJoinedEventArgs e)
        {
            Console.WriteLine("A new Gamer, " + e.Gamer.Gamertag + " has joined");
            if (gameMode == GameMode.Network_Multiplayer)
            {
                lob.AddPlayerToLobby(e.Gamer.Gamertag);
            }
            foreach (PlayerInfo info in activePlayers)
            {
                if (info.PlayerName == e.Gamer.Gamertag)
                    return;
            }

            PlayerInfo player = new PlayerInfo();
            bool result = player.GetPlayerInfoFromServer(e.Gamer.Gamertag, SERVER_IP, SERVER_PORT_NUM);
            if (!result)
            {
                player = new PlayerInfo();
                player.PlayerName = e.Gamer.Gamertag;
                player.Ammo_Level = 0;
                player.Armour_Level = 0;
                player.Money = 10;
                player.Speed_Level = 0;
                Console.WriteLine("Creating new profile");
                Console.WriteLine(player.ToString());
            }
            player.Player_Ship = AvailableShips[0];

            if (gameMode == GameMode.Network_Multiplayer && e.Gamer.Gamertag != SignedInGamer.SignedInGamers[0].Gamertag)
                player.PlayerLocation = Player_Location.Remote;
            else
                player.PlayerLocation = Player_Location.Local;

            activePlayers.Add(player);

            if (player.PlayerName == SignedInGamer.SignedInGamers[0].Gamertag)
            {
                playerIndex = activePlayers.Count - 1;
            }
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: RobinLieson/ar-battle-boats
        //Networking
        /// <summary>
        /// Get the player info from the Server
        /// </summary>
        private void GetPlayerInfo()
        {
            PlayerInfo playerInfo1; //Information for Player 1

            playerInfo1 = new PlayerInfo();
            bool result = playerInfo1.GetPlayerInfoFromServer(SignedInGamer.SignedInGamers[0].Gamertag, SERVER_IP, SERVER_PORT_NUM);
            if (!result)
            {
                playerInfo1 = new PlayerInfo();
                playerInfo1.PlayerName = SignedInGamer.SignedInGamers[0].Gamertag;
                playerInfo1.Ammo_Level = 0;
                playerInfo1.Armour_Level = 0;
                playerInfo1.Money = 0;
                playerInfo1.Speed_Level = 0;
                playerInfo1.Player_Ship = AvailableShips[0];
                playerInfo1.PlayerLocation = Player_Location.Local;
                Console.WriteLine("Creating new profile");
                Console.Write(playerInfo1.ToString());
            }

            playerInfo1.Player_Ship = AvailableShips[0];
            activePlayers.Add(playerInfo1);
        }