예제 #1
0
        public override bool OnClientReceive(LocalClient client)
        {
            foreach (GameObject go in changedObjects)
            {
                Dictionary <string, object> guiState = new Dictionary <string, object>();
                if (go is IGUIGameObject)
                {
                    IGUIGameObject gui = client.Level.Find(obj => obj.GUID == go.GUID) as IGUIGameObject;
                    if (gui != null)
                    {
                        gui.CleanupGUI(guiState);
                    }
                }

                client.Replace(go);

                if (go is IGUIGameObject)
                {
                    (go as IGUIGameObject).InitGUI(guiState);
                }

                if (go is AnimatedGameObject)
                {
                    (go as AnimatedGameObject).LoadAnimations();
                }
            }
            return(true);
        }
예제 #2
0
        public void Update(GameTime gameTime)
        {
            //First update client so it can read input and send appropriate events.
            if (client is LocalClient && client != null)
            {
                LocalClient lc = (LocalClient)client;
                lc.Update(gameTime);
            }

            if (server != null)
            {
                //Then update server so it can process events and send back the new level state.
                server.Update(gameTime);

                if (server is LocalServer)
                {
                    LocalServer ls = server as LocalServer;
                    // temp gameover check
                    Player player = ls.Level.Find(Player.LocalPlayerName) as Player;
                    if (player != null && player.Health <= 0)
                    {
                        GameOverState gos = GameEnvironment.GameStateManager.GetGameState("gameOverState") as GameOverState;
                        gos.GameMode = currentGameMode;
                        GameEnvironment.GameStateManager.SwitchTo("gameOverState");
                    }
                }
            }
        }
 public override bool OnClientReceive(LocalClient client)
 {
     base.OnClientReceive(client);
     client.Camera.CenterOn(client.Player);
     GameEnvironment.GameStateManager.SwitchTo("playingState");
     GameEnvironment.AssetManager.StopMusic();
     return(true);
 }
예제 #4
0
 public void HandleInput(InputHelper inputHelper)
 {
     if (client is LocalClient && client != null)
     {
         LocalClient lc = (LocalClient)client;
         lc.HandleInput(inputHelper);
     }
 }
예제 #5
0
 public virtual void DrawDebug(GameTime gameTime, SpriteBatch spriteBatch, Camera camera)
 {
     if (client != null && client is LocalClient)
     {
         LocalClient lc = (LocalClient)client;
         lc.DrawDebug(gameTime, spriteBatch, camera);
     }
 }
        public override void PreAnimate(LocalClient client)
        {
            dead.PlayAnimation("die");

            if (!playerSpecific)
            {
                GameEnvironment.AssetManager.PlaySound(soundAssetName);
            }
            else if (Player.LocalPlayerName == LocalPlayerName)
            {
                GameEnvironment.AssetManager.PlaySound(soundAssetName);
            }
        }
        public RemoteServer(LocalClient client)
        {
            this.client = client;

            string ip = GameEnvironment.GameSettingsManager.GetValue("server_ip_address");

            tcp = new TcpClient(ip, 29793);

            receivingThread = new Thread(new ThreadStart(Receive));
            binaryFormatter = new BinaryFormatter();
            pendingEvents   = new List <Event>();

            StartReceiving();

            ReallySend(new JoinServerEvent(client.ClientName));
        }
        public override bool OnClientReceive(LocalClient client)
        {
            if (counter == 0)
            {
                PreAnimate(client);
            }

            Animate();
            counter++;//TODO: make GameTime dependent

            if (counter >= Length)
            {
                PostAnimate();
                return(true);
            }
            return(false);
        }
        public override void PreAnimate(LocalClient client)
        {
            origin = toMove.Tile;
            if (!Before)
            { //The destination is drawn after the origin so we move the Living object to the tile here, before the animation.
                origin.RemoveImmediatly(toMove);
                destination.PutOnTile(toMove);
                toMove.Position += origin.Position - destination.Position;
            }

            if (!playerSpecific)
            {
                GameEnvironment.AssetManager.PlaySound(soundAssetName);
            }
            else if (Player.LocalPlayerName == LocalPlayerName)
            {
                GameEnvironment.AssetManager.PlaySound(soundAssetName);
            }
        }
        public override bool OnClientReceive(LocalClient client)
        {
            //First, make gui elements store their state in a dictionary.
            Dictionary <Guid, Dictionary <string, object> > guiStates = new Dictionary <Guid, Dictionary <string, object> >();

            if (client.Level != null)
            {
                HashSet <GameObject> set = new HashSet <GameObject>(client.Level.FindAll(obj => obj is IGUIGameObject));
                foreach (GameObject obj in set)
                {
                    Dictionary <string, object> guiState = new Dictionary <string, object>();
                    (obj as IGUIGameObject).CleanupGUI(guiState);
                    guiStates.Add(obj.GUID, guiState);
                }
            }

            //Actually update the level.
            client.Level = updatedLevel;
            updatedLevel.InitGUI(null);

            //Now initialise the gui again using the state stored in the dictionaries.
            foreach (GameObject obj in new HashSet <GameObject>(updatedLevel.FindAll(obj => obj is IGUIGameObject)))
            {
                Dictionary <string, object> guiState;
                guiStates.TryGetValue(obj.GUID, out guiState);

                (obj as IGUIGameObject).InitGUI(guiState ?? new Dictionary <string, object>());
            }

            //Finally load animations.
            foreach (GameObject obj in new HashSet <GameObject>(updatedLevel.FindAll(obj => obj is AnimatedGameObject)))
            {
                (obj as AnimatedGameObject).LoadAnimations();
            }

            //And center the camera on the player.
            if (!client.Camera.BoundingBox.Intersects(client.Player.BoundingBox))
            {
                client.Camera.CenterOn(client.Player);
            }

            return(true);
        }
        public void InitializeGameMode(GameMode gameMode)
        {
            PlayingState ps = GameEnvironment.GameStateManager.GetGameState("playingState") as PlayingState;

            Reset();
            ps.Reset();
            ps.CurrentGameMode = gameMode;
            switch (gameMode)
            {
            case GameMode.MultiplayerClient:
                //Initialize RemoteServer and LocalClient
                LocalClient lc = new LocalClient(server);
                AddClient(lc);
                server = new RemoteServer(lc);
                ps.SetClientAndServer(lc, server);
                break;

            case GameMode.MultiplayerHost:
                //Initialize LocalServer(public) and LocalClient
                server = new LocalServer();
                AddClient(new LocalClient(server));
                ps.SetClientAndServer(clients[0], server);
                tcpListener = new TcpListener(IPAddress.Any, 29793);
                tcpListener.Start();
                AddStartGame();
                break;

            case GameMode.Singleplayer:
                //Initialize LocalServer(private) and LocalClient
                server = new LocalServer();
                AddClient(new LocalClient(server));
                ps.SetClientAndServer(clients[0], server);
                AddStartGame();
                break;

            case GameMode.MultiplayerServer:
                //Initialize LocalServer(public)
                //server = new LocalServer(true);
                break;
            }
        }
        public override void PreAnimate(LocalClient client)
        {
            if (playerSpecific && LocalPlayerName == "")
            {
                throw new Exception("forgot to specify specific player");
            }

            if (!soundAssetName.Contains("Sounds/"))
            {
                soundAssetName = "Sounds/" + soundAssetName;               //forgot to specify the sound folder
                throw new Exception("forgot to specify the sound folder"); //exeption for now to show the programmer forgot the sound folder
            }

            if (!playerSpecific)
            {
                GameEnvironment.AssetManager.PlaySound(soundAssetName);
            }
            else if (Player.LocalPlayerName == LocalPlayerName)
            {
                GameEnvironment.AssetManager.PlaySound(soundAssetName);
            }
        }
 public abstract void PreAnimate(LocalClient client);
예제 #14
0
 public override void PreAnimate(LocalClient client)
 {
     //Create arrow
 }
 public override void OnClientReceive(LocalClient client)
 {
     //TODO: Change variable in localclient that indicates that it's its turn.
     client.IsMyTurn = true;
 }
 public override bool OnClientReceive(LocalClient client)
 {
     throw new NotImplementedException();
 }
예제 #17
0
 public abstract bool OnClientReceive(LocalClient client);