start with some structure of the game

This commit is contained in:
Daniel Olsen 2021-01-01 23:07:16 +01:00
parent 09233e1e99
commit 341fa3f2f2
3 changed files with 130 additions and 1 deletions

5
Cargo.lock generated Normal file
View File

@ -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"

119
src/azul.rs Normal file
View File

@ -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<Tile>, 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<Factory>,
boards: Vec<Board>
}
impl Game {
pub fn new(players: usize) -> Result<Self, &'static str> {
let n_factories = match players {
2 => 5,
3 => 7,
4 => 9,
_ => return Err("Not a valid amount of players")
};
let mut factories = Vec::<Factory>::with_capacity(n_factories);
for _ in 0..n_factories {
factories.push(Factory::default())
}
let mut boards = Vec::<Board>::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)
}
}

View File

@ -1,3 +1,8 @@
mod azul;
use azul::Game;
fn main() {
println!("Hello, world!");
let game = Game::new(2);
println!("{:#?}", game);
}