feat: add moving pawn

This commit is contained in:
2026-08-30 13:56:31 +02:00
parent 913262276b
commit 5326f787ad
2 changed files with 49 additions and 5 deletions

View File

@@ -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;
}

View File

@@ -14,7 +14,10 @@ use macroquad::{
use tokio::sync::mpsc::{Receiver, error::TryRecvError::Disconnected};
use crate::{
logic::board::board_view::BoardView,
logic::board::{
board_view::BoardView,
pawn::{CapturePath, MovePath},
},
network::{
client::Client, message::ServerMessage, network_identity::NetworkIdentity,
server::ServerStage,
@@ -60,8 +63,8 @@ pub enum GuiCommands {
Ready,
Unready,
Capture,
Move,
Capture(CapturePath),
Move(MovePath),
}
impl GameClient {
@@ -90,8 +93,13 @@ impl GameClient {
GuiCommands::Unready => {
client.revoke_readiness().await;
}
GuiCommands::Capture => todo!(),
GuiCommands::Move => todo!(),
GuiCommands::Capture(capture_path) => todo!(),
GuiCommands::Move(move_path) => {
client
.send_move(move_path.from, move_path.available_steps[0])
.await; // ugly
}
},
None => {
@@ -229,6 +237,14 @@ impl GameClient {
_ => {}
}
}
if let Some(capture_path) = self.board.get_choosen_capture() {
let _ = self.cmd_sender.try_send(GuiCommands::Capture(capture_path));
}
if let Some(move_path) = self.board.get_choosen_move() {
let _ = self.cmd_sender.try_send(GuiCommands::Move(move_path));
}
}
fn update_network(&mut self) {