public override void BuildIndestructableWalls() { Random r = new Random(); var wallFactory = new WallFactory(); for (int i = 0; i < Map.Objects.GetLength(0); i++) { for (int j = 0; j < Map.Objects.GetLength(0); j++) { if (j == 0 || j == (Map.Objects.GetLength(0) - 1) || i == 0 || i == (Map.Objects.GetLength(0) - 1)) { Map.Objects[i][j].entity = wallFactory.CreateWall(2); } else { if (i % 2 == 0 && j % 2 == 0) { Map.Objects[i][j].entity = wallFactory.CreateWall(2); } } } } }
public override void BuildItemDropWalls() { Random r = new Random(); int rand = 0; var wallFactory = new WallFactory(); ItemArray itemsRepository = new ItemArray(); var iter = itemsRepository.GetIterator(); for (int i = 0; i < Map.Objects.GetLength(0); i++) { for (int j = 0; j < Map.Objects.GetLength(0); j++) { rand = r.Next(0, 10); if (j == 0 || j == (Map.Objects.GetLength(0) - 1) || i == 0 || i == (Map.Objects.GetLength(0) - 1)) { continue; } else { if (i % 2 == 0 && j % 2 == 0) { continue; } else { if (((i == 1 && (j == 1 || j == 2)) || (i == 2 && j == 1) || (i == (Map.Objects.GetLength(0) - 1) - 2 && j == (Map.Objects.GetLength(0) - 1) - 1) || (i == (Map.Objects.GetLength(0) - 1) - 1 && (j == (Map.Objects.GetLength(0) - 1) - 1 || j == (Map.Objects.GetLength(0) - 1) - 2)))) { //empty path continue; } else if (rand >= 9) { Map.Objects[i][j].entity = wallFactory.CreateWall(3); iter.HasNext(); Map.Objects[i][j].item = iter.Next(j, numSquaresY); } } } } } }
public override void BuildDestructableWalls() { Random r = new Random(); int rand = 0; var wallFactory = new WallFactory(); for (int i = 0; i < Map.Objects.GetLength(0); i++) { for (int j = 0; j < Map.Objects.GetLength(0); j++) { rand = r.Next(0, 10); if (j == 0 || j == (Map.Objects.GetLength(0) - 1) || i == 0 || i == (Map.Objects.GetLength(0) - 1)) { continue; } else { if (i % 2 == 0 && j % 2 == 0) { continue; } else { if (((i == 1 && (j == 1 || j == 2)) || (i == 2 && j == 1) || (i == (Map.Objects.GetLength(0) - 1) - 2 && j == (Map.Objects.GetLength(0) - 1) - 1) || (i == (Map.Objects.GetLength(0) - 1) - 1 && (j == (Map.Objects.GetLength(0) - 1) - 1 || j == (Map.Objects.GetLength(0) - 1) - 2)))) { //empty path continue; } else if (rand >= 6) { Map.Objects[i][j].entity = wallFactory.CreateWall(1); } } } } } }
private void AddNewItem() { int x = 0, y = 0; Random r = new Random(); while (!(Map.Objects[x][y].entity == null)) { x = r.Next(0, numSquaresX); y = r.Next(0, numSquaresY); } var wallFactory = new WallFactory(); ItemArray itemsRepository = new ItemArray(); var iter = itemsRepository.GetIterator(); Map.Objects[x][y].entity = wallFactory.CreateWall(3); iter.HasNext(); Map.Objects[x][y].item = iter.Next(y, numSquaresY); }
public void Explode(int x, int y) { if (Map.Objects[x][y].bomb == null) { return; } CompositeDirectory destroyedEntities = new CompositeDirectory(); int radius = Map.Objects[x][y].bomb.explosionRadius(2); Map.Objects[x][y].destroy(); var wallFactory = new WallFactory(); bool up = false, down = false, left = false, right = false; for (int i = 1; i <= radius; i++) { if (x + i < numSquaresX && !(Map.Objects[x + i][y].entity is IndestructableWall) && !(Map.Objects[x + i][y].entity is Fire) && !right) { if (Map.Objects[x][y].bomb is FireBomb) { Map.Objects[x + i][y].entity = new Fire(x + i, y); } else if (Map.Objects[x][y].bomb is IceBomb) { if (!(Map.Objects[x + 1][y].entity is DestructableWall)) { Map.Objects[x + i][y].entity = wallFactory.CreateWall(4); } else { right = true; } } else { DestructionTemplate destroyedObject = Map.Objects[x + i][y].destroy(); if (destroyedObject != null) { destroyedEntities.add(destroyedObject); } } } else { right = true; } if (x - i >= 0 && !(Map.Objects[x - i][y].entity is IndestructableWall) && !(Map.Objects[x - i][y].entity is Fire) && !left) { if (Map.Objects[x][y].bomb is FireBomb) { Map.Objects[x - i][y].entity = new Fire(x - i, y); } else if (Map.Objects[x][y].bomb is IceBomb) { if (!(Map.Objects[x - 1][y].entity is DestructableWall)) { Map.Objects[x - i][y].entity = wallFactory.CreateWall(4); } else { left = true; } } else { DestructionTemplate destroyedObject = Map.Objects[x - i][y].destroy(); if (destroyedObject != null) { destroyedEntities.add(destroyedObject); } } } else { left = true; } if (y + i < numSquaresX && !(Map.Objects[x][y + i].entity is IndestructableWall) && !(Map.Objects[x][y + i].entity is Fire) && !up) { if (Map.Objects[x][y].bomb is FireBomb) { Map.Objects[x][y + i].entity = new Fire(x, y - i); } else if (Map.Objects[x][y].bomb is IceBomb) { if (!(Map.Objects[x][y + i].entity is DestructableWall)) { Map.Objects[x][y + i].entity = wallFactory.CreateWall(4); } else { down = true; } } else { DestructionTemplate destroyedObject = Map.Objects[x][y + i].destroy(); if (destroyedObject != null) { destroyedEntities.add(destroyedObject); } } } else { down = true; } if (y - i >= 0 && !(Map.Objects[x][y - i].entity is IndestructableWall) && !(Map.Objects[x][y - i].entity is Fire) && !down) { if (Map.Objects[x][y].bomb is FireBomb) { Map.Objects[x][y - i].entity = new Fire(x, y - i); } else if (Map.Objects[x][y].bomb is IceBomb) { if (!(Map.Objects[x][y - i].entity is DestructableWall)) { Map.Objects[x][y - i].entity = wallFactory.CreateWall(4); } else { up = true; } } else { DestructionTemplate destroyedObject = Map.Objects[x][y - i].destroy(); if (destroyedObject != null) { destroyedEntities.add(destroyedObject); } } } else { up = true; } } Player player = GetPlayer(Map.Objects[x][y].bomb.playerId); if (player != null) { player.destroyedEntities.add(destroyedEntities); } Map.Objects[x][y].bomb = null; }