mirror of
https://github.com/szymon-jozef/checkers.git
synced 2026-10-27 19:20:44 +01:00
feat: add moving and capturing to server
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use log::{error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
net::{IpAddr, Ipv4Addr, SocketAddr},
|
net::{IpAddr, Ipv4Addr, SocketAddr},
|
||||||
@@ -9,7 +9,7 @@ use tokio::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
logic::game_master::GameMaster,
|
logic::{board::pawn::CapturePath, game_master::GameMaster, math::position::Position},
|
||||||
network::{
|
network::{
|
||||||
connection::{Connection, ConnectionType},
|
connection::{Connection, ConnectionType},
|
||||||
message::{
|
message::{
|
||||||
@@ -195,12 +195,12 @@ impl Server {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
ClientMessage::RequestCapture { capture_path: _ } => {
|
ClientMessage::RequestCapture { capture_path } => {
|
||||||
self.process_capture();
|
self.process_capture(capture_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientMessage::RequestMove { from: _, to: _ } => {
|
ClientMessage::RequestMove { from, to } => {
|
||||||
self.process_move();
|
self.process_move(from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientMessage::TextMessage (content) => {
|
ClientMessage::TextMessage (content) => {
|
||||||
@@ -223,12 +223,24 @@ impl Server {
|
|||||||
// TODO! Do something with this name i guess
|
// TODO! Do something with this name i guess
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_capture(&self) {
|
fn process_capture(&mut self, capture_path: CapturePath) {
|
||||||
todo!();
|
if let Some(gm) = self.game_master.as_mut() {
|
||||||
|
if gm.capture(&capture_path) {
|
||||||
|
debug!("Capture valid!");
|
||||||
|
} else {
|
||||||
|
debug!("Invalid capture!");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_move(&self) {
|
fn process_move(&mut self, from: Position, to: Position) {
|
||||||
todo!();
|
if let Some(gm) = self.game_master.as_mut() {
|
||||||
|
if gm.move_pawn(from, to) {
|
||||||
|
debug!("Move was valid!");
|
||||||
|
} else {
|
||||||
|
debug!("Move was invalid!");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn request_handshake(&mut self, addr: SocketAddr) {
|
async fn request_handshake(&mut self, addr: SocketAddr) {
|
||||||
|
|||||||
Reference in New Issue
Block a user