public CreatureCommand Act(int x, int y)
        {
            CreatureCommand movement = new CreatureCommand();

            if (Game.KeyPressed == Keys.W || Game.KeyPressed == Keys.Up)
            {
                movement.DeltaY = -1;
            }

            if (Game.KeyPressed == Keys.S || Game.KeyPressed == Keys.Down)
            {
                movement.DeltaY = 1;
            }

            if (Game.KeyPressed == Keys.A || Game.KeyPressed == Keys.Left)
            {
                movement.DeltaX = -1;
            }

            if (Game.KeyPressed == Keys.D || Game.KeyPressed == Keys.Right)
            {
                movement.DeltaX = 1;
            }

            CheckBorders(x, y, movement);
            ICreature creatureX = Game.Map[x + movement.DeltaX, y];

            if (creatureX is Sack)
            {
                movement.DeltaX = 0;
            }

            ICreature creatureY = Game.Map[x, y + movement.DeltaY];

            if (creatureY is Sack)
            {
                movement.DeltaY = 0;
            }

            return(movement);
        }
Beispiel #2
0
        public CreatureCommand Act(int x, int y)
        {
            var cmd = new CreatureCommand {
                DeltaX = 0, DeltaY = 1, TransformTo = this
            };

            if (CanFallTo(x + cmd.DeltaX, y + cmd.DeltaY))
            {
                ++FallingTime;
            }
            else
            {
                if (FallingTime > 1)
                {
                    cmd.TransformTo = new Gold();
                }
                FallingTime = 0;
                cmd.DeltaY  = 0;
            }
            return(cmd);
        }
        public CreatureCommand Act(int x, int y)
        {
            var command = new CreatureCommand();

            switch (Game.KeyPressed)
            {
            case Keys.Left:
                if (x != 0)
                {
                    command.DeltaX = -1;
                }
                command.DeltaY = 0;
                break;

            case Keys.Right:
                if (x != Game.Map.GetLength(0) - 1)
                {
                    command.DeltaX = 1;
                }
                command.DeltaY = 0;
                break;

            case Keys.Down:
                if (y != Game.Map.GetLength(1) - 1)
                {
                    command.DeltaY = 1;
                }
                command.DeltaX = 0;
                break;

            case Keys.Up:
                if (y != 0)
                {
                    command.DeltaY = -1;
                }
                command.DeltaX = 0;
                break;
            }
            return(command);
        }
Beispiel #4
0
        public CreatureCommand Act(int x, int y)
        {
            var player = new CreatureCommand();

            switch (Game.KeyPressed)
            {
            case Keys.Up:
                if (y - 1 >= 0 && !(Game.Map[x, y - 1] is Sack))
                {
                    player.DeltaY = -1;
                }
                break;

            case Keys.Down:
                if (y + 1 < Game.MapHeight && !(Game.Map[x, y + 1] is Sack))
                {
                    player.DeltaY = 1;
                }
                break;

            case Keys.Left:
                if (x - 1 >= 0 && !(Game.Map[x - 1, y] is Sack))
                {
                    player.DeltaX = -1;
                }
                break;

            case Keys.Right:
                if (x + 1 < Game.MapWidth && !(Game.Map[x + 1, y] is Sack))
                {
                    player.DeltaX = 1;
                }
                break;

            default:
                break;
            }

            return(player);
        }
Beispiel #5
0
        public CreatureCommand Act(int x, int y)
        {
            var command = new CreatureCommand();

            if (Game.KeyPressed == Keys.Right && x + 1 < Game.MapWidth)
            {
                command.DeltaX = 1;
            }
            else if (Game.KeyPressed == Keys.Left && x - 1 >= 0)
            {
                command.DeltaX = -1;
            }
            else if (Game.KeyPressed == Keys.Up && y - 1 >= 0)
            {
                command.DeltaY = -1;
            }
            else if (Game.KeyPressed == Keys.Down && y + 1 < Game.MapHeight)
            {
                command.DeltaY = 1;
            }
            return(command);
        }
        public CreatureCommand Act(int x, int y)
        {
            var act = new CreatureCommand();

            if ((y + 1 < Game.MapHeight) &&
                (Game.Map[x, y + 1] == null ||
                 ((Game.Map[x, y + 1] is Player || Game.Map[x, y + 1] is Monster) &&
                  Way > 0)))
            {
                act.DeltaY += 1;
                Way++;
            }
            else if (Way > 1)
            {
                act.TransformTo = (ICreature) new Gold();
            }
            else
            {
                Way = 0;
            }
            return(act);
        }
        public CreatureCommand Act(int x, int y)
        {
            var result = new CreatureCommand();

            switch (Game.KeyPressed)
            {
            case System.Windows.Forms.Keys.Left:
                if (x - 1 >= 0 && !(Game.Map[x - 1, y] is Sack))
                {
                    result.DeltaX = -1;
                }
                break;

            case System.Windows.Forms.Keys.Up:
                if (y - 1 >= 0 && !(Game.Map[x, y - 1] is Sack))
                {
                    result.DeltaY = -1;
                }
                break;

            case System.Windows.Forms.Keys.Down:
                if (y + 1 < Game.MapHeight && !(Game.Map[x, y + 1] is Sack))
                {
                    result.DeltaY = 1;
                }
                break;

            case System.Windows.Forms.Keys.Right:
                if (x + 1 < Game.MapWidth && !(Game.Map[x + 1, y] is Sack))
                {
                    result.DeltaX = 1;
                }
                break;

            default:
                break;
            }
            return(result);
        }
        public CreatureCommand Act(int x, int y)
        {
            var act             = new CreatureCommand();
            var playerLocationX = -1;
            var playerLocationY = -1;

            for (int i = 0; i < Game.MapWidth; i++)
            {
                for (int j = 0; j < Game.MapHeight; j++)
                {
                    if (Game.Map[i, j] is Player)
                    {
                        playerLocationX = i;
                        playerLocationY = j;
                    }
                }
            }
            if (playerLocationX == -1 && playerLocationY == -1)
            {
                return(act);
            }
            if (playerLocationX > x && x + 1 < Game.MapWidth && !(Game.Map[x + 1, y] is Sack || Game.Map[x + 1, y] is Terrain || Game.Map[x + 1, y] is Monster))
            {
                act.DeltaX = 1;
            }
            else if (playerLocationX < x && x - 1 >= 0 && !(Game.Map[x - 1, y] is Sack || Game.Map[x - 1, y] is Terrain || Game.Map[x - 1, y] is Monster))
            {
                act.DeltaX = -1;
            }
            else if (playerLocationY < y && y - 1 >= 0 && !(Game.Map[x, y - 1] is Sack || Game.Map[x, y - 1] is Terrain || Game.Map[x, y - 1] is Monster))
            {
                act.DeltaY = -1;
            }
            else if (playerLocationY > y && y + 1 < Game.MapHeight && !(Game.Map[x, y + 1] is Sack || Game.Map[x, y + 1] is Terrain || Game.Map[x, y + 1] is Monster))
            {
                act.DeltaY = 1;
            }
            return(act);
        }
        public CreatureCommand Act(int x, int y)
        {
            var command = new CreatureCommand();
            var key     = Game.KeyPressed;

            switch (key)
            {
            case Keys.Up:
                if (y > 0 && !(Game.Map[x, y - 1] is Sack))
                {
                    command.DeltaY = -1;
                }
                break;

            case Keys.Down:
                if (y < Game.MapHeight - 1 && !(Game.Map[x, y + 1] is Sack))
                {
                    command.DeltaY = 1;
                }
                break;

            case Keys.Left:
                if (x > 0 && !(Game.Map[x - 1, y] is Sack))
                {
                    command.DeltaX = -1;
                }
                break;

            case Keys.Right:
                if (x < Game.MapWidth - 1 && !(Game.Map[x + 1, y] is Sack))
                {
                    command.DeltaX = 1;
                }
                break;
            }

            return(command);
        }
        public CreatureCommand Act(int x, int y)
        {
            var command   = new CreatureCommand();
            var isFalling = y < Game.MapHeight - 1 &&
                            ((Game.Map[x, y + 1] is Player || Game.Map[x, y + 1] is Monster) &&
                             passedCells > 0 || Game.Map[x, y + 1] == null);

            if (isFalling)
            {
                command.DeltaY = 1;
                ++passedCells;
            }
            else
            {
                if (passedCells > 1)
                {
                    command.TransformTo = new Gold();
                }
                passedCells = 0;
            }

            return(command);
        }
        private CreatureCommand HandleKeys()
        {
            var cmd = new CreatureCommand();

            if (Game.KeyPressed == Keys.Left)
            {
                cmd.DeltaX = -1;
            }
            else if (Game.KeyPressed == Keys.Right)
            {
                cmd.DeltaX = 1;
            }
            else if (Game.KeyPressed == Keys.Up)
            {
                cmd.DeltaY = -1;
            }
            else if (Game.KeyPressed == Keys.Down)
            {
                cmd.DeltaY = 1;
            }

            return(cmd);
        }
Beispiel #12
0
        public CreatureCommand Act(int x, int y)
        {
            var cmd = new CreatureCommand {
                DeltaX = 0, DeltaY = 0, TransformTo = this
            };

            switch (Game.KeyPressed)
            {
            case System.Windows.Forms.Keys.Up:
                cmd.DeltaY = -1;
                break;

            case System.Windows.Forms.Keys.Down:
                cmd.DeltaY = 1;
                break;

            case System.Windows.Forms.Keys.Left:
                cmd.DeltaX = -1;
                break;

            case System.Windows.Forms.Keys.Right:
                cmd.DeltaX = 1;
                break;

            default:
                break;
            }
            if (!CanWalkTo(x + cmd.DeltaX, y + cmd.DeltaY))
            {
                cmd.DeltaX = cmd.DeltaY = 0;
            }
            else if (Game.Map.GetValue(x + cmd.DeltaX, y + cmd.DeltaY) is Gold)
            {
                Game.Scores += 10;
            }
            return(cmd);
        }
Beispiel #13
0
        public CreatureCommand Act(int x, int y)
        {
            CreatureCommand Command = new CreatureCommand()
            {
                DeltaX    = 0,
                DeltaY    = 0,
                NextState = CreatureType.Digger
            };
            Pair move = Mooving(x, y);

            Command.DeltaX = move.x;
            Command.DeltaY = move.y;
            if (Command.DeltaX == 0)
            {
                if (Game.IsIt(x, y + Command.DeltaY, CreatureType.Sack))
                {
                    Command.DeltaX = 0;
                    Command.DeltaY = 0;
                }
            }
            if (Command.DeltaY == 0)
            {
                if (Game.IsIt(x + Command.DeltaX, y, CreatureType.Sack))
                {
                    if ((x + 2 * Command.DeltaX >= Game.MapWidth || x + 2 * Command.DeltaX < 0) || (Game.Map[x + 2 * Command.DeltaX, y] != null))
                    {
                        Command.DeltaX = 0;
                        Command.DeltaY = 0;
                    }
                }
            }
            if (Game.IsIt(x + Command.DeltaX, y + Command.DeltaY, CreatureType.Gold))
            {
                Game.Scores += 1;
            }
            return(Command);
        }
Beispiel #14
0
        private CreatureCommand Move(int pX, int pY, int x, int y)
        {
            var el = new CreatureCommand();
            var dX = pX - x;
            var dY = pY - y;

            if (dX > 0 && x + 1 < Game.MapWidth && CheckBox(x + 1, y))
            {
                el.DeltaX = 1;
            }
            else if (dX < 0 && x - 1 > -1 && CheckBox(x - 1, y))
            {
                el.DeltaX = -1;
            }
            else if (dY > 0 && y + 1 < Game.MapHeight && CheckBox(x, y + 1))
            {
                el.DeltaY = 1;
            }
            else if (dY < 0 && y - 1 > -1 && CheckBox(x, y - 1))
            {
                el.DeltaY = -1;
            }
            return(el);
        }
Beispiel #15
0
        public CreatureCommand Act(int x, int y)
        {
            var player = new CreatureCommand();
            var key    = Game.KeyPressed;

            if (key == Keys.Up && y - 1 >= 0)
            {
                player.DeltaY = -1;
            }
            else if (key == Keys.Down && y + 1 < Game.MapHeight)
            {
                player.DeltaY = 1;
            }
            else if (key == Keys.Left && x - 1 >= 0)
            {
                player.DeltaX = -1;
            }
            else if (key == Keys.Right && x + 1 < Game.MapWidth)
            {
                player.DeltaX = 1;
            }

            return(player);
        }
Beispiel #16
0
        public CreatureCommand Act(int x, int y)
        {
            var com = new CreatureCommand {
                DeltaX = 0, DeltaY = 0
            };

            if (x < game.DigX && x < game.MapWidth - 1)
            {
                com = Checking(x, y, x + 1, y, com);
            }
            if (x > game.DigX && x > 0)
            {
                com = Checking(x, y, x - 1, y, com);
            }
            if (y < game.DigY && y < game.MapHeight - 1 && com.DeltaX == 0)
            {
                com = Checking(x, y, x, y + 1, com);
            }
            if (y > game.DigY && y > 0 && com.DeltaX == 0)
            {
                com = Checking(x, y, x, y - 1, com);
            }
            return(com);
        }
Beispiel #17
0
        public CreatureCommand Act(int x, int y)
        {
            var monster = new CreatureCommand {
            };

            if (PlayerOnTheMap())
            {
                if (GetCoordinatesPlayer()[0] < x) //Алгоритм нахождения кратчайшего пути до Player
                {
                    monster.DeltaX = -1;
                    if (!GetNameObject(x + monster.DeltaX, y + monster.DeltaY))
                    {
                        return(monster);
                    }
                    {
                        monster.DeltaX = 0;
                        return(monster);
                    }
                }

                if (GetCoordinatesPlayer()[0] > x)
                {
                    monster.DeltaX = 1;
                    if (!GetNameObject(x + monster.DeltaX, y + monster.DeltaY))
                    {
                        return(monster);
                    }
                    {
                        monster.DeltaX = 0;
                        return(monster);
                    }
                }

                if (GetCoordinatesPlayer()[1] < y)
                {
                    monster.DeltaY = -1;
                    if (!GetNameObject(x + monster.DeltaX, y + monster.DeltaY))
                    {
                        return(monster);
                    }
                    {
                        monster.DeltaY = 0;
                        return(monster);
                    }
                }

                if (GetCoordinatesPlayer()[1] > y)
                {
                    monster.DeltaY = 1;
                    if (!GetNameObject(x + monster.DeltaX, y + monster.DeltaY))
                    {
                        return(monster);
                    }
                    {
                        monster.DeltaY = 0;
                        return(monster);
                    }
                }
            }
            return(monster);
        }
Beispiel #18
0
        void Act()
        {
            bool skip = false;
            if (request == MovementRequest.No || request == MovementRequest.Processed)
                skip = true;
            else if (request == MovementRequest.Given)
                request = MovementRequest.Taken;
            else throw new Exception("Wrong request state "+request);

            animations.Clear();
            for (int x = 0; x < map.Width; x++)
                for (int y = 0; y < map.Height; y++)
                {
                    var creature = map[x, y];
                    if (creature == null) continue;
                    CreatureCommand command;
                    if (!map.GameOver && !skip)
                        command = creature.Act(map, x, y);
                    else
                        command = new CreatureCommand { DeltaX = 0, DeltaY = 0, TransformTo = null };
                    animations.Add(new CreatureAnimation
                    {
                        Command=command,
                        Creature = creature,
                        Location = new Point(x * ElementSize, y * ElementSize)
                    });
                }
            animations = animations.OrderByDescending(z => z.Creature.GetDrawingPriority()).ToList();
        }
Beispiel #19
0
        public CreatureCommand Act(int x, int y, Game game)
        {
            int[] mas = new int[] { 0, 0 };
            if (game.KeyPressed == Keys.F && game.LastKeyPressed != null && game.LastKeyPressed != Keys.F && game.countDynamit > 0)
            {
                game.countDynamit--;
                game.KeyPressed = game.LastKeyPressed;
                if (game.KeyPressed == Keys.W || game.KeyPressed == Keys.Up)
                {
                    if (game.Map[x, y + 1] == null)
                    {
                        game.Map[x, y + 1] = new Dynamite(6);
                    }
                }
                if (game.KeyPressed == Keys.A || game.KeyPressed == Keys.Left)
                {
                    if (game.Map[x + 1, y] == null)
                    {
                        game.Map[x + 1, y] = new Dynamite(6);
                    }
                }
                if (game.KeyPressed == Keys.D || game.KeyPressed == Keys.Right)
                {
                    if (game.Map[x - 1, y] == null)
                    {
                        game.Map[x - 1, y] = new Dynamite(6);
                    }
                }
                if (game.KeyPressed == Keys.S || game.KeyPressed == Keys.Down)
                {
                    if (game.Map[x, y - 1] == null)
                    {
                        game.Map[x, y - 1] = new Dynamite(6);
                    }
                }
                if (game.KeyPressed != null)
                {
                    game.LastKeyPressed = game.KeyPressed;
                }
                game.KeyPressed = null;
                return(new CreatureCommand {
                    DeltaX = 0, DeltaY = 0, TransformTo = game.Map[x, y]
                });
            }
            if (game.KeyPressed == Keys.W || game.KeyPressed == Keys.Up)
            {
                mas = new int[] { 0, -1 }
            }
            ;
            if (game.KeyPressed == Keys.A || game.KeyPressed == Keys.Left)
            {
                mas = new int[] { -1, 0 }
            }
            ;
            if (game.KeyPressed == Keys.D || game.KeyPressed == Keys.Right)
            {
                mas = new int[] { 1, 0 }
            }
            ;
            if (game.KeyPressed == Keys.S || game.KeyPressed == Keys.Down)
            {
                mas = new int[] { 0, 1 }
            }
            ;
            if (game.KeyPressed != null)
            {
                game.LastKeyPressed = game.KeyPressed;
            }
            game.KeyPressed = null;

            var ans = new CreatureCommand {
                DeltaX = mas[0], DeltaY = mas[1], TransformTo = game.Map[x, y]
            };

            if (x + ans.DeltaX > 0 && x + ans.DeltaX < game.MapWidth - 1 && y + ans.DeltaY > 0 && y + ans.DeltaY < game.MapHeight - 1 &&
                !(game.Map[x + ans.DeltaX, y + ans.DeltaY] is Sack || game.Map[x + ans.DeltaX, y + ans.DeltaY] is Dynamite))
            {
                return(ans);
            }
            else
            {
                return new CreatureCommand {
                           DeltaX = 0, DeltaY = 0, TransformTo = game.Map[x, y]
                }
            };
        }
        public CreatureCommand Act(int x, int y)
        {
            var result = new CreatureCommand();

            return(new CreatureCommand());
        }
Beispiel #21
0
        private static bool IsSackNear(int x, int y, CreatureCommand command)
        {
            var potentialSack = Game.Map[x + command.DeltaX, y + command.DeltaY];

            return(potentialSack != null && potentialSack.ToString() == "Digger.Sack");
        }
 private void HandleFreeWay(CreatureCommand cmd)
 {
     cmd.DeltaY = 1;
     isFalling  = true;
 }