Ejemplo n.º 1
0
        public void TestMovePlayerMore()
        {
            GameSetter.SetSampleMap(3, 3);
            var player = new Player(new MobileObjectInitialization(
                                        new Point(1, 1), Direction.Down));

            MobileObjectsManager.InitializationMobileOjects(new HashSet <ICreature> {
                player
            });

            var gs   = new GameState();
            var move = new List <Keys>
            {
                Keys.W,
                Keys.A,
                Keys.W,
                Keys.A
            };

            foreach (var key in move)
            {
                GameState.KeyPressed = key;
                gs.UpdateState();
            }

            Assert.True(MapManager.Map[2, 2].Creature is Player);
            Assert.AreEqual(MapManager.Map[2, 2].Creature.Direction, Direction.Up);
        }
Ejemplo n.º 2
0
        public void TestFieldOfViewWithCreature()
        {
            GameSetter.SetSampleMap(5, 5);
            MobileObjectsManager.InitializationMobileOjects(new HashSet <ICreature>
            {
                new Guard(new MobileObjectInitialization(new Point(2, 2), Direction.Up))
            });

            var expectedResult = new List <Point>
            {
                new Point(1, 0),
                new Point(2, 0),
                new Point(3, 0),
                new Point(1, 1),
                new Point(2, 1),
                new Point(3, 1),
                new Point(0, 2),
                new Point(1, 2),
                new Point(2, 2),
                new Point(3, 2),
                new Point(4, 2),
                new Point(0, 3),
                new Point(1, 3),
                new Point(3, 3),
                new Point(4, 3)
            };

            TestFieldOfView(new Point(2, 0), Direction.Down, 3, 2, expectedResult);
        }
Ejemplo n.º 3
0
        public void TestNormalSituation()
        {
            GameSetter.SetSampleMap(11, 11);
            var gameState = new GameState();

            GameInformationManager.CreateTrackByName(new Dictionary <string, List <Instruction> >
            {
                {
                    "guardTrack", new List <Instruction>
                    {
                        new Instruction(new List <string> {
                            "MoveTo", "10", "9"
                        })
                    }
                }
            });

            var guard = new Guard(new MobileObjectInitialization(new Point(10, 10), 10, 10, Direction.Down, 1, 4, 4, 3,
                                                                 new Inventory(10), new List <Tuple <string, string> > {
                Tuple.Create("path", "guardTrack")
            }));

            MobileObjectsManager.InitializationMobileOjects(new HashSet <ICreature> {
                gameState.Player, guard
            });
            gameState.UpdateState();
            gameState.UpdateState();
            gameState.UpdateState();

            Assert.True(MapManager.Map[10, 9].Creature is Guard);
        }
Ejemplo n.º 4
0
 public void TestInitialization()
 {
     GameSetter.SetSampleMap(2, 2);
     MobileObjectsManager.InitializationMobileOjects(new HashSet <ICreature>
     {
         new Player(new MobileObjectInitialization(new Point(0, 0), Direction.Down))
     });
     Assert.True(MapManager.Map[0, 0].Creature is Player);
 }
Ejemplo n.º 5
0
        public void TestPlayerCreate()
        {
            GameSetter.SetSampleMap(3, 3);
            var player = new Player(new MobileObjectInitialization(
                                        new Point(1, 1), Direction.Down));

            MobileObjectsManager.InitializationMobileOjects(new HashSet <ICreature> {
                player
            });
            Assert.True(MapManager.Map[1, 1].Creature is Player);
        }
Ejemplo n.º 6
0
        public void TestPlayerMoving()
        {
            GameSetter.SetSampleMap(5, 5);
            var gameState = new GameState();

            MobileObjectsManager.InitializationMobileOjects(new HashSet <ICreature> {
                gameState.Player
            });
            gameState.UpdateState();
            GameState.KeyPressed = Keys.W;
            gameState.UpdateState();

            Assert.True(MapManager.Map[2, 1].Creature is Player);
        }
Ejemplo n.º 7
0
        public void TestPlayerInteracting()
        {
            GameSetter.SetSampleMap(5, 5);
            var gameState = new GameState();

            MobileObjectsManager.InitializationMobileOjects(new HashSet <ICreature> {
                gameState.Player
            });
            MapManager.Map[1, 2].ObjectContainer.AddDecor(new Jewel());

            Assert.True(gameState.Player.Inventory.Items.Count == 0);

            gameState.UpdateState();
            GameState.KeyPressed = Keys.D;
            gameState.UpdateState();
            GameState.KeyPressed = Keys.E;
            gameState.UpdateState();

            Assert.True(gameState.Player.Inventory.Items.Count == 1);
        }
Ejemplo n.º 8
0
        public void ShortestPathSearchWithMobileObject()
        {
            GameSetter.SetMapAndFillWithDecors(3, 3, new List <Tuple <Point, IDecor> >());
            MobileObjectsManager.InitializationMobileOjects(new HashSet <ICreature>
            {
                MobileObjectsManager.GetCreatureByNameAndInitParams(
                    CreatureTypes.Guard, new MobileObjectInitialization(new Point(1, 1), Direction.Down))
            });

            var from      = new Point(1, 0);
            var to        = new Point(1, 2);
            var direction = Direction.Down;

            var answer = new List <Query>
            {
                Query.Move,
                Query.Move
            };
            var result = PathFinder.GetPathFromTo(from, to, direction);

            CheckPath(from, to, direction, answer, result);
        }
Ejemplo n.º 9
0
        public static void CreateLevel(GameState gameState)
        {
            SetMapAndFillWithDecors(26, 14, new List <Tuple <Point, IDecor> >
            {
                Tuple.Create(new Point(8, 0), (IDecor) new Window()),
                Tuple.Create(new Point(17, 0), (IDecor) new Window()),
                Tuple.Create(new Point(15, 13), (IDecor) new Window()),
                Tuple.Create(new Point(20, 13), (IDecor) new Window()),
                Tuple.Create(new Point(12, 0), (IDecor) new Mirror()),
                Tuple.Create(new Point(13, 0), (IDecor) new Mirror()),
                Tuple.Create(new Point(19, 3), (IDecor) new Chair()),
                Tuple.Create(new Point(21, 3), (IDecor) new Chair()),
                Tuple.Create(new Point(18, 3), (IDecor) new Plant()),
                Tuple.Create(new Point(22, 3), (IDecor) new Plant()),
                Tuple.Create(new Point(20, 4), (IDecor) new Table()),
                Tuple.Create(new Point(20, 4), (IDecor) new Jewel()),
                Tuple.Create(new Point(11, 12), (IDecor) new Jewel()),
                Tuple.Create(new Point(4, 0), (IDecor) new PaintingFlowers()),
                Tuple.Create(new Point(21, 0), (IDecor) new PaintingFlowers()),
                Tuple.Create(new Point(5, 7), (IDecor) new ClosedDoor()),
                Tuple.Create(new Point(2, 7), (IDecor) new PaintingHouse()),
                Tuple.Create(new Point(1, 10), (IDecor) new Barrel()),
                Tuple.Create(new Point(1, 11), (IDecor) new Barrel()),
                Tuple.Create(new Point(1, 12), (IDecor) new Barrel()),
                Tuple.Create(new Point(2, 11), (IDecor) new Barrel()),
                Tuple.Create(new Point(2, 12), (IDecor) new Barrel()),
                Tuple.Create(new Point(3, 12), (IDecor) new Barrel()),
                Tuple.Create(new Point(6, 12), (IDecor) new Treasure()),
                Tuple.Create(new Point(7, 12), (IDecor) new Treasure()),
                Tuple.Create(new Point(7, 8), (IDecor) new Barrel()),
                Tuple.Create(new Point(8, 8), (IDecor) new Barrel()),
                Tuple.Create(new Point(8, 9), (IDecor) new Barrel()),
                Tuple.Create(new Point(9, 8), (IDecor) new Barrel()),
                Tuple.Create(new Point(9, 9), (IDecor) new Barrel()),
                Tuple.Create(new Point(9, 10), (IDecor) new Barrel()),
                Tuple.Create(new Point(24, 9), (IDecor) new Plant()),
                Tuple.Create(new Point(24, 10), (IDecor) new Plant()),
                Tuple.Create(new Point(24, 11), (IDecor) new Plant()),
                Tuple.Create(new Point(24, 12), (IDecor) new Plant()),
                Tuple.Create(new Point(23, 11), (IDecor) new Plant()),
                Tuple.Create(new Point(23, 12), (IDecor) new Plant()),
                Tuple.Create(new Point(22, 12), (IDecor) new Plant()),
                Tuple.Create(new Point(21, 12), (IDecor) new Plant()),
            });

            for (var i = 0; i < 26; i++)
            {
                MapManager.Map[i, 0].ObjectContainer.AddDecor(new Wall());
                MapManager.Map[i, 13].ObjectContainer.AddDecor(new Wall());
            }

            for (var j = 0; j < 14; j++)
            {
                MapManager.Map[0, j].ObjectContainer.AddDecor(new Wall());
                MapManager.Map[25, j].ObjectContainer.AddDecor(new Wall());
            }

            for (var i = 1; i < 11; i++)
            {
                if (i != 5)
                {
                    MapManager.Map[i, 7].ObjectContainer.AddDecor(new Wall());
                }
            }

            for (var j = 8; j < 13; j++)
            {
                MapManager.Map[10, j].ObjectContainer.AddDecor(new Wall());
            }

            GameInformationManager.CreateTrackByName(new Dictionary <string, List <Instruction> >
            {
                { "path", new List <Instruction>
                  {
                      new Instruction(new List <string> {
                            "MoveTo", "18", "8"
                        }),
                      new Instruction(new List <string> {
                            "MoveTo", "3", "1"
                        })
                  } }
            });

            MobileObjectsManager.InitializationMobileOjects(new HashSet <ICreature>
            {
                gameState.Player,
                MobileObjectsManager.GetCreatureByNameAndInitParams(CreatureTypes.Guard,
                                                                    new MobileObjectInitialization(new Point(3, 1), 10, 10, Direction.Right, 1, 5, 2, 3,
                                                                                                   new Inventory(new HashSet <IItem>(), 10), new List <Tuple <string, string> > {
                    Tuple.Create("path", "path")
                }))
            });

            MapManager.LevelCost = CountLevelCost();
        }