Ejemplo n.º 1
0
        public void PlayerMovesOutAndIntoTheRange()
        {
            var map     = new GameMap(new GameMapDefinition(), 60, ChunkSize);
            var player1 = this.GetPlayer();

            player1.Stub(p => p.Id).Return(1);
            player1.X = 101;
            player1.Y = 100;
            map.Add(player1);
            var player2 = this.GetPlayer();

            player2.Stub(p => p.Id).Return(2);
            player2.X = 101;
            player2.Y = 100;
            map.Add(player2);

            map.Move(player1, 100, 130, new object(), 0);
            player1.AssertWasCalled(p => p.LocateablesOutOfScope(null), o => o.IgnoreArguments());
            player2.AssertWasCalled(p => p.LocateableRemoved(null, null), o => o.IgnoreArguments());
            player2.AssertWasCalled(p => p.NewLocateablesInScope(null), o => o.IgnoreArguments().Repeat.Times(1));
            player1.AssertWasCalled(p => p.LocateableAdded(null, null), o => o.IgnoreArguments().Repeat.Times(1));

            map.Move(player2, 101, 130, new object(), 0);
            player2.AssertWasCalled(p => p.NewLocateablesInScope(null), o => o.IgnoreArguments().Repeat.Times(2));
            player1.AssertWasCalled(p => p.LocateableAdded(null, null), o => o.IgnoreArguments().Repeat.Times(2));
        }
Ejemplo n.º 2
0
        public void PlayerMovesOutAndIntoTheRange()
        {
            var map     = new GameMap(new GameMapDefinition(), 60, ChunkSize, null);
            var player1 = this.GetPlayer();

            player1.Setup(p => p.Id).Returns(1);
            player1.Object.Position = new Point(101, 100);
            map.Add(player1.Object);
            var player2 = this.GetPlayer();

            player2.Setup(p => p.Id).Returns(2);
            player2.Object.Position = new Point(101, 100);
            map.Add(player2.Object);

            player1.Verify(p => p.NewLocateablesInScope(It.Is <IEnumerable <ILocateable> >(n => n.Contains(player2.Object))), Times.Once);
            player2.Verify(p => p.NewLocateablesInScope(It.Is <IEnumerable <ILocateable> >(n => n.Contains(player1.Object))), Times.Once);
            player1.Verify(p => p.LocateableAdded(It.IsAny <object>(), It.IsAny <BucketItemEventArgs <ILocateable> >()), Times.Once);
            player1.Invocations.Clear();
            player2.Invocations.Clear();

            map.Move(player1.Object, new Point(100, 130), new object(), 0);
            player1.Verify(p => p.LocateablesOutOfScope(It.Is <IEnumerable <ILocateable> >(n => n.Contains(player2.Object))), Times.Once);
            player2.Verify(p => p.LocateableRemoved(It.IsAny <object>(), It.IsAny <BucketItemEventArgs <ILocateable> >()), Times.Once);
            player1.Invocations.Clear();
            player2.Invocations.Clear();

            map.Move(player2.Object, new Point(101, 130), new object(), 0);
            player2.Verify(p => p.NewLocateablesInScope(It.Is <IEnumerable <ILocateable> >(n => n.Contains(player1.Object))), Times.Once);
            player1.Verify(p => p.LocateableAdded(It.IsAny <object>(), It.IsAny <BucketItemEventArgs <ILocateable> >()), Times.Once);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Tests the performance of the movements. Not a standard test.
        /// </summary>
        /// [Test]
        public void TestPerformanceMove()
        {
            var map     = new GameMap(new GameMapDefinition(), 60, ChunkSize, null);
            var player1 = this.GetPlayer();

            player1.Setup(p => p.Id).Returns(1);

            map.Add(player1.Object);
            var player2 = this.GetPlayer();

            player2.Setup(p => p.Id).Returns(2);
            player2.Object.Position = new Point(101, 100);
            map.Add(player2.Object);

            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            var moveLock = new object();

            for (int i = 0; i < 1000; i++)
            {
                map.Move(player1.Object, new Point((byte)(100 + (i % 30)), (byte)(100 + (i % 30))), moveLock, 0);
            }

            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);
        }
Ejemplo n.º 4
0
        public void LocateableNotOutOfScopeWhenMovedToObservedBucket()
        {
            var worldObserver = new Mock <IWorldObserver>();
            var view          = new Mock <IWorldView>();

            worldObserver.Setup(o => o.WorldView).Returns(view.Object);
            var adapter    = new ObserverToWorldViewAdapter(worldObserver.Object, 12);
            var map        = new GameMap(new DataModel.Configuration.GameMapDefinition(), 10, 8, null);
            var nonPlayer1 = new NonPlayerCharacter(new DataModel.Configuration.MonsterSpawnArea(), new DataModel.Configuration.MonsterDefinition(), map)
            {
                Position = new Point(128, 128)
            };

            map.Add(nonPlayer1);
            var nonPlayer2 = new NonPlayerCharacter(new DataModel.Configuration.MonsterSpawnArea(), new DataModel.Configuration.MonsterDefinition(), map)
            {
                Position = new Point(100, 128)
            };

            map.Add(nonPlayer2);
            adapter.ObservingBuckets.Add(nonPlayer1.NewBucket);
            adapter.ObservingBuckets.Add(nonPlayer2.NewBucket);

            adapter.LocateableAdded(map, new BucketItemEventArgs <ILocateable>(nonPlayer1));
            adapter.LocateableAdded(map, new BucketItemEventArgs <ILocateable>(nonPlayer2));

            map.Move(nonPlayer1, nonPlayer2.Position, nonPlayer1, MoveType.Instant);

            view.Verify(v => v.NewNpcsInScope(It.Is <IEnumerable <NonPlayerCharacter> >(arg => arg.Contains(nonPlayer1))), Times.Once);
            view.Verify(v => v.NewNpcsInScope(It.Is <IEnumerable <NonPlayerCharacter> >(arg => arg.Contains(nonPlayer2))), Times.Once);
            view.Verify(v => v.ObjectsOutOfScope(It.IsAny <IEnumerable <IIdentifiable> >()), Times.Never);
            view.Verify(v => v.ObjectMoved(It.Is <ILocateable>(arg => arg == nonPlayer1), MoveType.Instant), Times.Once);
        }
Ejemplo n.º 5
0
        public void LocateableNotOutOfScopeWhenMovedToObservedBucket()
        {
            var worldObserver = MockRepository.GenerateStub <IWorldObserver>();
            var view          = MockRepository.GenerateStrictMock <IWorldView>();

            worldObserver.Stub(o => o.WorldView).Return(view);
            var adapter    = new ObserverToWorldViewAdapter(worldObserver, 12);
            var map        = new GameMap(new DataModel.Configuration.GameMapDefinition(), 10, 8, null);
            var nonPlayer1 = new NonPlayerCharacter(new DataModel.Configuration.MonsterSpawnArea(), new DataModel.Configuration.MonsterDefinition(), map)
            {
                X = 128,
                Y = 128
            };

            map.Add(nonPlayer1);
            var nonPlayer2 = new NonPlayerCharacter(new DataModel.Configuration.MonsterSpawnArea(), new DataModel.Configuration.MonsterDefinition(), map)
            {
                X = 100,
                Y = 128
            };

            map.Add(nonPlayer2);
            adapter.ObservingBuckets.Add(nonPlayer1.NewBucket);
            adapter.ObservingBuckets.Add(nonPlayer2.NewBucket);
            view.Expect(v => v.NewNpcsInScope(null)).IgnoreArguments().Repeat.Twice();
            adapter.LocateableAdded(map, new BucketItemEventArgs <ILocateable>(nonPlayer1));
            adapter.LocateableAdded(map, new BucketItemEventArgs <ILocateable>(nonPlayer2));

            view.Expect(v => v.ObjectsOutOfScope(null)).IgnoreArguments().Repeat.Never();
            view.Expect(v => v.ObjectMoved(null, MoveType.Instant)).IgnoreArguments().Repeat.Once();
            map.Move(nonPlayer1, nonPlayer2.X, nonPlayer2.Y, nonPlayer1, MoveType.Instant);
            view.VerifyAllExpectations();
        }
Ejemplo n.º 6
0
        public void TestPlayerEntersMap()
        {
            var map     = new GameMap(new GameMapDefinition(), 60, ChunkSize);
            var player1 = this.GetPlayer();

            player1.Object.Position = new Point(100, 100);
            map.Add(player1.Object);
            var player2 = this.GetPlayer();

            player2.Object.Position = new Point(101, 100);
            map.Add(player2.Object);
            player1.Verify(p => p.NewLocateablesInScope(It.Is <IEnumerable <ILocateable> >(n => n.Contains(player2.Object))), Times.Once);
            player2.Verify(p => p.NewLocateablesInScope(It.Is <IEnumerable <ILocateable> >(n => n.Contains(player1.Object))), Times.Once);
            player1.Verify(p => p.LocateableAdded(It.IsAny <object>(), It.IsAny <BucketItemEventArgs <ILocateable> >()), Times.Once);
        }
Ejemplo n.º 7
0
        public void Spell()
        {
            Human hero   = new Human();
            Elpf  enemie = new Elpf();

            new PrivateType(typeof(GameMap)).SetStaticField("instance", null);
            GameMap map = GameMap.GetInstance();

            map.Add(hero, 1);
            map.Add(enemie, 2);
            Assert.IsTrue(hero.Spell(enemie));
            Assert.AreEqual(enemie.Hp, 40);
            Assert.IsTrue(hero.Spell(enemie));
            Assert.IsTrue(enemie.IsDead);
        }
Ejemplo n.º 8
0
        public void PlayerMovesOutOfRange()
        {
            var map     = new GameMap(new GameMapDefinition(), 60, ChunkSize);
            var player1 = this.GetPlayer();

            player1.Object.Position = new Point(101, 100);
            map.Add(player1.Object);
            var player2 = this.GetPlayer();

            player2.Object.Position = new Point(101, 100);
            map.Add(player2.Object);

            map.Move(player1.Object, new Point(100, 130), new object(), 0);
            player1.Verify(p => p.LocateablesOutOfScope(It.Is <IEnumerable <ILocateable> >(n => n.Contains(player2.Object))), Times.Once);
            player2.Verify(p => p.LocateableRemoved(It.IsAny <object>(), It.IsAny <BucketItemEventArgs <ILocateable> >()), Times.Once);
        }
Ejemplo n.º 9
0
        public void Add()
        {
            new PrivateType(typeof(Elpf)).SetStaticField("ind", 0);
            new PrivateType(typeof(GameMap)).SetStaticField("instance", null);
            GameMap map  = GameMap.GetInstance();
            Elpf    per1 = new Elpf();
            Elpf    per2 = new Elpf();

            Assert.AreEqual(per1.Name, "Elpf0");
            Assert.AreEqual(per2.Name, "Elpf1");
            Assert.IsTrue(map.Add(per1, 20));
            Assert.IsFalse(map.Add(per1, 20));
            Assert.IsFalse(map.Add(per2, 20));
            Assert.IsFalse(map.Add(per1, 21));
            Assert.IsTrue(map.Add(per2, 21));
        }
Ejemplo n.º 10
0
        // Create some sample treasure
        // that can be picked up on the map
        public static void CreateLoot()
        {
            // number of treasure drops to create
            int numLoot = 20;

            Random rndNum = new Random();

            // Produce lot up to a max of numLoot
            for (int i = 0; i < numLoot; i++)
            {
                // Create an Item with some standard attributes
                int  lootPosition = 0;
                Item newLoot      = new Item(Color.Green, Color.Transparent, "fancy shirt", 'L', 2);


                // Try placing the Item at lootPosition; if this fails, try random positions on the map's tile array
                while (GameMap.Tiles[lootPosition].IsBlockingMove)
                {
                    // pick a random spot on the map
                    lootPosition = rndNum.Next(0, GameMap.Width * GameMap.Height);
                }

                // set the loot's new position
                newLoot.Position = new Point(lootPosition % GameMap.Width, lootPosition / GameMap.Width);

                // add the Item to the MultiSpatialMap
                GameMap.Add(newLoot);
            }
        }
Ejemplo n.º 11
0
        public void Move()
        {
            new PrivateType(typeof(Elpf)).SetStaticField("ind", 0);
            new PrivateType(typeof(GameMap)).SetStaticField("instance", null);
            GameMap map  = GameMap.GetInstance();
            Elpf    per1 = new Elpf();
            Elpf    per2 = new Elpf();

            Assert.IsTrue(map.Add(per1, 13));
            Assert.IsTrue(map.Add(per2, 12));
            Assert.IsTrue(per1.Move(14));
            Assert.IsTrue(per2.Move(14));
            Assert.AreEqual(per2.Name, map[13]);
            Elpf per3 = new Elpf();

            Assert.IsTrue(map.Add(per3, 29));
            Assert.IsFalse(per3.Move(34));
        }
Ejemplo n.º 12
0
        public void TestPlayerLeavesMap()
        {
            var map     = new GameMap(new GameMapDefinition(), 60, ChunkSize);
            var player1 = this.GetPlayer();

            player1.Object.Position = new Point(100, 100);
            map.Add(player1.Object);
            var player2 = this.GetPlayer();

            player2.Object.Position = new Point(101, 100);
            map.Add(player2.Object);
            map.Remove(player2.Object);
            Assert.AreEqual(player2.Object.ObservingBuckets.Count, 0);
            player1.Verify(p => p.LocateableRemoved(It.IsAny <object>(), It.IsAny <BucketItemEventArgs <ILocateable> >()), Times.Once);
            player2.Verify(p => p.LocateableRemoved(It.IsAny <object>(), It.IsAny <BucketItemEventArgs <ILocateable> >()), Times.Once);
            Assert.That(player1.Object.Observers.Count, Is.EqualTo(0));
            Assert.That(player2.Object.Observers.Count, Is.EqualTo(0));
        }
Ejemplo n.º 13
0
        public void TestPlayerEntersMap()
        {
            var map     = new GameMap(new GameMapDefinition(), 60, ChunkSize);
            var player1 = this.GetPlayer();

            player1.Stub(p => p.Id).Return(1);
            player1.X = 100;
            player1.Y = 100;
            map.Add(player1);
            var player2 = this.GetPlayer();

            player2.Stub(p => p.Id).Return(2);
            player2.X = 101;
            player2.Y = 100;
            map.Add(player2);
            player1.AssertWasCalled(p => p.NewLocateablesInScope(null), o => o.IgnoreArguments());
            player2.AssertWasCalled(p => p.NewLocateablesInScope(null), o => o.IgnoreArguments());
            player1.AssertWasCalled(p => p.LocateableAdded(null, null), o => o.IgnoreArguments());
        }
Ejemplo n.º 14
0
        public void TestPlayerEntersMap()
        {
            var map     = new GameMap(new GameMapDefinition(), 60, ChunkSize, null);
            var player1 = this.GetPlayer();

            player1.Setup(p => p.Id).Returns(1);
            player1.Object.X = 100;
            player1.Object.Y = 100;
            map.Add(player1.Object);
            var player2 = this.GetPlayer();

            player2.Setup(p => p.Id).Returns(2);
            player2.Object.X = 101;
            player2.Object.Y = 100;
            map.Add(player2.Object);
            player1.Verify(p => p.NewLocateablesInScope(It.Is <IEnumerable <ILocateable> >(n => n.Contains(player2.Object))), Times.Once);
            player2.Verify(p => p.NewLocateablesInScope(It.Is <IEnumerable <ILocateable> >(n => n.Contains(player1.Object))), Times.Once);
            player1.Verify(p => p.LocateableAdded(It.IsAny <object>(), It.IsAny <BucketItemEventArgs <ILocateable> >()), Times.Once);
        }
Ejemplo n.º 15
0
        public void TestPlayerLeavesMap()
        {
            var map     = new GameMap(new GameMapDefinition(), 60, ChunkSize, 0);
            var player1 = this.GetPlayer();

            player1.Stub(p => p.Id).Return(1);
            player1.X = 100;
            player1.Y = 100;
            map.Add(player1);
            var player2 = this.GetPlayer();

            player2.Stub(p => p.Id).Return(2);
            player2.X = 101;
            player2.Y = 100;
            map.Add(player2);
            map.Remove(player2);
            player1.AssertWasCalled(p => p.LocateableRemoved(null, null), o => o.IgnoreArguments());
            Assert.AreEqual(player2.ObservingBuckets.Count, 0);
        }
Ejemplo n.º 16
0
        public void Remove()
        {
            new PrivateType(typeof(Elpf)).SetStaticField("ind", 0);
            new PrivateType(typeof(GameMap)).SetStaticField("instance", null);
            GameMap map  = GameMap.GetInstance();
            Elpf    per1 = new Elpf();

            Assert.IsTrue(map.Add(per1, 20));
            Assert.IsTrue(map.Remove(per1));
            Assert.IsFalse(map.Remove(per1));
        }
Ejemplo n.º 17
0
    /// <summary>
    /// 创建一个很大的Dic1
    /// </summary>
    /// <param name="v"></param>
    /// <returns></returns>
    public static GameMap <int, int> CreateArr1(int v)
    {
        GameMap <int, int> arr = new GameMap <int, int>();

        System.Random r = new System.Random();
        for (int i = 0; i < v; i++)
        {
            arr.Add(i, r.Next(0, v));
        }
        return(arr);
    }
Ejemplo n.º 18
0
        public void PlayerMovesOutOfRange()
        {
            var map     = new GameMap(new GameMapDefinition(), 60, ChunkSize, null);
            var player1 = this.GetPlayer();

            player1.Setup(p => p.Id).Returns(1);
            player1.Object.X = 101;
            player1.Object.Y = 100;
            map.Add(player1.Object);
            var player2 = this.GetPlayer();

            player2.Setup(p => p.Id).Returns(2);
            player2.Object.X = 101;
            player2.Object.Y = 100;
            map.Add(player2.Object);

            map.Move(player1.Object, 100, 130, new object(), 0);
            player1.Verify(p => p.LocateablesOutOfScope(It.Is <IEnumerable <ILocateable> >(n => n.Contains(player2.Object))), Times.Once);
            player2.Verify(p => p.LocateableRemoved(It.IsAny <object>(), It.IsAny <BucketItemEventArgs <ILocateable> >()), Times.Once);
        }
Ejemplo n.º 19
0
        public void ClassInitialize()
        {
            new PrivateType(typeof(Elpf)).SetStaticField("ind", 0);
            new PrivateType(typeof(GameMap)).SetStaticField("instance", null);
            GameMap map  = GameMap.GetInstance();
            GameMap map1 = GameMap.GetInstance();

            Assert.AreEqual(map.Map.ToString(), "_".PadLeft(30, '_'));
            Elpf per1 = new Elpf();

            Assert.IsTrue(map.Add(per1, 20));
            Assert.AreEqual(map.Map[20], "Elpf0");
            Assert.AreEqual(map1.Map[20], "Elpf0");
            GameMap map2 = GameMap.GetInstance();

            Assert.AreEqual(map2.Map[20], "Elpf0");
        }
Ejemplo n.º 20
0
        // Create a player using SadConsole's Entity class
        public static void CreatePlayer()
        {
            Player = new Player(Color.Yellow, Color.Transparent);

            // Place the player on the first non-movement-blocking tile on the map
            for (int i = 0; i < GameMap.Tiles.Length; i++)
            {
                if (!GameMap.Tiles[i].IsBlockingMove)
                {
                    // Set the player's position to the index of the current map position
                    Player.Position = SadConsole.Helpers.GetPointFromIndex(i, GameMap.Width);
                    break;
                }
            }

            // add the player to the Map's collection of Entities
            GameMap.Add(Player);
        }
Ejemplo n.º 21
0
        public void LocateableAddedAlreadyExists()
        {
            var worldObserver = MockRepository.GenerateStub <IWorldObserver>();
            var view          = MockRepository.GenerateStrictMock <IWorldView>();

            worldObserver.Stub(o => o.WorldView).Return(view);
            var adapter   = new ObserverToWorldViewAdapter(worldObserver, 12);
            var map       = new GameMap(new DataModel.Configuration.GameMapDefinition(), 10, 8, 1000);
            var nonPlayer = new NonPlayerCharacter(new DataModel.Configuration.MonsterSpawnArea(), new DataModel.Configuration.MonsterDefinition(), 0, map)
            {
                X = 128,
                Y = 128
            };

            map.Add(nonPlayer);
            view.Expect(v => v.NewNpcsInScope(null)).IgnoreArguments().Repeat.Once();
            adapter.LocateableAdded(map, new BucketItemEventArgs <ILocateable>(nonPlayer));
            adapter.ObservingBuckets.Add(nonPlayer.CurrentBucket);
            adapter.LocateableAdded(map, new BucketItemEventArgs <ILocateable>(nonPlayer));
            view.VerifyAllExpectations();
        }
Ejemplo n.º 22
0
        public void LocateableAddedAlreadyExists()
        {
            var worldObserver = new Mock <IWorldObserver>();
            var view          = new Mock <IWorldView>();

            worldObserver.Setup(o => o.WorldView).Returns(view.Object);
            var adapter   = new ObserverToWorldViewAdapter(worldObserver.Object, 12);
            var map       = new GameMap(new DataModel.Configuration.GameMapDefinition(), 10, 8, null);
            var nonPlayer = new NonPlayerCharacter(new DataModel.Configuration.MonsterSpawnArea(), new DataModel.Configuration.MonsterDefinition(), map)
            {
                Position = new Point(128, 128)
            };

            map.Add(nonPlayer);
            adapter.LocateableAdded(map, new BucketItemEventArgs <ILocateable>(nonPlayer));
            adapter.ObservingBuckets.Add(nonPlayer.NewBucket);
            nonPlayer.OldBucket = nonPlayer.NewBucket; // oldbucket would be set, if it got moved on the map

            adapter.LocateableAdded(map, new BucketItemEventArgs <ILocateable>(nonPlayer));
            view.Verify(v => v.NewNpcsInScope(It.Is <IEnumerable <NonPlayerCharacter> >(arg => arg.Contains(nonPlayer))), Times.Once);
        }
Ejemplo n.º 23
0
        // Create some random monsters with random attack and defense values
        // and drop them all over the map in
        // random places.
        public static void CreateMonsters()
        {
            // number of monsters to create
            int numMonsters = 10;

            // random position generator
            Random rndNum = new Random();

            // Create several monsters and
            // pick a random position on the map to place them.
            // check if the placement spot is blocking (e.g. a wall)
            // and if it is, try a new position
            for (int i = 0; i < numMonsters; i++)
            {
                int     monsterPosition = 0;
                Monster newMonster      = new Monster(Color.Blue, Color.Transparent);
                while (GameMap.Tiles[monsterPosition].IsBlockingMove)
                {
                    // pick a random spot on the map
                    monsterPosition = rndNum.Next(0, HUD.MapWidth * HUD.MapHeight);
                }

                // plug in some magic numbers for attack and defense values
                newMonster.Defense       = rndNum.Next(0, 10);
                newMonster.DefenseChance = rndNum.Next(0, 50);
                newMonster.Attack        = rndNum.Next(0, 10);
                newMonster.AttackChance  = rndNum.Next(0, 50);
                newMonster.Name          = "a common troll";

                // Set the monster's new position
                // Note: this fancy math will be replaced by a new helper method
                // in the next revision of SadConsole
                newMonster.Position = new Point(monsterPosition % HUD.MapWidth, monsterPosition / HUD.MapWidth);
                GameMap.Add(newMonster);
            }
        }