summaryrefslogtreecommitdiff
path: root/src/game.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/game.rs')
-rw-r--r--src/game.rs47
1 files changed, 29 insertions, 18 deletions
diff --git a/src/game.rs b/src/game.rs
index 626a377..dad72cd 100644
--- a/src/game.rs
+++ b/src/game.rs
@@ -3,42 +3,42 @@ use crate::command::Command;
use crate::json;
pub struct GameBoard {
- players: [Player; 2],
- powerups: Vec<Powerup>,
- map: Map,
+ pub players: [Player; 2],
+ pub powerups: Vec<Powerup>,
+ pub map: Map,
}
-struct Player {
- active_worm: usize,
- worms: Vec<Worm>
+pub struct Player {
+ pub active_worm: usize,
+ pub worms: Vec<Worm>
}
-struct Worm {
- id: i32,
- health: i32,
- position: Point2d<i8>,
- weapon_damage: i32,
- weapon_range: u8
+pub struct Worm {
+ pub id: i32,
+ pub health: i32,
+ pub position: Point2d<i8>,
+ pub weapon_damage: i32,
+ pub weapon_range: u8
}
-enum Powerup {
+pub enum Powerup {
Health(Point2d<i8>, i32)
}
-struct Map {
- size: u8,
+pub struct Map {
+ pub size: u8,
/// This is 2d, each row is size long
- cells: Vec<CellType>
+ pub cells: Vec<CellType>
}
-enum CellType {
+pub enum CellType {
Air,
Dirt,
DeepSpace,
}
-enum SimulationOutcome {
+pub enum SimulationOutcome {
PlayerWon(usize),
Draw,
Continue,
@@ -98,6 +98,17 @@ impl GameBoard {
}
pub fn simulate(&mut self, moves: [Command; 2]) -> SimulationOutcome {
+ for player in &mut self.players {
+ player.active_worm = (player.active_worm + 1) % player.worms.len();
+ }
SimulationOutcome::Continue
}
}
+
+impl Player {
+ pub fn find_worm(&self, id: i32) -> Option<&Worm> {
+ self.worms
+ .iter()
+ .find(|w| w.id == id)
+ }
+}