From 1281de10704e5ae71a5150e5d8ee8893f2901f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B8vbr=C3=B8tte=20Olsen?= Date: Sat, 2 Feb 2019 16:06:08 +0100 Subject: [PATCH 1/6] fix comma --- static/state.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/state.json b/static/state.json index 6c4b11b..37f8e42 100644 --- a/static/state.json +++ b/static/state.json @@ -60,7 +60,7 @@ "race_picture": "images/Cybkatte.png", "race_bio": null }, - "color": "#0000FF" + "color": "#0000FF", "tech": { "weapons": { "level": 1, -- 2.44.2 From f813c1681e64ac8664060dedadcaa047e9e2bed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B8vbr=C3=B8tte=20Olsen?= Date: Mon, 6 May 2019 01:28:22 +0200 Subject: [PATCH 2/6] add Default trait to player object --- Player.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Player.rs b/Player.rs index e173fd3..7577942 100644 --- a/Player.rs +++ b/Player.rs @@ -2,14 +2,28 @@ enum Race { Griffin, Catte } +impl Default for Race { + fn default() -> Self { + Race::Catte + } +} struct ResearchItem { levels: u8, points: u16 } +impl Default for ResearchItem { + fn default() -> Self { + ResearchItem{ + levels: 1, + points: 0 + } + } +} +#[derive(Default)] struct Research { - Weapons: ResearchItem + Weapons: ResearchItem, Banking: ResearchItem, Manufactoring: ResearchItem, Terraforming: ResearchItem, @@ -18,9 +32,10 @@ struct Research { Scanning: ResearchItem } +#[derive(Default)] struct Player { Name: String, Color: (u8, u8, u8), Race: Race, - Research -} \ No newline at end of file + Research: Research +} -- 2.44.2 From 164cf5886d27d9847614b74c80c676fccc53e37d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B8vbr=C3=B8tte=20Olsen?= Date: Wed, 8 May 2019 01:36:04 +0200 Subject: [PATCH 3/6] more types --- Player.rs | 41 -------------------------------------- game/carrier.rs | 11 +++++++++++ game/mod.rs | 13 +++++++++++++ game/player.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ game/star.rs | 15 ++++++++++++++ main.rs | 2 ++ 6 files changed, 93 insertions(+), 41 deletions(-) delete mode 100644 Player.rs create mode 100644 game/carrier.rs create mode 100644 game/mod.rs create mode 100644 game/player.rs create mode 100644 game/star.rs diff --git a/Player.rs b/Player.rs deleted file mode 100644 index 7577942..0000000 --- a/Player.rs +++ /dev/null @@ -1,41 +0,0 @@ -enum Race { - Griffin, - Catte -} -impl Default for Race { - fn default() -> Self { - Race::Catte - } -} - -struct ResearchItem { - levels: u8, - points: u16 -} -impl Default for ResearchItem { - fn default() -> Self { - ResearchItem{ - levels: 1, - points: 0 - } - } -} - -#[derive(Default)] -struct Research { - Weapons: ResearchItem, - Banking: ResearchItem, - Manufactoring: ResearchItem, - Terraforming: ResearchItem, - Hyperspace: ResearchItem, - Experimentation: ResearchItem, - Scanning: ResearchItem -} - -#[derive(Default)] -struct Player { - Name: String, - Color: (u8, u8, u8), - Race: Race, - Research: Research -} diff --git a/game/carrier.rs b/game/carrier.rs new file mode 100644 index 0000000..b4cd340 --- /dev/null +++ b/game/carrier.rs @@ -0,0 +1,11 @@ +enum Order { + NOTHING +} + +pub struct Carrier { + OwnerID: u8, + name: String, + ships: u16, + location: (u16, u16), + orders: Vec +} \ No newline at end of file diff --git a/game/mod.rs b/game/mod.rs new file mode 100644 index 0000000..5ee1334 --- /dev/null +++ b/game/mod.rs @@ -0,0 +1,13 @@ +mod player; +mod star; +mod carrier; + +use game::player::Player; +use game::star::Star; +use game::carrier::Carrier; + +struct Game { + players: Vec, + stars: Vec, + carriers: Vec +} \ No newline at end of file diff --git a/game/player.rs b/game/player.rs new file mode 100644 index 0000000..e48aa19 --- /dev/null +++ b/game/player.rs @@ -0,0 +1,52 @@ +enum Race { + Griffin, + Catte +} +impl Default for Race { + fn default() -> Self { + Race::Catte + } +} + +struct ResearchItem { + levels: u8, + points: u16 +} +impl Default for ResearchItem { + fn default() -> Self { + ResearchItem{ + levels: 1, + points: 0 + } + } +} + +#[derive(Default)] +struct Research { + weapons: ResearchItem, + banking: ResearchItem, + manufactoring: ResearchItem, + terraforming: ResearchItem, + hyperspace: ResearchItem, + experimentation: ResearchItem, + scanning: ResearchItem +} + +//#[derive(Default)] +pub struct Player { + name: String, + color: (u8, u8, u8), + race: Race, + research: Research +} +impl Default for Player { + fn default() -> Self { + Player{ + name: String::default(), + //Color: (rand::thread_rng().gen(), rand::thread_rng().gen(), rand::thread_rng().gen()), + color: (0,0,0), + race: Race::default(), + research: Research::default() + } + } +} \ No newline at end of file diff --git a/game/star.rs b/game/star.rs new file mode 100644 index 0000000..23e54fd --- /dev/null +++ b/game/star.rs @@ -0,0 +1,15 @@ +struct Infrastructre { + factory: u16, + lab: u16, + bank: u16 +} + +pub struct Star { + ownerID: Option, + location: (u16, u16), + name: String, + natural_resources: u16, + infrastructre: Infrastructre, + hypergate: bool, + ships: u16 +} \ No newline at end of file diff --git a/main.rs b/main.rs index dbec9c6..7f57396 100644 --- a/main.rs +++ b/main.rs @@ -3,6 +3,8 @@ #[macro_use] extern crate rocket; #[macro_use] extern crate rocket_contrib; +mod game; + use rocket_contrib::serve::StaticFiles; fn main() { -- 2.44.2 From aa56a22f1b990c17d40642c1cda7677295289a65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B8vbr=C3=B8tte=20Olsen?= Date: Wed, 8 May 2019 01:42:58 +0200 Subject: [PATCH 4/6] clean --- Carrier.rs | 21 --------------------- Stars.rs | 13 ------------- game/carrier.rs | 15 ++++++++++++--- game/star.rs | 2 +- 4 files changed, 13 insertions(+), 38 deletions(-) delete mode 100644 Carrier.rs delete mode 100644 Stars.rs diff --git a/Carrier.rs b/Carrier.rs deleted file mode 100644 index e7c23db..0000000 --- a/Carrier.rs +++ /dev/null @@ -1,21 +0,0 @@ -use std::collections::VecDeque; - -enum Action { - NOTHING, - GARRISON(u16), - DROP_ALL, - DROP(u16), - DROP_ALL_BUT(u16), - COLLECT_ALL, - COLLECT(u16), - COLLECT_ALL_BUT(u16), - LOOP -} - -struct Carrier { - ships: u16, - location: &Star - action_queue: VecDeque<(&Star, Action)>, - past_actions: VecDeque<(&Star, Action)>, - owner: &player -} \ No newline at end of file diff --git a/Stars.rs b/Stars.rs deleted file mode 100644 index 626fa6f..0000000 --- a/Stars.rs +++ /dev/null @@ -1,13 +0,0 @@ -struct Star { - resources: u16, - name: String, - ships: u16, - owner: &Player, - infrastructure: Infrastructure -} - -struct Infrastructure { - Fabrication: u8, - Science: u8, - Finance: u8 -} \ No newline at end of file diff --git a/game/carrier.rs b/game/carrier.rs index b4cd340..19e00c5 100644 --- a/game/carrier.rs +++ b/game/carrier.rs @@ -1,11 +1,20 @@ enum Order { - NOTHING + NOTHING, + GARRISON(u16), + DROP_ALL, + DROP(u16), + DROP_ALL_BUT(u16), + COLLECT_ALL, + COLLECT(u16), + COLLECT_ALL_BUT(u16), + LOOP } pub struct Carrier { - OwnerID: u8, + owner: &Player, name: String, ships: u16, location: (u16, u16), - orders: Vec + orders: Vec<(&Star, Order)>, + order_pointer: u8 } \ No newline at end of file diff --git a/game/star.rs b/game/star.rs index 23e54fd..834bb37 100644 --- a/game/star.rs +++ b/game/star.rs @@ -5,7 +5,7 @@ struct Infrastructre { } pub struct Star { - ownerID: Option, + owner: Option<&player>, location: (u16, u16), name: String, natural_resources: u16, -- 2.44.2 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 5/6] 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 -- 2.44.2 From d3d47b0cb378220fae47070839bc3a79d787def5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B8vbr=C3=B8tte=20Olsen?= Date: Thu, 9 May 2019 01:16:43 +0200 Subject: [PATCH 6/6] add another player --- game/mod.rs | 7 +++---- game/player.rs | 15 +++++++++++++-- main.rs | 7 ++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/game/mod.rs b/game/mod.rs index b6d3daa..28a1e92 100644 --- a/game/mod.rs +++ b/game/mod.rs @@ -1,4 +1,4 @@ -mod player; +pub mod player; mod star; mod carrier; @@ -14,9 +14,8 @@ pub struct Game { } impl Game { - pub fn addPlayer(&mut self, name: String) { - let mut player: Player = Player::default(); - player.name = name; + pub fn addPlayer(&mut self, name: String, color: Option<(u8,u8,u8)>, race: Option) { + let player = Player::new(name, color, race); self.players.push(player); } } \ No newline at end of file diff --git a/game/player.rs b/game/player.rs index 10ea7c2..796f3ac 100644 --- a/game/player.rs +++ b/game/player.rs @@ -1,5 +1,5 @@ #[derive(Debug)] -enum Race { +pub enum Race { Griffin, Catte } @@ -36,7 +36,7 @@ struct Research { #[derive(Debug)] pub struct Player { - pub name: String, + name: String, color: (u8, u8, u8), race: Race, research: Research @@ -51,4 +51,15 @@ impl Default for Player { research: Research::default() } } +} + +impl Player { + pub fn new(name: String, color: Option<(u8, u8, u8)>, race: Option) -> Player { + Player { + name: name, + color: color.unwrap_or(Player::default().color), + race: race.unwrap_or(Player::default().race), + research: Research::default() + } + } } \ No newline at end of file diff --git a/main.rs b/main.rs index 935d2d5..955e00c 100644 --- a/main.rs +++ b/main.rs @@ -24,7 +24,8 @@ fn world() -> &'static str { fn test() -> String { let mut game: Game = Game::default(); - game.addPlayer("Daniel".to_string()); - - format!("{:?}", game) + game.addPlayer("Daniel".to_string(), Option::Some((255, 0, 0)), Option::Some(game::player::Race::Catte)); + game.addPlayer("Torpus".to_string(), Option::Some((0, 255, 0)), Option::Some(game::player::Race::Griffin)); + + format!("{:#?}", game) } \ No newline at end of file -- 2.44.2