aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortslil clingman <>2020-01-30 21:45:44 -0800
committertslil clingman <>2020-01-30 21:45:44 -0800
commit10f615418ebc5cf4a12b82bbcb95a74cbde8c339 (patch)
treeb2a52731a037a85012d0d1a8e4c10f570ccb14d5
parent5f2bdc5c15cb5fcd12bff1787a4862c9ab553d95 (diff)
Some minor bugs
-rw-r--r--src/game.rs11
-rw-r--r--src/main.rs8
2 files changed, 14 insertions, 5 deletions
diff --git a/src/game.rs b/src/game.rs
index 4a80ce7..8716111 100644
--- a/src/game.rs
+++ b/src/game.rs
@@ -110,6 +110,7 @@ pub struct Piece {
pub stone: Stone,
}
+#[derive(Clone, Copy)]
pub enum WinType {
RoadWin(Player),
FlatWin(Player),
@@ -675,6 +676,7 @@ pub struct Game {
white_player_name: String,
black_player_name: String,
date_string: String,
+ win_type: Option<WinType>,
}
impl Game {
@@ -701,6 +703,7 @@ impl Game {
white_player_name: white_player_name.to_string(),
black_player_name: black_player_name.to_string(),
date_string: date_str.to_string(),
+ win_type: None,
},
warning,
)
@@ -766,6 +769,9 @@ impl Game {
result.push(line);
}
}
+ if self.win_type.is_some() {
+ result.push(self.win_type.unwrap().to_string());
+ }
result
}
@@ -835,7 +841,8 @@ impl Game {
TurnOrder::BlackPlacesWhite => TurnOrder::Normal,
TurnOrder::Normal => TurnOrder::Normal,
};
- return Ok((pos_vec, self.last_state().check_win()));
+ self.win_type = self.last_state().check_win();
+ return Ok((pos_vec, self.win_type));
}
}
}
@@ -877,7 +884,7 @@ impl fmt::Display for Game {
self.white_player_name,
self.black_player_name,
self.size,
- self.query_action_lines().join("\n")
+ self.query_action_lines().join("\n"),
)
}
}
diff --git a/src/main.rs b/src/main.rs
index 1c9a29a..ec8bc7a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -182,7 +182,6 @@ impl GUI {
GUIResult::Quit => {
self.message_log
.log_message(String::from("Press any key to quit."));
- self.screen.getch();
return false;
}
GUIResult::SwitchElement => match self.input_source {
@@ -236,7 +235,6 @@ impl GUI {
self.message_log.log_error(String::from(
"Error: external and internal game states disagree. Press any key to quit.",
));
- self.screen.getch();
return false;
} else {
self.message_log.log_error(format!(
@@ -250,7 +248,10 @@ impl GUI {
self.board_gui.update(&game, pos_vec);
self.game_log.update(&game);
if let Some(w) = win {
- self.message_log.log_message(format!("{}", w));
+ self.message_log.log_message(format!(
+ "Game over: {}\nPress any key to quit.",
+ w
+ ));
return false;
}
}
@@ -368,6 +369,7 @@ fn main() {
loop {
let inp = gui.query_input(&game, call_proc, p1_white, &engine);
if !gui.handle_input(&mut game, call_proc, p1_white, inp) {
+ gui.screen.getch();
break;
}
}