public int IsNeedToFall(int x, int y) { if (x + 1 < Game.MapWidth) { if (Game.IsIt(x + 1, y, CreatureType.Digger)) { if (Keyboard.IsKeyDown(Key.A) && x > 0) { if (Game.Map[x - 1, y] == null) { return(-1); } } } } if (x > 0) { if (Game.IsIt(x - 1, y, CreatureType.Digger)) { if (Keyboard.IsKeyDown(Key.D) && x < Game.MapWidth - 1) { if (Game.Map[x + 1, y] == null) { return(1); } } } } return(0); }
public CreatureCommand Act(int x, int y) { CreatureCommand Command = new CreatureCommand() { DeltaX = 0, DeltaY = 0, NextState = CreatureType.Sack }; if (y < Game.MapHeight - 1) { if (Game.Map[x, y + 1] == null) { isFall = true; Command.DeltaY += 1; if (y + Command.DeltaY + 1 >= Game.MapHeight) { Command.NextState = CreatureType.Gold; } else if (Game.IsIt(x, y + Command.DeltaY + 1, CreatureType.Terrain) || Game.IsIt(x, y + Command.DeltaY + 1, CreatureType.Gold)) { Command.NextState = CreatureType.Gold; } } else { if (Game.Map[x, y + 1].GetCreatureType() == CreatureType.Monster) { Command.DeltaY += 1; Command.NextState = CreatureType.Gold; } else if (isFall && Game.Map[x, y + 1].GetCreatureType() == CreatureType.Digger) { Command.DeltaY += 1; } } } Command.DeltaX += IsNeedToFall(x, y + Command.DeltaY); return(Command); }
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); }
Pair BFS(Pair[] start, int x, int y) { if (start.Length == 0) { return new Pair { x = -1, y = -1 } } ; List <Pair> list = new List <Pair>(); for (int l = 0; l < start.Length; ++l) { for (int i = start[l].y - 1; i <= start[l].y + 1; ++i) { for (int j = start[l].x - 1; j <= start[l].x + 1; ++j) { if (i >= 0 && i < Game.MapHeight && j >= 0 && j < Game.MapWidth && (j == start[l].x || i == start[l].y)) { if (!map[i, j]) { if (Game.IsIt(j, i, CreatureType.Monster) && j == x && i == y) { continue; } if (Game.IsIt(j, i, CreatureType.Digger)) { int mayBeX = start[l].x, mayBeY = start[l].y; while (true) { int localX = length[mayBeY, mayBeX].x; int localY = length[mayBeY, mayBeX].y; if (localX == x && localY == y) { return new Pair { y = mayBeX, x = mayBeY } } ; mayBeX = localX; mayBeY = localY; if (mayBeY == -1 || mayBeX == -1) { return new Pair { y = j, x = i } } ; } } if (Game.Map[j, i] == null || Game.IsIt(j, i, CreatureType.Monster)) { length[i, j].x = start[l].x; length[i, j].y = start[l].y; list.Add(new Pair { y = i, x = j }); map[i, j] = true; } } } } } } return(BFS(list.ToArray(), x, y)); }