summaryrefslogtreecommitdiff
path: root/src/engine
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-07-01 22:39:44 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-07-01 22:39:44 +0200
commit99378ed484b04c710e0307db93ada65b29d93bae (patch)
tree860636d6e7be6bf5208f2f865a68e1289bd8272a /src/engine
parent709bd0b9be0eeed4ad204c121fcadef505d5336d (diff)
Started filling in bitwise simulation logic
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/bitwise_engine.rs31
1 files changed, 28 insertions, 3 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 {