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


C# GameStateManager.GetAllOfType方法代码示例

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


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

示例1: Initialize

        /// <summary>
        /// Instantiates all the classes needed for the game
        /// </summary>
        public override void Initialize()
        {
            //generate Level from file
            var parser = new LevelParser();
            level = parser.GenerateLevel(ScreenManager.Content.Load<List<String[]>>(@"Levels\level1"));

            //create a camer, for we want to see the game
            camera = new Camera(0.4f, Vector2.Zero, 0, true, null);

            Point size = new Point(49, 49);

            PlayerController playerController = new PlayerController(Direction.None, "PacMa", 1, PlayerIndex.One,
                                                                     MovObjType.LocalPacMan, ScreenManager.Input);

            //Create a player object
            PacMan player = new PacMan(@"Sprites\PacMan", level.getCell(1, 1), level,
                                                new PlayerController(Direction.None, "Player 1",1, PlayerIndex.One, MovObjType.LocalPacMan, ScreenManager.Input), Direction.None, 3f, size);

            //Create all ghosts for the game

            Ghost blinky = new Ghost(@"Sprites\GhostBase", level.getCell(26, 1), level, Direction.Down, 3f, size, Color.Red, new Blinky(player, new Point(0, 0), new Point(15, 15), new Point(16, 16)));
            Ghost pinky = new Ghost(@"Sprites\GhostBase", level.getCell(26, 29), level, Direction.None, 3f, size, Color.Pink, new Pinky(player, new Point(0, 28), new Point(15, 15), new Point(16, 16)));
            Ghost inky = new Ghost(@"Sprites\GhostBase", level.getCell(26, 14), level, Direction.None, 3f, size, Color.Blue,
                                   new Inky(player, blinky, new Point(31, 0), new Point(15, 15), new Point(16, 16)));
            Ghost clyde = new Ghost(@"Sprites\GhostBase", level.getCell(12, 17), level, Direction.None, 3f, size, Color.Yellow,
                                    new Clyde(player, new Point(31, 28), new Point(15, 15), new Point(16, 16)));

            //Initialize the list of gui elements
            guiElements = new List<GUIElement>();
            GUIString stringElement = new GUIString(player, Color.White, new Vector2(0, 0), new Vector2(10, 10));

            guiElements.Add(stringElement);

            //Store everything inside the gameStateManager
            gameStateManager = new GameStateManager();
            gameStateManager.GameState = GameState.Loading;

            gameStateManager.AddPlayers(player, blinky, pinky, inky, clyde);

            gameStateManager.Level = level;

            //            movOb.Add(player);
            //            movOb.Add(blinky);
            //            movOb.Add(pinky);
            //            movOb.Add(inky);
            //            movOb.Add(clyde);

            //Initialize the gameplay behaviours
            playBehaviour = new PlayBehaviour();
            deathBehaviour = new DeathBehaviour();

            gameStateManager.GetAllOfType<PacMan>();
            gameStateManager.GetAllOfType<Ghost>();
        }
开发者ID:Rosthouse,项目名称:Multi-Pac,代码行数:57,代码来源:SingleplayerScreen.cs

示例2: Initialize

        /// <summary>
        /// Initializes the current screen
        /// </summary>
        public override void Initialize()
        {
            //Store everything inside the gameStateManager
            gameStateManager = new GameStateManager();
            gameStateManager.GameState = GameState.Loading;
            gameStateManager.Level = level;

            //Initialize the gameplay behaviours
            playBehaviour = new PlayBehaviour();
            deathBehaviour = new DeathBehaviour();

            var parser = new LevelParser();

            gameStateManager.Level = parser.GenerateLevel(ScreenManager.Content.Load<List<String[]>>(@"Levels\level1"));
            guiElements = new List<GamePlayScreens.GUI.GUIElement>();

            //camera = new Camera(1, Vector2.Zero, 0);
            camera = new Camera(0.4f, Vector2.Zero, 0, true, null);

            // ask server for List of connected and waiting clients
            networkManager.sendMessage("getPlayers");

            // wait for the response to the request of available players
            NetIncomingMessage msg;
            bool waitingForServer = true;
            while (waitingForServer)
            {
                // check for messages as long the incoming messages queue has messages stored
                while ((msg = networkManager.getMessage()) != null)
                {
                    switch (msg.MessageType)
                    {
                        case NetIncomingMessageType.Data:
                            string msgStr = msg.ReadString();

                            // check if the message is the response to the request
                            string[] clients = msgStr.Split(';');
                            if (clients[0] == "getPlayers")
                            {
                                int i = 1;
                                foreach (string player in clients)
                                {
                                    if (player != "" && player != "getPlayers")
                                    {
                                        string[] values = player.Split('/');
                                        int localUID = networkManager.getUID();
                                        int remoteUID = Convert.ToInt32(values[0]);

                                        switch (values[1])
                                        {
                                            case "1": // Player is a PacMan
                                                // Check if it is a local or remote controlled gameobject
                                                if (localUID == remoteUID) // local controlled
                                                {
                                                    PlayerController playerController = new PlayerController(
                                                        Direction.None, values[0], remoteUID, PlayerIndex.One,
                                                        MovObjType.LocalPacMan, ScreenManager.Input);

                                                    NetworkController networkController =
                                                        new NetworkController(playerController.ID, playerController,
                                                                              networkManager);

                                                    gameStateManager.AddPlayers(new PacMan(@"Sprites\PacMan",
                                                        gameStateManager.Level.getCell(1, 1), gameStateManager.Level, networkController, Direction.None, 1.3f, new Point(50, 50)));
                                                }
                                                else // remote controlled
                                                {
                                                    EmptyController emptyController = new EmptyController(Direction.None,
                                                                                                          values[0],
                                                                                                          remoteUID,
                                                                                                          MovObjType.
                                                                                                              NetPacMan);

                                                    gameStateManager.AddPlayers(new PacMan(@"Sprites\PacMan",
                                                        gameStateManager.Level.getCell(1, 1), gameStateManager.Level,
                                                        new NetworkController(emptyController.ID, emptyController, networkManager),
                                                        Direction.None, 1.3f, new Point(50, 50)));
                                                }

                                                GUIString stringElement = new GUIString(gameStateManager.MovableObjects.Last(), Color.White, new Vector2(0, 0), new Vector2(10, i * 10));
                                                guiElements.Add(stringElement);

                                                break;

                                            case "2": // Player is a Ghost

                                                Blinky blinky = new Blinky(gameStateManager.GetAllOfType<PacMan>()[0],
                                                                           new Point(0, 0), new Point(15, 15),
                                                                           new Point(17, 17));

                                                GhostController ghostController = new GhostController(level,
                                                                                                      blinky,
                                                                                                      remoteUID);

                                                NetworkGhostController ghostNetworkController =
                                                    new NetworkGhostController(networkManager, ghostController,
                                                                               ghostController.ID);
//.........这里部分代码省略.........
开发者ID:Rosthouse,项目名称:Multi-Pac,代码行数:101,代码来源:MultiplayerScreen.cs


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