summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-06-30 22:45:05 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-06-30 22:45:05 +0200
commit11a7896e40da2315df9e46c8b03afb3d6eec94dc (patch)
treeab0df5250c064cc91548ee90b5be8de54a8b7656 /src
parent11457a738e63b5aaae55779fbfdc4978e6524bb1 (diff)
Created data structure for bitwise game engine
Diffstat (limited to 'src')
-rw-r--r--src/engine/bitwise_engine.rs73
-rw-r--r--src/engine/mod.rs4
2 files changed, 75 insertions, 2 deletions
diff --git a/src/engine/bitwise_engine.rs b/src/engine/bitwise_engine.rs
new file mode 100644
index 0000000..79d5120
--- /dev/null
+++ b/src/engine/bitwise_engine.rs
@@ -0,0 +1,73 @@
+use engine::command::{Command, BuildingType};
+use engine::geometry::Point;
+use engine::settings::{GameSettings};
+use engine::{GameStatus, Player, GameState};
+
+const MAP_WIDTH: usize = 16;
+const MAP_HEIGHT: usize = 8;
+
+const MISSILE_COOLDOWN: usize = 3;
+
+const DEFENCE_HEALTH: usize = 4; // '20' health is 4 hits
+
+const MAX_TESLAS: usize = 2;
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct BitwiseGameState {
+ status: GameStatus,
+ player: Player,
+ opponent: Player,
+ player_buildings: PlayerBuildings,
+ opponent_buildings: PlayerBuildings,
+}
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+struct PlayerBuildings {
+ unconstructed: Vec<UnconstructedBuilding>,
+ energy_towers: [u8; MAP_HEIGHT],
+ missile_towers: [[u8; MAP_HEIGHT]; MISSILE_COOLDOWN],
+ defence_towers: [[u8; MAP_HEIGHT]; DEFENCE_HEALTH],
+ tesla_towers: [u8; MAP_HEIGHT],
+
+ missiles: [[u16; MAP_HEIGHT]; MAP_WIDTH/4],
+ tesla_cooldowns: [TeslaCooldown; MAX_TESLAS],
+
+ unoccupied: Vec<Point>
+}
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct UnconstructedBuilding {
+ pub pos: Point,
+ pub construction_time_left: u8,
+ pub building_type: BuildingType
+}
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct TeslaCooldown {
+ pub active: bool,
+ pub pos: Point,
+ pub cooldown: u8
+}
+
+
+impl GameState for BitwiseGameState {
+ fn simulate(&mut self, _settings: &GameSettings, _player_command: Command, _opponent_command: Command) -> GameStatus {
+ //TODO
+ self.status
+ }
+
+
+ fn player(&self) -> &Player { &self.player }
+ fn opponent(&self) -> &Player { &self.opponent }
+ fn player_has_max_teslas(&self) -> bool { self.player_buildings.count_teslas() >= MAX_TESLAS }
+ fn opponent_has_max_teslas(&self) -> bool { self.opponent_buildings.count_teslas() >= MAX_TESLAS }
+ fn unoccupied_player_cells(&self) -> &Vec<Point> { &self.player_buildings.unoccupied }
+ fn unoccupied_opponent_cells(&self) -> &Vec<Point> { &self.opponent_buildings.unoccupied }
+}
+
+impl PlayerBuildings {
+ pub fn count_teslas(&self) -> usize {
+ //TODO
+ 2
+ }
+}
diff --git a/src/engine/mod.rs b/src/engine/mod.rs
index 2910b75..6e7c5c9 100644
--- a/src/engine/mod.rs
+++ b/src/engine/mod.rs
@@ -2,7 +2,7 @@ pub mod command;
pub mod geometry;
pub mod settings;
pub mod expressive_engine;
-
+pub mod bitwise_engine;
use self::command::{Command};
use self::geometry::Point;
@@ -27,7 +27,7 @@ pub enum GameStatus {
Draw
}
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Player {
pub energy: u16,
pub health: u8,