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


C# Game.Add方法代码示例

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


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

示例1: Main

        public static void Main(String[] args)
        {
            Game aGame = new Game();

            aGame.Add("Chet");
            aGame.Add("Pat");
            aGame.Add("Sue");

            Random rand = new Random();

            do
            {

                aGame.Roll(rand.Next(5) + 1);

                if (rand.Next(9) == 7)
                {
                    notAWinner = aGame.MarkCurrentAnswerAsIncorrectAndMoveToNextPlayer();
                }
                else
                {
                    notAWinner = aGame.MarkCurrentAnswerAsCorrectAndMoveToNextPlayer();
                }

            } while (notAWinner);
        }
开发者ID:pjvds,项目名称:trivia,代码行数:26,代码来源:GameRunner.cs

示例2: needsTwoPlayersToPlay

 public void needsTwoPlayersToPlay()
 {
     Game g = new Game();
     g.Add("x");
     Assert.IsFalse(g.IsPlayable());
     g.Add("y");
     Assert.IsTrue(g.IsPlayable());
 }
开发者ID:pjvds,项目名称:trivia,代码行数:8,代码来源:GameTests.cs

示例3: addThrowsInvalidOperationExceptionWhenMaxNumOfPlayersHasBeenReached

        public void addThrowsInvalidOperationExceptionWhenMaxNumOfPlayersHasBeenReached()
        {
            bool didThrow = false;
            Game g = new Game ();

            for (int i = 0; i < Game.MAX_NUM_PLAYERS; i++) {
                g.Add (i.ToString ());
            }

            try {
                g.Add ("x");
            } catch (InvalidOperationException) {
                didThrow = true;
            }

            Assert.That (didThrow, Is.True);
        }
开发者ID:pjvds,项目名称:trivia,代码行数:17,代码来源:GameTests.cs

示例4: Main

        static void Main(string[] args)
        {
            var game = new Game();
            game.FramesPerSecond = 20;

            game.Add<Slemmer>("Jeroen");
            //game.Add<DemoCreature>("Antonius");

            game.Run();
        }
开发者ID:jeroenslemmer,项目名称:survivor,代码行数:10,代码来源:Program.cs

示例5: Main

        public static void Main(string[] args)
        {
            Game aGame = new Game();

            aGame.Add("Chet");
            aGame.Add("Pat");
            aGame.Add("Sue");

            Random rand = new Random();

            do {

                aGame.Roll(rand.Next(5) + 1);

                if (rand.Next(9) == 7) {
                    notAWinner = aGame.WrongAnswer();
                } else {
                    notAWinner = aGame.WasCorrectlyAnswered();
                }

            } while (notAWinner);
        }
开发者ID:jbrains,项目名称:LegacyCodeRetreat-TriviaGame-CSharp,代码行数:22,代码来源:GameRunner.cs

示例6: DestroyShip

        public void DestroyShip()
        {
            var game = new Game();
            var system = new StarSystem();
            system.RandomlySpawnEnemies = false;
            game.Add(system);
            var ship = new Ship();
            system.AddEntity(ship);
            ship.ImpulsePercentage = 100;
            Assert.IsTrue(ship.Energy > 0, "Ship didn't have any energy");
            var oldVelocity = ship.Velocity;
            Assert.AreEqual(0, ship.Velocity.Magnitude(), "Ship should be at rest at first");

            for (int i = 0; i < 20; i++)
            {
                game.Update(TimeSpan.FromSeconds(0.25));
                game.Update(TimeSpan.FromSeconds(0.25));
                game.Update(TimeSpan.FromSeconds(0.25));
                game.Update(TimeSpan.FromSeconds(0.25));
                Assert.IsTrue(oldVelocity.Magnitude() < ship.Velocity.Magnitude(), "The ship didn't increase in speed");
                oldVelocity = ship.Velocity;
            }
            var missile = new Projectile();
            system.AddEntity(missile);
            missile.Target = ship;
            oldVelocity = missile.Velocity;
            Assert.AreEqual(0, missile.Velocity.Magnitude(), "Missile should be at rest at first.");
            for (int i = 0; i < 9; i++)
            {
                game.Update(TimeSpan.FromSeconds(0.25));
                game.Update(TimeSpan.FromSeconds(0.25));
                game.Update(TimeSpan.FromSeconds(0.25));
                game.Update(TimeSpan.FromSeconds(0.25));
                Assert.IsFalse(missile.IsDestroyed, "the missile got destroyed.");
                Assert.IsTrue(oldVelocity.Magnitude() < missile.Velocity.Magnitude(), "The missile didn't increase in speed");
                oldVelocity = missile.Velocity;
            }
            game.Update(TimeSpan.FromSeconds(0.25));
            game.Update(TimeSpan.FromSeconds(0.25));
            game.Update(TimeSpan.FromSeconds(0.25));
            game.Update(TimeSpan.FromSeconds(0.25));
            Assert.IsTrue(missile.IsDestroyed, "the missile didn't get destroyed.");
            oldVelocity = missile.Velocity;
            game.Update(TimeSpan.FromSeconds(0.25));
            Assert.AreEqual(oldVelocity.Magnitude(), missile.Velocity.Magnitude(), "The (dead) missile didn't increase in speed");
        }
开发者ID:AdmiralPotato,项目名称:ggj2013,代码行数:46,代码来源:MissileTests.cs

示例7: LaunchMissileTowardTarget

 public void LaunchMissileTowardTarget()
 {
     var game = new Game();
     var system = new StarSystem();
     game.Add(system);
     var enemy = new Ship();
     system.AddEntity(enemy);
     var attacker = new Ship() { Tubes = 3 };
     system.AddEntity(attacker);
     game.Update(TimeSpan.FromSeconds(0.25));
     attacker.LoadProjectile(0, ProjectileType.Torpedo);
     enemy.ImpulsePercentage = 100;
     game.Update(TimeSpan.FromSeconds(0.25));
     game.Update(TimeSpan.FromSeconds(0.25));
     game.Update(TimeSpan.FromSeconds(0.25));
     game.Update(TimeSpan.FromSeconds(0.25));
     game.Update(TimeSpan.FromSeconds(0.25));
     game.Update(TimeSpan.FromSeconds(0.25));
     game.Update(TimeSpan.FromSeconds(0.25));
     game.Update(TimeSpan.FromSeconds(0.25));
     game.Update(TimeSpan.FromSeconds(0.25));
     game.Update(TimeSpan.FromSeconds(0.25));
     game.Update(TimeSpan.FromSeconds(0.25));
     game.Update(TimeSpan.FromSeconds(0.25));
     game.Update(TimeSpan.FromSeconds(0.25));
     game.Update(TimeSpan.FromSeconds(0.25));
     game.Update(TimeSpan.FromSeconds(0.25));
     game.Update(TimeSpan.FromSeconds(0.25));
     game.Update(TimeSpan.FromSeconds(0.25));
     game.Update(TimeSpan.FromSeconds(0.25));
     game.Update(TimeSpan.FromSeconds(0.25));
     game.Update(TimeSpan.FromSeconds(0.25));
     Assert.AreNotEqual(0, enemy.Position.X, "The enemy should have moved along the x axis");
     Assert.AreEqual(0, attacker.Position.X, "the attacker was not at the center");
     var missile = attacker.LaunchProjectile(0, enemy);
     Assert.AreEqual(0, missile.Position.X, "the missile was not at the center");
     var oldDiff = enemy.Position.X - missile.Position.X;
     missile.Update(TimeSpan.FromSeconds(0.25));
     var newDiff = enemy.Position.X - missile.Position.X;
     Assert.IsTrue(newDiff < oldDiff, "The missile didn't get closer to the ship");
 }
开发者ID:AdmiralPotato,项目名称:ggj2013,代码行数:41,代码来源:MissileTests.cs

示例8: createGameWithTwoPlayers

 private Game createGameWithTwoPlayers()
 {
     Game g = new Game ();
     g.Add ("x");
     g.Add ("y");
     return g;
 }
开发者ID:pjvds,项目名称:trivia,代码行数:7,代码来源:GameTests.cs

示例9: RunOutOfEnergy

        public void RunOutOfEnergy()
        {
            var game = new Game();
            var system = new StarSystem();
            system.RandomlySpawnEnemies = false;
            game.Add(system);
            var ship = new Ship();
            system.AddEntity(ship);
            ship.ImpulsePercentage = 100;
            Assert.IsTrue(ship.Energy > 0, "Ship didn't have any energy");
            var oldVelocity = ship.Velocity;
            Assert.AreEqual(0, ship.Velocity.Magnitude(), "Ship should be at rest at first");

            for (int i = 0; i < 200; i++)
            {
                game.Update(TimeSpan.FromSeconds(0.25));
                game.Update(TimeSpan.FromSeconds(0.25));
                game.Update(TimeSpan.FromSeconds(0.25));
                game.Update(TimeSpan.FromSeconds(0.25));
                Assert.IsTrue(oldVelocity.Magnitude() < ship.Velocity.Magnitude(), "The ship didn't increase in speed");
                oldVelocity = ship.Velocity;
            }
            Assert.AreEqual(0, ship.Energy, "The ship didn't run out of energy");
            game.Update(TimeSpan.FromSeconds(1));
            Assert.AreEqual(oldVelocity, ship.Velocity, "The ship should not have been able to increase it's velocity without energy.");
            game.Update(TimeSpan.FromSeconds(100000)); // get that ship very far away, so the missile won't detonate
            var missile = new Projectile();
            system.AddEntity(missile);
            missile.Target = ship;
            oldVelocity = missile.Velocity;
            Assert.AreEqual(0, missile.Velocity.Magnitude(), "Missile should be at rest at first.");
            for (int i = 0; i < 20; i++)
            {
                game.Update(TimeSpan.FromSeconds(0.25));
                game.Update(TimeSpan.FromSeconds(0.25));
                game.Update(TimeSpan.FromSeconds(0.25));
                game.Update(TimeSpan.FromSeconds(0.25));
                Assert.IsFalse(missile.IsDestroyed, "the missile got destroyed.");
                Assert.IsTrue(oldVelocity.Magnitude() < missile.Velocity.Magnitude(), "The missile didn't increase in speed");
                oldVelocity = missile.Velocity;
            }
            game.Update(TimeSpan.FromSeconds(0.25));
            game.Update(TimeSpan.FromSeconds(0.25));
            game.Update(TimeSpan.FromSeconds(0.25));
            game.Update(TimeSpan.FromSeconds(0.25));
            Assert.IsFalse(missile.IsDestroyed, "the missile didn't get destroyed.");
            oldVelocity = missile.Velocity;
            game.Update(TimeSpan.FromSeconds(0.25));
            Assert.AreEqual(oldVelocity.Magnitude(), missile.Velocity.Magnitude(), "The missile didn't run out of energy after over 20 seconds");
        }
开发者ID:AdmiralPotato,项目名称:ggj2013,代码行数:50,代码来源:MissileTests.cs

示例10: MissileTowardTarget

 public void MissileTowardTarget()
 {
     var game = new Game();
     var system = new StarSystem();
     game.Add(system);
     var ship = new Ship() { Tubes = 3 };
     system.AddEntity(ship);
     ship.ImpulsePercentage = 100;
     ship.Update(TimeSpan.FromSeconds(0.25));
     ship.Update(TimeSpan.FromSeconds(0.25));
     ship.Update(TimeSpan.FromSeconds(0.25));
     ship.Update(TimeSpan.FromSeconds(0.25));
     Assert.AreNotEqual(0, ship.Position.X, "The ship should have moved along the x axis");
     var missile = new Projectile();
     system.AddEntity(missile);
     Assert.AreEqual(0, missile.Position.X, "the missile was not at the center");
     missile.Target = ship;
     var oldDiff = ship.Position.X - missile.Position.X;
     missile.Update(TimeSpan.FromSeconds(0.1));
     var newDiff = ship.Position.X - missile.Position.X;
     Assert.IsTrue(newDiff < oldDiff, "The missile didn't get closer to the ship");
 }
开发者ID:AdmiralPotato,项目名称:ggj2013,代码行数:22,代码来源:MissileTests.cs

示例11: LoadProjectileLaunchWithoutWaitingAfterLoading

 public void LoadProjectileLaunchWithoutWaitingAfterLoading()
 {
     var game = new Game();
     var system = new StarSystem();
     system.RandomlySpawnEnemies = false;
     game.Add(system);
     var ship = new Ship() { Tubes = 3 };
     system.AddEntity(ship);
     game.Update(TimeSpan.FromSeconds(0.25));
     ship.LoadProjectile(0, ProjectileType.Torpedo);
     var projectile = ship.LaunchProjectile(0, ship);
     Assert.IsNull(projectile, "The projectile shouldn't have been launched if there hasn't been enough time to load it.");
 }
开发者ID:AdmiralPotato,项目名称:ggj2013,代码行数:13,代码来源:MissileTests.cs

示例12: LoadProjectileLaunchWithoutLoading

 public void LoadProjectileLaunchWithoutLoading()
 {
     var game = new Game();
     var system = new StarSystem();
     system.RandomlySpawnEnemies = false;
     game.Add(system);
     var ship = new Ship() { Tubes = 3 };
     system.AddEntity(ship);
     game.Update(TimeSpan.FromSeconds(0.25));
     var projectile = ship.LaunchProjectile(0, ship);
     Assert.IsNull(projectile, "The projectile shouldn't have been launched if it hadn't been loaded.");
 }
开发者ID:AdmiralPotato,项目名称:ggj2013,代码行数:12,代码来源:MissileTests.cs

示例13: LoadProjectileDoubleLoad

 public void LoadProjectileDoubleLoad()
 {
     var game = new Game();
     var system = new StarSystem();
     system.RandomlySpawnEnemies = false;
     game.Add(system);
     var ship = new Ship() { Tubes = 3 };
     system.AddEntity(ship);
     game.Update(TimeSpan.FromSeconds(0.25));
     var loaded = ship.LoadProjectile(0, ProjectileType.Torpedo);
     Assert.IsTrue(loaded, "Couldn't load the first projectile");
     loaded = ship.LoadProjectile(0, ProjectileType.Torpedo);
     Assert.IsFalse(loaded, "Somehow Loaded a second projectile.");
 }
开发者ID:AdmiralPotato,项目名称:ggj2013,代码行数:14,代码来源:MissileTests.cs

示例14: Test1

        public void Test1()
        {
            var outputStringWriter = new StringWriter {NewLine = "\n"};
            var aGame = new Game(outputStringWriter);
            aGame.Add("Chet");
            aGame.WrongAnswer();

            Assert.AreEqual("Chet was added\n" +
                            "They are player number 1\n" +
                            "Question was incorrectly answered\n" +
                            "Chet was sent to the penalty box\n",
                outputStringWriter.ToString());
        }
开发者ID:stanbe,项目名称:uglytrivia,代码行数:13,代码来源:GameTest.cs

示例15: GameRunner2

        public void GameRunner2()
        {
            var outputStringWriter = new StringWriter {NewLine = "\n"};
            var aGame = new Game(outputStringWriter);
            aGame.Add("Chet");
            aGame.Add("Pat");

            var rand = new Random(3);

            GameRunner.Run(aGame, rand);

            Assert.AreEqual("Chet was added\n" +
                            "They are player number 1\n" +
                            "Pat was added\n" +
                            "They are player number 2\n" +
                            "Chet is the current player\n" +
                            "They have rolled a 2\n" +
                            "Chet's new location is 2\n" +
                            "The category is Sports\n" +
                            "Sports Question 0\n" +
                            "Answer was correct!!!!\n" +
                            "Chet now has 1 Gold Coins.\n" +
                            "Pat is the current player\n" +
                            "They have rolled a 5\n" +
                            "Pat's new location is 5\n" +
                            "The category is Science\n" +
                            "Science Question 0\n" +
                            "Answer was correct!!!!\n" +
                            "Pat now has 1 Gold Coins.\n" +
                            "Chet is the current player\n" +
                            "They have rolled a 3\n" +
                            "Chet's new location is 5\n" +
                            "The category is Science\n" +
                            "Science Question 1\n" +
                            "Answer was correct!!!!\n" +
                            "Chet now has 2 Gold Coins.\n" +
                            "Pat is the current player\n" +
                            "They have rolled a 2\n" +
                            "Pat's new location is 7\n" +
                            "The category is Rock\n" +
                            "Rock Question 0\n" +
                            "Answer was correct!!!!\n" +
                            "Pat now has 2 Gold Coins.\n" +
                            "Chet is the current player\n" +
                            "They have rolled a 2\n" +
                            "Chet's new location is 7\n" +
                            "The category is Rock\n" +
                            "Rock Question 1\n" +
                            "Answer was correct!!!!\n" +
                            "Chet now has 3 Gold Coins.\n" +
                            "Pat is the current player\n" +
                            "They have rolled a 3\n" +
                            "Pat's new location is 10\n" +
                            "The category is Sports\n" +
                            "Sports Question 1\n" +
                            "Question was incorrectly answered\n" +
                            "Pat was sent to the penalty box\n" +
                            "Chet is the current player\n" +
                            "They have rolled a 4\n" +
                            "Chet's new location is 11\n" +
                            "The category is Rock\n" +
                            "Rock Question 2\n" +
                            "Answer was correct!!!!\n" +
                            "Chet now has 4 Gold Coins.\n" +
                            "Pat is the current player\n" +
                            "They have rolled a 1\n" +
                            "Pat is getting out of the penalty box\n" +
                            "Pat's new location is 11\n" +
                            "The category is Rock\n" +
                            "Rock Question 3\n" +
                            "Answer was correct!!!!\n" +
                            "Pat now has 3 Gold Coins.\n" +
                            "Chet is the current player\n" +
                            "They have rolled a 1\n" +
                            "Chet's new location is 0\n" +
                            "The category is Pop\n" +
                            "Pop Question 0\n" +
                            "Question was incorrectly answered\n" +
                            "Chet was sent to the penalty box\n" +
                            "Pat is the current player\n" +
                            "They have rolled a 4\n" +
                            "Pat is not getting out of the penalty box\n" +
                            "Chet is the current player\n" +
                            "They have rolled a 2\n" +
                            "Chet is not getting out of the penalty box\n" +
                            "Pat is the current player\n" +
                            "They have rolled a 3\n" +
                            "Pat is getting out of the penalty box\n" +
                            "Pat's new location is 2\n" +
                            "The category is Sports\n" +
                            "Sports Question 2\n" +
                            "Answer was correct!!!!\n" +
                            "Pat now has 4 Gold Coins.\n" +
                            "Chet is the current player\n" +
                            "They have rolled a 5\n" +
                            "Chet is getting out of the penalty box\n" +
                            "Chet's new location is 5\n" +
                            "The category is Science\n" +
                            "Science Question 2\n" +
                            "Answer was correct!!!!\n" +
//.........这里部分代码省略.........
开发者ID:stanbe,项目名称:uglytrivia,代码行数:101,代码来源:GameTest.cs


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