Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
use std::collections::HashMap;
use rand::prelude::SliceRandom;
use rand::Rng;
use std::collections::HashMap;
use yew::prelude::*;


#[derive(Debug)]
pub struct Symbol {
color: (u8,u8,u8),
color: (u8, u8, u8),
size: &'static str,
stype: &'static str,
}

#[derive(Debug)]
pub struct Stone {
pub color: (u8,u8,u8),
pub color: (u8, u8, u8),
pub radius: usize,
symbols: [Symbol; 3]
symbols: [Symbol; 3],
}

pub struct Board {
pub width: usize,
pub height: usize,
pub samount: usize,
pub stones: HashMap<(usize,usize),Stone>
pub stones: HashMap<(usize, usize), Stone>,
}

impl Symbol {
fn new() -> Symbol {
Symbol {
color: Symbol::random_item(&mut [(0, 255, 255), (255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0)]),
color: Symbol::random_item(&mut [
(0, 255, 255),
(255, 0, 0),
(0, 255, 0),
(0, 0, 255),
(255, 255, 0),
]),
size: Symbol::random_item(&mut ["large", "medium", "small"]),
stype: Symbol::random_item(&mut ["puzzle", "mushroom", "heart", "leaf", "arrow"]),
}
Expand All @@ -41,16 +46,17 @@ impl Symbol {
}

impl Stone {
fn new() -> Stone { // no input required, random placement
fn new() -> Stone {
// no input required, random placement
Stone {
radius: 25, // 50px initially TODO: make this a function of the amount of stones (maybe dependent on players and the size of the board)
symbols: Stone::add_symbols(), // TODO: make sure the sizes, colors, and types are evenly distributed on each stone
color: Symbol::random_item(&mut [(255, 0, 0), (0, 255, 0), (0, 0, 255)]),
}
}

fn add_symbols() -> [Symbol;4] {
let symbols = [Symbol::new(), Symbol::new(), Symbol::new(), Symbol::new()];
fn add_symbols() -> [Symbol; 3] {
let symbols = [Symbol::new(), Symbol::new(), Symbol::new()];
symbols
}
}
Expand All @@ -66,7 +72,7 @@ impl Board {
}

pub fn place_stones(&mut self) {
// Randomly place stones without overlapping
// Randomly place stones without overlapping
let mut rng = rand::thread_rng();

for _ in 0..self.samount {
Expand All @@ -83,5 +89,3 @@ impl Board {
}
}
}