diff options
-rw-r--r-- | src/engine/bitwise_engine.rs | 31 | ||||
-rw-r--r-- | src/input/json.rs | 13 |
2 files changed, 29 insertions, 15 deletions
diff --git a/src/engine/bitwise_engine.rs b/src/engine/bitwise_engine.rs index 04e4f85..7e02cde 100644 --- a/src/engine/bitwise_engine.rs +++ b/src/engine/bitwise_engine.rs @@ -4,7 +4,6 @@ use engine::settings::{GameSettings}; use engine::{GameStatus, Player, GameState}; const MAP_WIDTH: usize = 16; -const MAP_HEIGHT: usize = 8; const MISSILE_COOLDOWN: usize = 3; @@ -51,8 +50,17 @@ pub struct TeslaCooldown { const EMPTY: [Point; 0] = []; impl GameState for BitwiseGameState { - fn simulate(&mut self, _settings: &GameSettings, _player_command: Command, _opponent_command: Command) -> GameStatus { - //TODO + fn simulate(&mut self, settings: &GameSettings, _player_command: Command, _opponent_command: Command) -> GameStatus { + //TODO: Commands + //TODO: Make buildings out of under construction buildings + //TODO: Fire the TESLAS! + //TODO: Put missiles on the map + //TODO: Move and collide missiles + + BitwiseGameState::add_energy(settings, &mut self.player, &mut self.player_buildings); + BitwiseGameState::add_energy(settings, &mut self.opponent, &mut self.opponent_buildings); + + self.update_status(); self.status } @@ -76,6 +84,23 @@ impl BitwiseGameState { player_buildings, opponent_buildings } } + + fn add_energy(settings: &GameSettings, player: &mut Player, player_buildings: &mut PlayerBuildings) { + player.energy_generated = player_buildings.energy_towers.count_ones() as u16 * settings.energy.energy_generated_per_turn; + player.energy += player.energy_generated; + } + + fn update_status(&mut self) { + let player_dead = self.player.health == 0; + let opponent_dead = self.opponent.health == 0; + self.status = match (player_dead, opponent_dead) { + (true, true) => GameStatus::Draw, + (false, true) => GameStatus::PlayerWon, + (true, false) => GameStatus::OpponentWon, + (false, false) => GameStatus::Continue, + }; + } + } impl PlayerBuildings { diff --git a/src/input/json.rs b/src/input/json.rs index b509926..13f0b5e 100644 --- a/src/input/json.rs +++ b/src/input/json.rs @@ -244,18 +244,7 @@ impl State { ) .collect() } - - fn unconstructed_buildings_to_bitwise_engine(&self, player_type: char) -> Vec<bitwise_engine::UnconstructedBuilding> { - self.game_map.iter() - .flat_map(|row| row.iter() - .flat_map(|cell| cell.buildings.iter() - .filter(|b| b.player_type == player_type && b.construction_time_left >= 0) - .map(|b| b.to_bitwise_engine_unconstructed()) - ) - ) - .collect() - } - + fn buildings_to_expressive_engine(&self, player_type: char) -> Vec<expressive_engine::Building> { self.game_map.iter() .flat_map(|row| row.iter() |