From 21ef5f7c5b9488b6ba54a0ce538356cf9550a849 Mon Sep 17 00:00:00 2001 From: Daniel Olsen Date: Sat, 2 Jan 2021 02:25:39 +0100 Subject: [PATCH] convert to tile centricm --- src/azul.rs | 126 ++++++++++++++++++++++++++++++++++------------------ src/main.rs | 4 +- 2 files changed, 86 insertions(+), 44 deletions(-) diff --git a/src/azul.rs b/src/azul.rs index 6442765..58d0435 100644 --- a/src/azul.rs +++ b/src/azul.rs @@ -1,3 +1,5 @@ +use std::ops::{Deref, DerefMut}; + #[derive(Debug)] enum Tile { Start, @@ -9,59 +11,88 @@ enum Tile { } #[derive(Debug)] -struct Bag { - blue: u8, - yellow: u8, - red: u8, - black: u8, - teal: u8 -} +struct Bag (Vec); impl Default for Bag { fn default() -> Self { - Bag { - blue: 20, - yellow: 20, - red: 20, - black: 20, - teal: 20 - } + let mut bag = Vec::::with_capacity(100); + for _ in 0..20 { + bag.push(Tile::Blue); + }; + for _ in 0..20 { + bag.push(Tile::Yellow); + }; + for _ in 0..20 { + bag.push(Tile::Red); + }; + for _ in 0..20 { + bag.push(Tile::Black); + }; + for _ in 0..20 { + bag.push(Tile::Teal); + }; + + Bag(bag) } } +impl Deref for Bag { + type Target = Vec; + + fn deref(&self) -> &Vec { + &self.0 + } +} +impl DerefMut for Bag { + fn deref_mut(&mut self) -> &mut Vec { + &mut self.0 + } +} + + #[derive(Default, Debug)] -struct Factory { - blue: u8, - yellow: u8, - red: u8, - black: u8, - teal: u8 -} +struct Factory (Vec); -#[derive(Debug)] -struct Market { - start: u8, - blue: u8, - yellow: u8, - red: u8, - black: u8, - teal: u8 +impl Deref for Factory { + type Target = Vec; + + fn deref(&self) -> &Vec { + &self.0 + } } -impl Default for Market { - fn default() -> Self { - Market { - start: 1, - blue: 0, - yellow: 0, - red: 0, - black: 0, - teal: 0 - } +impl DerefMut for Factory { + fn deref_mut(&mut self) -> &mut Vec { + &mut self.0 } } + +#[derive(Debug)] +struct Market (Vec); + +impl Default for Market { + fn default() -> Self { + let mut market = Vec::::with_capacity(20); + market.push(Tile::Start); + Market(market) + } +} +impl Deref for Market { + type Target = Vec; + + fn deref(&self) -> &Vec { + &self.0 + } +} +impl DerefMut for Market { + fn deref_mut(&mut self) -> &mut Vec { + &mut self.0 + } +} + + #[derive(Debug, Default)] -struct Patternline (Option, u8); -type Patterns = [Patternline; 5]; +struct PatternLine (Option, u8); +type Patterns = [PatternLine; 5]; type Row = [bool; 5]; type Wall = [Row; 5]; @@ -70,7 +101,7 @@ type Wall = [Row; 5]; struct Board { score: u8, wall: Wall, - floor: Vec, + floor: Vec, patterns: Patterns, } impl Default for Board { @@ -88,6 +119,7 @@ impl Default for Board { pub struct Game { turn: u8, player: u8, + box_top: Bag, bag: Bag, market: Market, factories: Vec, @@ -114,6 +146,7 @@ impl Game { let game = Game { turn: 0, player: 0, + box_top: Bag::default(), bag: Bag::default(), market: Market::default(), factories: factories, @@ -121,4 +154,13 @@ impl Game { }; Ok(game) } + pub fn fill(&mut self) -> Result<(), &'static str> { + for factory in &self.factories { + if factory.len() != 0 { + return Err("Cannot fill, factories are not empty") + }; + }; + Ok(()) + } + // pub fn shop(&mut self, ) } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 3d16769..287d771 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,8 +3,8 @@ use azul::Game; fn main() -> Result<(), &'static str>{ - let game = Game::new(2)?; + let mut game = Game::new(2)?; println!("{:#?}", game); - + game.fill()?; Ok(()) }