Exemplo n.º 1
0
        public void GetCreature_ShouldReturnAddedCreature_AfterAddCreatureInEmptyCell()
        {
            var player  = new Player(0);
            var student = new Student(dialogue);

            level.AddCreature(0, 0, player);
            level.GetCreatures(0, 0).Should().HaveCount(1).And.AllBeOfType(typeof(Player));
            level.AddCreature(0, 0, student);
            level.GetCreatures(0, 0).Should().HaveCount(2).And.BeEquivalentTo(player, student);
        }
        public void ActStudent_ShouldReturnOffsetOnX()
        {
            var point   = new Point(1, 0);
            var student = level.GetCreatures(point.X, point.Y).FirstOrDefault();

            student.Should().NotBeNull();
            for (int i = 0; i < 1000; i++)
            {
                var action = student.Act(level, point.X, point.Y);
                action.DeltaX.Should().BeInRange(-1, 1);
                level.RemoveCreature(point.X, point.Y, student.GetType());
                point.X += action.DeltaX;
                point.Y += action.DeltaY;
                level.AddCreature(point.X, point.Y, student);
            }
            level.GetCreatures(point.X, point.Y).Any(x => x is Student).Should().BeTrue();
        }
Exemplo n.º 3
0
        public Move Act(Level level, int x, int y)
        {
            level.NumberBeer = numberBeer;

            if (PlayerNumber == 1 && timeIgnor > 0)
            {
                timeIgnor -= 1;
                if (timeIgnor == 0)
                {
                    Status = Status.Active;
                }
            }

            if (level.KeyPressed == Keys.R)
            {
                if (PlayerNumber == 0 && numberBeer > 0 && !level.CheckCreature(x, y, typeof(Python)))
                {
                    level.AddCreature(x, y, new Python());
                    numberBeer -= 1;
                }

                if (PlayerNumber == 1 && numberBeer > 0)
                {
                    Status      = Status.Inactive;
                    timeIgnor   = 15;
                    numberBeer -= 1;
                }

                if (PlayerNumber == 3 && numberBeer > 0 && !level.CheckCreature(x, y, typeof(Device)))
                {
                    level.AddCreature(x, y, new Device());
                    numberBeer -= 1;
                }
            }

            if (y + 1 <= level.Height - 1 &&
                !(level.CheckCreature(x, y + 1, typeof(Terrain)) ||
                  level.CheckCreature(x, y + 1, typeof(Stairs)) ||
                  level.CheckCreature(x, y, typeof(Stairs))))
            {
                return new Move {
                           DeltaY = 1
                }
            }
            ;

            if (level.KeyPressed == Keys.Up && y - 1 >= 0 &&
                level.CheckCreature(x, y, typeof(Stairs)) &&
                !level.CheckCreature(x, y - 1, typeof(Terrain)))
            {
                return new Move {
                           DeltaY = -1
                }
            }
            ;

            if (level.KeyPressed == Keys.Down && y + 1 <= level.Height - 1 &&
                (level.CheckCreature(x, y + 1, typeof(Stairs)) || !level.CheckCreature(x, y + 1, typeof(Terrain))))
            {
                return new Move {
                           DeltaY = 1
                }
            }
            ;

            if (level.KeyPressed == Keys.Left && x - 1 >= 0 &&
                !level.CheckCreature(x - 1, y, typeof(Terrain)))
            {
                return new Move {
                           DeltaX = -1
                }
            }
            ;

            if (level.KeyPressed == Keys.Right && x + 1 <= level.Width - 1 &&
                !level.CheckCreature(x + 1, y, typeof(Terrain)))
            {
                return new Move {
                           DeltaX = 1
                }
            }
            ;

            return(new Move());
        }