コード例 #1
0
        uint entitiesCount; //for id stuff

        public Server(short port, int maxPlayers, int maxEntities, int defaultFraction)
        {
            entitiesCount = 4;
            connections   = new ConcurrentDictionary <int, Connection>();
            connectionIds = new IdMap(maxPlayers);

            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket.Bind(new IPEndPoint(IPAddress.Any, port));
            socket.Listen(maxPlayers);

            game = new Game(ref connections);

            /* Initialize Map */

            Fraction fr1 = new Fraction(ref connections);
            Fraction fr2 = new Fraction(ref connections);
            Fraction fr3 = new Fraction(ref connections);
            Fraction fr4 = new Fraction(ref connections);

            fr1.AddEntity(new Entity(32, 32, 16, 0));
            fr1.AddEntity(new Entity(64, 64, 32, 1));

            fr2.AddEntity(new Entity(608, 32, 16, 2));
            fr2.AddEntity(new Entity(576, 64, 32, 3));

            fr3.AddEntity(new Entity(32, 448, 16, 4));
            fr3.AddEntity(new Entity(64, 416, 32, 5));

            fr4.AddEntity(new Entity(608, 448, 16, 6));
            fr4.AddEntity(new Entity(576, 416, 32, 7));

            game.AddFraction(fr1);
            game.AddFraction(fr2);
            game.AddFraction(fr3);
            game.AddFraction(fr4);

            Thread gameThread = new Thread(game.Run);

            gameThread.Start();
        }
コード例 #2
0
        public void SetInfo(GameCommon gc)
        {
            List <Fraction> nf = new List <Fraction>();

            int count = 0;

            foreach (FractionCommon fc in gc.Fractions)
            {
                Fraction f = new Fraction(fractionColors[count], this);
                count++;

                foreach (EntityCommon ec in fc.entities)
                {
                    Entity e = new Entity(new Vector2f(ec.x, ec.y), ec.id, ec.mass);
                    e.SetFraction(f);

                    /*  if (fractions.Count > 0)
                     *    foreach (Entity es in fractions[gc.FractionId].entities)
                     *        if (es.Id == e.Id)
                     *        {
                     *            if (es.Selected)
                     *
                     *            if (es.DrawMoving)
                     *                e.DrawMoving = true;
                     *        }*/

                    f.AddEntity(e);
                }
                nf.Add(f);
            }
            fractions = nf;

            Fraction pf = fractions[gc.FractionId];

            ec.SetPlayersFraction(ref pf);
        }