mirror of
https://github.com/szymon-jozef/checkers.git
synced 2026-10-27 19:20:44 +01:00
feat: add moving pawn
This commit is contained in:
@@ -113,7 +113,10 @@ pub struct Board {
|
||||
is_my_turn: bool,
|
||||
|
||||
available_captures: Option<Vec<CapturePath>>,
|
||||
choosen_capture: Option<CapturePath>,
|
||||
|
||||
available_moves: Option<Vec<MovePath>>,
|
||||
choosen_move: Option<MovePath>,
|
||||
|
||||
field_size: f32,
|
||||
}
|
||||
@@ -138,7 +141,10 @@ impl Board {
|
||||
is_my_turn: false,
|
||||
|
||||
available_captures: None,
|
||||
choosen_capture: None,
|
||||
|
||||
available_moves: None,
|
||||
choosen_move: None,
|
||||
|
||||
field_size: 32.0,
|
||||
}
|
||||
@@ -175,6 +181,20 @@ impl Board {
|
||||
}
|
||||
|
||||
self.highlight_move_paths(from);
|
||||
|
||||
if let Some(field) = &self.get_clicked_field() {
|
||||
if let Some(available_moves) = &self.available_moves {
|
||||
if available_moves.iter().any(|available_move| {
|
||||
available_move.from == from
|
||||
&& available_move.available_steps.contains(&field.pos)
|
||||
}) {
|
||||
self.choosen_move = Some(MovePath {
|
||||
from,
|
||||
available_steps: vec![field.pos],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BoardState::ChooseCapture(from) => {
|
||||
@@ -201,6 +221,14 @@ impl Board {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_choosen_capture(&mut self) -> Option<CapturePath> {
|
||||
self.choosen_capture.take()
|
||||
}
|
||||
|
||||
pub fn get_choosen_move(&mut self) -> Option<MovePath> {
|
||||
self.choosen_move.take()
|
||||
}
|
||||
|
||||
pub fn update_board_view(&mut self, board_view: BoardView) {
|
||||
self.board_view = board_view;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user