From d2cbb431a724f3352f76126cbfd156c9055ad869 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B8vbr=C3=B8tte=20Olsen?= Date: Thu, 9 May 2019 00:13:15 +0200 Subject: [PATCH] Basic Game object testing --- game/carrier.rs | 15 ++++++++++++--- game/mod.rs | 17 +++++++++++++---- game/player.rs | 8 +++++--- game/star.rs | 4 +++- main.rs | 12 +++++++++++- 5 files changed, 44 insertions(+), 12 deletions(-) diff --git a/game/carrier.rs b/game/carrier.rs index 19e00c5..cdba79f 100644 --- a/game/carrier.rs +++ b/game/carrier.rs @@ -1,3 +1,4 @@ +#[derive(Debug)] enum Order { NOTHING, GARRISON(u16), @@ -9,12 +10,20 @@ enum Order { COLLECT_ALL_BUT(u16), LOOP } +impl Default for Order { + fn default() -> Self { + Order::NOTHING + } +} +#[derive(Default,Debug)] pub struct Carrier { - owner: &Player, + ownerID: u8, name: String, ships: u16, location: (u16, u16), - orders: Vec<(&Star, Order)>, - order_pointer: u8 + orders: Vec<(u8, Order)>, + completedOrders: Vec<(u8, Order)>, + order_pointer: u8, + repeat: bool } \ No newline at end of file diff --git a/game/mod.rs b/game/mod.rs index 5ee1334..b6d3daa 100644 --- a/game/mod.rs +++ b/game/mod.rs @@ -2,12 +2,21 @@ mod player; mod star; mod carrier; -use game::player::Player; -use game::star::Star; -use game::carrier::Carrier; +use self::player::Player; +use self::star::Star; +use self::carrier::Carrier; -struct Game { +#[derive(Default,Debug)] +pub struct Game { players: Vec, stars: Vec, carriers: Vec +} + +impl Game { + pub fn addPlayer(&mut self, name: String) { + let mut player: Player = Player::default(); + player.name = name; + self.players.push(player); + } } \ No newline at end of file diff --git a/game/player.rs b/game/player.rs index e48aa19..10ea7c2 100644 --- a/game/player.rs +++ b/game/player.rs @@ -1,3 +1,4 @@ +#[derive(Debug)] enum Race { Griffin, Catte @@ -8,6 +9,7 @@ impl Default for Race { } } +#[derive(Debug)] struct ResearchItem { levels: u8, points: u16 @@ -21,7 +23,7 @@ impl Default for ResearchItem { } } -#[derive(Default)] +#[derive(Default,Debug)] struct Research { weapons: ResearchItem, banking: ResearchItem, @@ -32,9 +34,9 @@ struct Research { scanning: ResearchItem } -//#[derive(Default)] +#[derive(Debug)] pub struct Player { - name: String, + pub name: String, color: (u8, u8, u8), race: Race, research: Research diff --git a/game/star.rs b/game/star.rs index 834bb37..7419898 100644 --- a/game/star.rs +++ b/game/star.rs @@ -1,11 +1,13 @@ +#[derive(Default,Debug)] struct Infrastructre { factory: u16, lab: u16, bank: u16 } +#[derive(Default,Debug)] pub struct Star { - owner: Option<&player>, + ownerID: Option, location: (u16, u16), name: String, natural_resources: u16, diff --git a/main.rs b/main.rs index 7f57396..935d2d5 100644 --- a/main.rs +++ b/main.rs @@ -4,12 +4,13 @@ #[macro_use] extern crate rocket_contrib; mod game; +use game::Game; use rocket_contrib::serve::StaticFiles; fn main() { let myrocket = rocket::ignite().mount("/", StaticFiles::from("static")); - let myrocket = myrocket.mount("/api", routes![world]); + let myrocket = myrocket.mount("/api", routes![world,test]); myrocket.launch(); } @@ -17,4 +18,13 @@ fn main() { #[get("/")] fn world() -> &'static str { "Hello, world!" +} + +#[get("/test")] +fn test() -> String { + let mut game: Game = Game::default(); + + game.addPlayer("Daniel".to_string()); + + format!("{:?}", game) } \ No newline at end of file