|
|
|
@ -134,6 +134,13 @@ impl Room {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ClientMessage::TileTake(pos) => {
|
|
|
|
|
if let Some(p) = self.connections.get(&addr) {
|
|
|
|
|
if *p == self.active_player {
|
|
|
|
|
self.on_tile_take(pos.into());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ClientMessage::Validate => {
|
|
|
|
|
if let Some(p) = self.connections.get(&addr) {
|
|
|
|
|
if *p == self.active_player {
|
|
|
|
@ -141,7 +148,6 @@ impl Room {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => todo!(),
|
|
|
|
|
}
|
|
|
|
|
!self.connections.is_empty()
|
|
|
|
|
}
|
|
|
|
@ -185,6 +191,19 @@ impl Room {
|
|
|
|
|
self.broadcast(ServerMessage::TilePlaced(pos.into(), tile.into()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn on_tile_take(&mut self, pos: Position2d) {
|
|
|
|
|
if self.board.get(pos.x, pos.y) == self.validated_board.get(pos.x, pos.y) {
|
|
|
|
|
self.send(
|
|
|
|
|
self.active_player,
|
|
|
|
|
ServerMessage::TurnRejected("Cannot take already validated tile.".to_string()),
|
|
|
|
|
);
|
|
|
|
|
} else if let Some(tile) = self.board.take(pos.x, pos.y) {
|
|
|
|
|
self.players[self.active_player].hand.push(tile);
|
|
|
|
|
self.sync_hand(self.active_player);
|
|
|
|
|
self.broadcast(ServerMessage::TileRemoved(pos.into()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn on_validate(&mut self) {
|
|
|
|
|
let diff = self.board.difference(&self.validated_board);
|
|
|
|
|
if diff.is_empty() {
|
|
|
|
|