Exemple #1
0
 public static Base BaseFactory(ServerGame game, Vector2 position)
 {
     Base baseObj = new Base(game.GameObjectCollection);
     game.GameObjectCollection.Add(baseObj);
     Base.ServerInitialize(baseObj, position);
     return baseObj;
 }
Exemple #2
0
        //This method starts running the lobby and blocks until the lobby ends
        public void Run()
        {
            //Start the client listener in its own thread
            //This thread allows clients to asynchronously join the lobby
            Thread clientListenerThread = new Thread(new ThreadStart(ClientListener));
            clientListenerThread.Start();

            //wait to start
            MessageBox.Show("Enter to start", NetUtils.GetLocalIP());

            //lock client list
            clientsMutex.WaitOne();
            clientsLocked = true;
            clientsMutex.ReleaseMutex();

            // Start up the game.
            ServerGame game = new ServerGame(this);
            game.Run();

            //the game has finished
            foreach (RemotePlayer c in clients)
            {
                c.Disconnect();
            }

            //this.prelimListener.Stop();
            UdpTcpPair.StopListener();
            clientListenerThread.Join();
        }
 public static Company Factory(ServerGame game, PlayerGameObject controllingPlayer)
 {
     Company obj = new Company(game.GameObjectCollection);
     game.GameObjectCollection.Add(obj);
     Company.ServerInitialize(obj, controllingPlayer);
     return obj;
 }
 public static PlayerGameObject Factory(ServerGame game, RemotePlayer player)
 {
     PlayerGameObject obj = new PlayerGameObject(game.GameObjectCollection);
     game.GameObjectCollection.Add(obj);
     PlayerGameObject.ServerInitialize(obj, player.Id);
     return obj;
 }
        public static void ExecuteCommand(RtsCommandMessage message, ServerGame game, RemotePlayer player)
        {
            int baseObjID = message.ReadInt();

            Base obj = game.GameObjectCollection.Get<Base>(baseObjID);
            if (player.Owns(obj))
            {
                obj.BuildTransportVehicle();
            }
        }
        public static void ExecuteCommand(RtsCommandMessage message, ServerGame game, RemotePlayer player)
        {
            int coID = message.ReadInt();

            Company obj = game.GameObjectCollection.Get<Company>(coID);
            if (player.Owns(obj))
            {
                obj.Destroy();
            }
        }
        public ServerLogic(ServerGame game, Lobby lobby, Vector2 worldSize)
        {
            RemotePlayer player1 = null;
            RemotePlayer player2 = null;

            foreach (RemotePlayer player in lobby.Clients)
            {
                player.CreatPlayerGameObject(game);
            }

            if (lobby.Clients.Count > 0)
            {
                player1 = lobby.Clients[0];
            }

            if (lobby.Clients.Count > 1)
            {
                player2 = lobby.Clients[1];
            }

            Base player2Base = Base.BaseFactory(game, new Vector2((float)(0.84 * worldSize.X), (float)(0.5 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.84 * worldSize.X), (float)(0.25 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.84 * worldSize.X), (float)(0.75 * worldSize.Y)));

            Base.BaseFactory(game, new Vector2((float)(0.67 * worldSize.X), (float)(0.11 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.67 * worldSize.X), (float)(0.37 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.67 * worldSize.X), (float)(0.63 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.67 * worldSize.X), (float)(0.89 * worldSize.Y)));

            Base.BaseFactory(game, new Vector2((float)(0.5 * worldSize.X), (float)(0.5 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.5 * worldSize.X), (float)(0.25 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.5 * worldSize.X), (float)(0.75 * worldSize.Y)));

            Base.BaseFactory(game, new Vector2((float)(0.33 * worldSize.X), (float)(0.11 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.33 * worldSize.X), (float)(0.37 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.33 * worldSize.X), (float)(0.63 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.33 * worldSize.X), (float)(0.89 * worldSize.Y)));

            Base player1Base = Base.BaseFactory(game, new Vector2((float)(0.16 * worldSize.X), (float)(0.5 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.16 * worldSize.X), (float)(0.25 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.16 * worldSize.X), (float)(0.75 * worldSize.Y)));

            player1Base.SetPlayerInControll(player1);
            Company.Factory(game, player1.GameObject);

            for(int i = 0; i < 5; i++)
            {
                CombatVehicle.CombatVehicleFactory(game.GameObjectCollection, player1.GameObject, player1Base.Position + new Vector2(i * 20, 100));
                Transport.TransportFactory(game.GameObjectCollection, player1.GameObject, player1Base.Position + new Vector2(i * 20, 200));
            }


            player2Base.SetPlayerInControll(player2);
        }
        public static void ExecuteCommand(RtsCommandMessage message, ServerGame game, RemotePlayer player)
        {
            int companyId = message.ReadInt();
            int vehicleId = message.ReadInt();

            Company co = game.GameObjectCollection.Get<Company>(companyId);
            CombatVehicle vic = game.GameObjectCollection.Get<CombatVehicle>(vehicleId);
            if (player.Owns(co) && player.Owns(co))
            {
                co.AddVehicle(vic);
            }
        }
        public static void ExecuteCommand(RtsCommandMessage message, ServerGame game, RemotePlayer player)
        {
            int baseObjID = message.ReadInt();
            int coID = message.ReadInt();

            Base obj = game.GameObjectCollection.Get<Base>(baseObjID);
            Company co = game.GameObjectCollection.Get<Company>(coID);
            if (player.Owns(obj) && player.Owns(co))
            {
                co.ResupplyPoint = obj;
            }
        }
        public static void ExecuteCommand(RtsCommandMessage message, ServerGame game, RemotePlayer player)
        {
            int companyId = message.ReadInt();
            int positionCount = message.ReadInt();
            List<Vector2> positions = new List<Vector2>();

            for (int i = 0; i < positionCount; i++)
            {
                positions.Add(message.ReadVector2());
            }

            Company co = game.GameObjectCollection.Get<Company>(companyId);
            if (player.Owns(co))
            {
                co.SetPositions(game.GameObjectCollection, positions);
            }
        }
 public static void ExecuteCommand(RtsCommandMessage message, ServerGame game, RemotePlayer player)
 {
     player.GameObject.AddCompany(game);
 }
 public void Execute(ServerGame game, RemotePlayer player)
 {
     this.ResetReader();
     int typeID = this.ReadInt();
     commandDelegates[typeID](this, game, player);
 }
Exemple #13
0
 public void HandleAllTCPMessages(ServerGame game)
 {
     foreach (RemotePlayer client in clients)
     {
         client.HandleAllTCPMessages(game);
     }
 }
 public Company AddCompany(ServerGame serverGame)
 {
     Company co = Company.Factory(serverGame, this);
     companies.Value.Add(co);
     return co;
 }