当前位置: 首页>>代码示例>>C#>>正文


C# NetworkPlayer.SetTeam方法代码示例

本文整理汇总了C#中NetworkPlayer.SetTeam方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkPlayer.SetTeam方法的具体用法?C# NetworkPlayer.SetTeam怎么用?C# NetworkPlayer.SetTeam使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NetworkPlayer的用法示例。


在下文中一共展示了NetworkPlayer.SetTeam方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    static void Main(string[] args)
    {
        int loopStartTime = 0;
        int loopEndTime = 0;
        float deltaSecond = 0;

        //Frequency to return data
        const float ReturnDataPerSecond = 20;
        float lastSentData = 0;

        //Team containers
        ShapeTeamContainer greenTeam = new ShapeTeamContainer(ShapeTeam.GREEN);
        ShapeTeamContainer redTeam = new ShapeTeamContainer(ShapeTeam.RED);

        NetPeerConfiguration config = new NetPeerConfiguration("ShapeSpace");
        config.Port = 55678;
        config.MaximumConnections = maxPlayers;
        config.ConnectionTimeout = 10;
        config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
        config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);

        server = new NetServer(config);
        //Console.WriteLine(server.Configuration.LocalAddress);

        physicsWorld = new World(Vector2.Zero);
        //50px = 1m
        ConvertUnits.SetDisplayUnitToSimUnitRatio(50f);

        try
        {
            server.Start();
        }
        catch(Exception e)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(e);
            Console.ForegroundColor = ConsoleColor.White;
            WaitForKeyPress();
        }

        Console.WriteLine("Server Started Sucessfully!");

        //Main program loop
        while(true)
        {
            deltaSecond = (loopEndTime - loopStartTime) / 1000f;

            lastSentData += deltaSecond;

            loopStartTime = Environment.TickCount;

            //Handle incoming messages
            NetIncomingMessage msg;
            while ((msg = server.ReadMessage()) != null)
            {
                //Console.WriteLine(msg.MessageType);
                switch (msg.MessageType)
                {
                    case NetIncomingMessageType.Data:
                        //A swith handling ShapeSpace custom message types
                        switch((ShapeCustomNetMessageType)msg.ReadByte())
                        {
                            case ShapeCustomNetMessageType.InputUpdate:
                                int playerIndex = msg.ReadInt32();
                                float timeSinceLast = msg.ReadFloat();
                                Vector2 input = msg.ReadVector2();

                                connectedPlayers[playerIndex].inputs.Add(new InputWithTime(timeSinceLast,input));

                                //Console.WriteLine(timeSinceLast + ": " + input.ToString());
                                break;
                            case ShapeCustomNetMessageType.SetupRequest:
                                NetOutgoingMessage returnMessage = server.CreateMessage();

                                NetworkPlayer newPlayer = new NetworkPlayer(physicsWorld, msg.SenderConnection, new Vector2(0,0));

                                //ShapeTeam team = (ShapeTeam)msg.ReadByte();
                                string username = msg.ReadString();

                                try
                                {
                                    //newPlayer.SetTeam(team);
                                    newPlayer.SetUserName(username);

                                    int spot = AddNewPlayer(newPlayer);

                                    newPlayer.indexOnServer = spot;

                                    //Assign the new player to the team with the least amount of players
                                    ShapeTeamContainer newPlayerTeam = greenTeam.GetNumberOfMembers() < redTeam.GetNumberOfMembers() ? greenTeam : redTeam;
                                    bool isBank = newPlayerTeam.AddPlayer(newPlayer.indexOnServer);
                                    newPlayer.SetTeam(newPlayerTeam.GetTeam());
                                    newPlayer.body.Position = ConvertUnits.ToSimUnits(newPlayerTeam.basePosition);

                                    if (isBank)
                                        newPlayer.SetClass(new ShapeClassBank());
                                    else
                                        newPlayer.SetClass(new ShapeClassKnocker());

                                    newPlayer.OnCreateRemnant += CreateRemnant;
//.........这里部分代码省略.........
开发者ID:TheKalleAnka,项目名称:ShapeSpace,代码行数:101,代码来源:ShapeSpaceServer.cs


注:本文中的NetworkPlayer.SetTeam方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。