Skip to content

Commit ee6178b

Browse files
Added a variable that remembers whether the last move was made using a mouse
1 parent d776a95 commit ee6178b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/board.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,14 @@ pub struct Board {
132132
pub is_game_against_bot: bool,
133133
// the display mode
134134
pub display_mode: DisplayMode,
135+
// coordinates of the interactable part of the screen (either normal chess board or promotion screen)
135136
pub top_x: u16,
136137
pub top_y: u16,
138+
// dimension of a selectable cell (either 1 of the 64 cells, or 1 of the 4 promotion options)
137139
pub width: u16,
138140
pub height: u16,
141+
// last move was with a mouse
142+
pub mouse_used: bool,
139143
// if the bot is starting, meaning the player is black
140144
pub is_bot_starting: bool,
141145
// The white piece that got taken
@@ -218,6 +222,7 @@ impl Default for Board {
218222
is_bot_starting: false,
219223
white_taken_pieces: vec![],
220224
black_taken_pieces: vec![],
225+
mouse_used: false,
221226
}
222227
}
223228
}
@@ -248,6 +253,7 @@ impl Board {
248253
is_bot_starting: false,
249254
white_taken_pieces: vec![],
250255
black_taken_pieces: vec![],
256+
mouse_used: false,
251257
}
252258
}
253259

@@ -1006,7 +1012,7 @@ impl Board {
10061012
// - last move cell: green
10071013
// - default cell: white or black
10081014
// Draw the cell blue if this is the current cursor cell
1009-
if i == self.cursor_coordinates.row && j == self.cursor_coordinates.col {
1015+
if i == self.cursor_coordinates.row && j == self.cursor_coordinates.col && self.mouse_used == false {
10101016
Board::render_cell(frame, square, Color::LightBlue, None);
10111017
}
10121018
// Draw the cell magenta if the king is getting checked

src/handler.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
1414
// crossterm on Windows sends Release and Repeat events as well, which we ignore.
1515
return Ok(());
1616
}
17+
app.board.mouse_used = false;
1718
match key_event.code {
1819
// Exit application on `q`
1920
KeyCode::Char('q') => {
@@ -121,6 +122,7 @@ pub fn handle_mouse_events(mouse_event: MouseEvent, app: &mut App) -> AppResult<
121122
if x > 7 || y > 7 {
122123
return Ok(());
123124
}
125+
app.board.mouse_used = true;
124126
let coords: Coord = Coord::new(y as u8, x as u8);
125127

126128
if app.board.selected_coordinates.col == UNDEFINED_POSITION &&

0 commit comments

Comments
 (0)