Allow joining an existing room and validating tile placement
This commit is contained in:
@@ -35,12 +35,20 @@ impl Hand {
|
||||
pub fn complete(&mut self, deck: &mut RngDeck) -> Result<(), EmptyDeckError> {
|
||||
for _ in 0..self.count_missing_operators() {
|
||||
self.tiles
|
||||
.push(Tile::Operator(deck.rand_operator().ok_or(())?));
|
||||
.push(Tile::Operator(deck.rand_operator().ok_or(EmptyDeckError.into())?));
|
||||
}
|
||||
for _ in 0..self.count_missing_numbers() {
|
||||
self.tiles
|
||||
.push(Tile::Digit(Digit::new(deck.rand_digit().ok_or(())?)));
|
||||
.push(Tile::Digit(Digit::new(deck.rand_digit().ok_or(EmptyDeckError.into())?)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn remove(&mut self, idx: usize) -> Option<Tile> {
|
||||
if idx < self.tiles.len() {
|
||||
Some(self.tiles.remove(idx))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user