From 341fa3f2f22a6638c04455d74ee76ab727c3bcba Mon Sep 17 00:00:00 2001 From: Daniel Olsen Date: Fri, 1 Jan 2021 23:07:16 +0100 Subject: [PATCH] start with some structure of the game --- Cargo.lock | 5 +++ src/azul.rs | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 7 +++- 3 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 Cargo.lock create mode 100644 src/azul.rs diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..67a6654 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "Mercury" +version = "0.1.0" diff --git a/src/azul.rs b/src/azul.rs new file mode 100644 index 0000000..b35df32 --- /dev/null +++ b/src/azul.rs @@ -0,0 +1,119 @@ +#[derive(Debug)] +enum Tile { + Blue, + Yellow, + Red, + Black, + Teal +} + +#[derive(Debug)] +struct Bag { + blue: u8, + yellow: u8, + red: u8, + black: u8, + teal: u8 +} +impl Default for Bag { + fn default() -> Self { + Bag { + blue: 20, + yellow: 20, + red: 20, + black: 20, + teal: 20 + } + } +} + +#[derive(Default, Debug)] +struct Factory { + blue: u8, + yellow: u8, + red: u8, + black: u8, + teal: u8 +} + +#[derive(Debug)] +struct Market { + start: u8, + blue: u8, + yellow: u8, + red: u8, + black: u8, + teal: u8 +} +impl Default for Market { + fn default() -> Self { + Market { + start: 1, + blue: 0, + yellow: 0, + red: 0, + black: 0, + teal: 0 + } + } +} + +#[derive(Debug, Default)] +struct Patternline (Option, u8); +type Patterns = [Patternline; 5]; + +type Row = [bool; 5]; +type Wall = [Row; 5]; + +#[derive(Debug)] +struct Board { + score: u8, + wall: Wall, + floor: u8, + patterns: Patterns, +} +impl Default for Board { + fn default() -> Self { + Board { + score: 0, + wall: Wall::default(), + floor: 0, + patterns: Patterns::default() + } + } +} + +#[derive(Default, Debug)] +pub struct Game { + bag: Bag, + market: Market, + factories: Vec, + boards: Vec +} +impl Game { + pub fn new(players: usize) -> Result { + let n_factories = match players { + 2 => 5, + 3 => 7, + 4 => 9, + _ => return Err("Not a valid amount of players") + }; + let mut factories = Vec::::with_capacity(n_factories); + for _ in 0..n_factories { + factories.push(Factory::default()) + } + + let mut boards = Vec::::with_capacity(players); + for _ in 0..players { + boards.push(Board::default()); + } + + let game = Game { + bag: Bag::default(), + market: Market::default(), + factories: factories, + boards: boards + }; + Ok(game) + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e7a11a9..6fa60f2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,8 @@ +mod azul; +use azul::Game; + fn main() { - println!("Hello, world!"); + + let game = Game::new(2); + println!("{:#?}", game); }