Skip to content
Snippets Groups Projects
Commit b603c6b8 authored by pumapaul's avatar pumapaul
Browse files

Fix issue where too few enemies were placed on the board

parent 647d4594
No related branches found
No related tags found
No related merge requests found
...@@ -71,7 +71,7 @@ impl Level { ...@@ -71,7 +71,7 @@ impl Level {
fn add_enemies(enemy_count: usize, board: Board) -> Board { fn add_enemies(enemy_count: usize, board: Board) -> Board {
let mut result = board.clone(); let mut result = board.clone();
for index in 0..enemy_count - 1 { for index in 0..enemy_count {
result = Level::add_entity(Tile::Enemy(index), result); result = Level::add_entity(Tile::Enemy(index), result);
} }
...@@ -80,13 +80,12 @@ impl Level { ...@@ -80,13 +80,12 @@ impl Level {
fn add_entity(entity: Tile, board: Board) -> Board { fn add_entity(entity: Tile, board: Board) -> Board {
let empty_count = Level::count_empty_tiles(board); let empty_count = Level::count_empty_tiles(board);
let player_position = thread_rng().gen_range(0, empty_count); let entity_position = thread_rng().gen_range(0, empty_count);
let player_x = player_position / config::BOARD_HEIGHT; let entity_x = entity_position / config::BOARD_HEIGHT;
let player_y = player_position % config::BOARD_HEIGHT; let entity_y = entity_position % config::BOARD_HEIGHT;
let mut board = board.clone(); let mut board = board.clone();
board[player_x][player_y] = entity; board[entity_x][entity_y] = entity;
board board
} }
......
#[derive(Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub enum Tile { pub enum Tile {
Enemy(usize), Enemy(usize),
Exit, Exit,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment