bool MiceWalk(IMouse[] mice) { IMouse selectedMouse = null; foreach (var mouse in mice) { if (!mouse.IsActive) { continue; } if (tiles[mouse.Y, mouse.XForward] != TileType.Empty) { continue; } if (selectedMouse != null && selectedMouse.IsCloserToFinishThan(mouse)) { continue; } selectedMouse = mouse; } if (selectedMouse != null) { tiles[selectedMouse.Y, selectedMouse.X] = TileType.Empty; selectedMouse.X = selectedMouse.XForward; tiles[selectedMouse.Y, selectedMouse.X] = TileType.Mouse; return(true); } return(false); }
bool MiceFall(IMouse[] mice, ref int score) { IMouse selectedMouse = null; foreach (var mouse in mice) { if (!mouse.IsActive) { continue; } if (mouse.Y == 0) { if (mouse.X > 0 && mouse.X < tiles.GetLength(1) - 1) { continue; } score++; tiles[mouse.Y, mouse.X] = TileType.Empty; mouse.IsActive = false; return(true); } if (tiles[mouse.Y - 1, mouse.X] != TileType.Empty) { continue; } if (selectedMouse != null && selectedMouse.IsCloserToFinishThan(mouse)) { continue; } selectedMouse = mouse; } if (selectedMouse != null) { tiles[selectedMouse.Y, selectedMouse.X] = TileType.Empty; selectedMouse.Y -= 1; tiles[selectedMouse.Y, selectedMouse.X] = TileType.Mouse; return(true); } return(false); }