convert to tile centricm

This commit is contained in:
Daniel Olsen 2021-01-02 02:25:39 +01:00
parent 68adc43999
commit 21ef5f7c5b
2 changed files with 86 additions and 44 deletions

View File

@ -1,3 +1,5 @@
use std::ops::{Deref, DerefMut};
#[derive(Debug)] #[derive(Debug)]
enum Tile { enum Tile {
Start, Start,
@ -9,59 +11,88 @@ enum Tile {
} }
#[derive(Debug)] #[derive(Debug)]
struct Bag { struct Bag (Vec<Tile>);
blue: u8,
yellow: u8,
red: u8,
black: u8,
teal: u8
}
impl Default for Bag { impl Default for Bag {
fn default() -> Self { fn default() -> Self {
Bag { let mut bag = Vec::<Tile>::with_capacity(100);
blue: 20, for _ in 0..20 {
yellow: 20, bag.push(Tile::Blue);
red: 20, };
black: 20, for _ in 0..20 {
teal: 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<Tile>;
fn deref(&self) -> &Vec<Tile> {
&self.0
}
}
impl DerefMut for Bag {
fn deref_mut(&mut self) -> &mut Vec<Tile> {
&mut self.0
}
}
#[derive(Default, Debug)] #[derive(Default, Debug)]
struct Factory { struct Factory (Vec<Tile>);
blue: u8,
yellow: u8,
red: u8,
black: u8,
teal: u8
}
#[derive(Debug)] impl Deref for Factory {
struct Market { type Target = Vec<Tile>;
start: u8,
blue: u8, fn deref(&self) -> &Vec<Tile> {
yellow: u8, &self.0
red: u8, }
black: u8,
teal: u8
} }
impl Default for Market { impl DerefMut for Factory {
fn default() -> Self { fn deref_mut(&mut self) -> &mut Vec<Tile> {
Market { &mut self.0
start: 1,
blue: 0,
yellow: 0,
red: 0,
black: 0,
teal: 0
}
} }
} }
#[derive(Debug)]
struct Market (Vec<Tile>);
impl Default for Market {
fn default() -> Self {
let mut market = Vec::<Tile>::with_capacity(20);
market.push(Tile::Start);
Market(market)
}
}
impl Deref for Market {
type Target = Vec<Tile>;
fn deref(&self) -> &Vec<Tile> {
&self.0
}
}
impl DerefMut for Market {
fn deref_mut(&mut self) -> &mut Vec<Tile> {
&mut self.0
}
}
#[derive(Debug, Default)] #[derive(Debug, Default)]
struct Patternline (Option<Tile>, u8); struct PatternLine (Option<Tile>, u8);
type Patterns = [Patternline; 5]; type Patterns = [PatternLine; 5];
type Row = [bool; 5]; type Row = [bool; 5];
type Wall = [Row; 5]; type Wall = [Row; 5];
@ -70,7 +101,7 @@ type Wall = [Row; 5];
struct Board { struct Board {
score: u8, score: u8,
wall: Wall, wall: Wall,
floor: Vec<Patternline>, floor: Vec<PatternLine>,
patterns: Patterns, patterns: Patterns,
} }
impl Default for Board { impl Default for Board {
@ -88,6 +119,7 @@ impl Default for Board {
pub struct Game { pub struct Game {
turn: u8, turn: u8,
player: u8, player: u8,
box_top: Bag,
bag: Bag, bag: Bag,
market: Market, market: Market,
factories: Vec<Factory>, factories: Vec<Factory>,
@ -114,6 +146,7 @@ impl Game {
let game = Game { let game = Game {
turn: 0, turn: 0,
player: 0, player: 0,
box_top: Bag::default(),
bag: Bag::default(), bag: Bag::default(),
market: Market::default(), market: Market::default(),
factories: factories, factories: factories,
@ -121,4 +154,13 @@ impl Game {
}; };
Ok(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, )
} }

View File

@ -3,8 +3,8 @@ use azul::Game;
fn main() -> Result<(), &'static str>{ fn main() -> Result<(), &'static str>{
let game = Game::new(2)?; let mut game = Game::new(2)?;
println!("{:#?}", game); println!("{:#?}", game);
game.fill()?;
Ok(()) Ok(())
} }