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


C# Engine.AddObject方法代码示例

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


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

示例1: Initialize

        static void Initialize(Engine engine)
        {
            int startRow = 3;
            int startCol = 2;
            int endRow = WorldRows;
            int endCol = WorldCols - 2;

            for (int i = startCol; i < endCol; i++)
            {
                Block currBlock = new Block(new MatrixCoords(startRow, i));

                //if (i == startCol + 7)
                //    currBlock = new ExplodingBlock(new MatrixCoords(startRow, i));
                currBlock = new GiftBlock(new MatrixCoords(startRow, i));
                //if (i > startCol + 3 && i < endCol - 25)
                //    currBlock = new UnpassableBlock(new MatrixCoords(startRow, i));

                engine.AddObject(currBlock);
            }

            for (int i = startRow; i < endRow; i++)
            {
                IndestructibleBlock wallBlockLeft = new IndestructibleBlock(new MatrixCoords(i, startCol - 1));
                engine.AddObject(wallBlockLeft);

                IndestructibleBlock wallBlockRight = new IndestructibleBlock(new MatrixCoords(i, endCol));
                engine.AddObject(wallBlockRight);
            }

            //for (int i = 6; i < 9; i++)
            //{
            //    TrailObject trailObject = new TrailObject(new MatrixCoords(startRow + 1, i));
            //    engine.AddObject(trailObject);
            //}

            Ball theBall = new Ball(new MatrixCoords(WorldRows / 2, 0),
                new MatrixCoords(1, 1));
            engine.AddObject(theBall);

            //MeteoriteBall theMeteoriteBall = new MeteoriteBall(new MatrixCoords(WorldRows / 2, 1), new MatrixCoords(1, 1));
            //engine.AddObject(theMeteoriteBall);

            //UnstoppableBall theUnstoppableBall = new UnstoppableBall(new MatrixCoords(WorldRows / 2, 1),   new MatrixCoords(-1, 1));
            //engine.AddObject(theUnstoppableBall);

            Racket theRacket = new Racket(new MatrixCoords(WorldRows - 1, WorldCols / 2 - 3), RacketLength);

            engine.AddObject(theRacket);
        }
开发者ID:pepakam,项目名称:TelerikAcademy,代码行数:49,代码来源:AcademyPopcornMain.cs

示例2: Initialize

        const int battleTime = 120; // in seconds.

        #endregion Fields

        #region Methods

        /// <summary>
        /// Initializes the game engine.
        /// </summary>
        static void Initialize(Engine gameEngine)
        {
            KeyboardInterface keyboard1 = new KeyboardInterface(Environment.CurrentDirectory + "../../../player1settings.txt");
            KeyboardInterface keyboard2 = new KeyboardInterface(Environment.CurrentDirectory + "../../../player2settings.txt");

            HumanPlayer p1 = new HumanPlayer("player1", new GridPosition(2, 2), ObjectColor.Yellow, keyboard1);
            HumanPlayer p2 = new HumanPlayer("player2", new GridPosition(battleFieldHeight - 3, battleFieldWidth - 4), ObjectColor.White, keyboard2);

            gameEngine.AddObject(p1);
            gameEngine.AddObject(p2);

            int startRow = 1;
            // Left wall
            for (int i = startRow; i < battleFieldHeight - 1; i++)
            {
                Wall pillar = new Wall(new GridPosition(i, 0));
                gameEngine.AddObject(pillar);
            }

            // Top wall
            for (int i = 1; i < battleFieldWidth - 2; i++)
            {
                Wall pillar = new Wall(new GridPosition(startRow, i));
                gameEngine.AddObject(pillar);
            }

            // Right wall
            for (int i = startRow; i < battleFieldHeight - 1; i++)
            {
                Wall pillar = new Wall(new GridPosition(i, battleFieldWidth - 2));
                gameEngine.AddObject(pillar);
            }

            // Bottom wall
            for (int i = 1; i < battleFieldWidth - 2; i++)
            {
                Wall pillar = new Wall(new GridPosition(battleFieldHeight - 2, i));
                gameEngine.AddObject(pillar);
            }

            Random rand = new Random();

            for (int i = 0; i < 100; ++i)
            {
                gameEngine.AddObject(BlockFactory.CreateBlock(
                    rand.Next(20),
                    new GridPosition(rand.Next(3, battleFieldHeight - 3), rand.Next(3, battleFieldWidth - 4)),
                    ObjectColor.White)
                    );
            }

            for (int i = 0; i < 5; ++i)
            {
                gameEngine.AddObject(BlockFactory.CreateBlock(1,
                    new GridPosition(rand.Next(3, battleFieldHeight - 3), rand.Next(3, battleFieldWidth - 4)),
                    ObjectColor.Gray)
                    );
            }

            for (int i = 0; i < 5; ++i)
            {
                gameEngine.AddObject(BlockFactory.CreateBlock(2,
                    new GridPosition(rand.Next(3, battleFieldHeight - 3), rand.Next(3, battleFieldWidth - 4)),
                    ObjectColor.Gray)
                    );
            }
        }
开发者ID:androidejl,项目名称:Telerik,代码行数:76,代码来源:TanksGame.cs


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