2024-02-17 12:55:36 +01:00
|
|
|
use store::GameState;
|
|
|
|
|
|
2024-02-09 17:47:34 +01:00
|
|
|
// Application.
|
|
|
|
|
#[derive(Debug, Default)]
|
|
|
|
|
pub struct App {
|
|
|
|
|
// should the application exit?
|
|
|
|
|
pub should_quit: bool,
|
2024-02-17 12:55:36 +01:00
|
|
|
pub game: GameState,
|
2024-02-09 17:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl App {
|
|
|
|
|
// Constructs a new instance of [`App`].
|
|
|
|
|
pub fn new() -> Self {
|
|
|
|
|
Self::default()
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-17 12:55:36 +01:00
|
|
|
// Constructs a new instance of [`App`].
|
|
|
|
|
pub fn start(&mut self) {
|
|
|
|
|
self.game = GameState::new();
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-09 17:47:34 +01:00
|
|
|
pub fn input(&mut self, input: &str) {
|
|
|
|
|
println!("'{}'", input);
|
2024-02-17 12:55:36 +01:00
|
|
|
println!("'{}'", self.display());
|
2024-02-09 17:47:34 +01:00
|
|
|
if input == "quit" {
|
|
|
|
|
self.quit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set running to false to quit the application.
|
|
|
|
|
pub fn quit(&mut self) {
|
|
|
|
|
self.should_quit = true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-17 12:55:36 +01:00
|
|
|
pub fn display(&mut self) -> String {
|
|
|
|
|
let mut board = "
|
|
|
|
|
24 23 22 21 20 19 18 17 16 15 14 13
|
|
|
|
|
-------------------------------------------------------------------"
|
|
|
|
|
.to_owned();
|
|
|
|
|
board = board
|
|
|
|
|
+ "-------------------------------------------------------------------
|
|
|
|
|
1 2 3 4 5 6 7 8 9 10 11 12 ";
|
2024-02-09 17:47:34 +01:00
|
|
|
|
2024-02-17 12:55:36 +01:00
|
|
|
// ligne 1 à 8 : positions 24 à 13
|
|
|
|
|
// ligne 9 nombre exact
|
|
|
|
|
// ligne 10 ---
|
|
|
|
|
// lignes 11 à 18 : positions 1 à 12
|
|
|
|
|
board
|
|
|
|
|
// self.game.to_string()
|
2024-02-09 17:47:34 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
#[test]
|
2024-02-17 12:55:36 +01:00
|
|
|
fn test_display() {
|
|
|
|
|
let expected = "
|
|
|
|
|
24 23 22 21 20 19 18 17 16 15 14 13
|
|
|
|
|
-------------------------------------------------------------------
|
|
|
|
|
| | | X |
|
|
|
|
|
| | | X |
|
|
|
|
|
| | | X |
|
|
|
|
|
| | | X |
|
|
|
|
|
| | | X |
|
|
|
|
|
| | | X |
|
|
|
|
|
| | | X |
|
|
|
|
|
| | | X |
|
|
|
|
|
| | | 15 |
|
|
|
|
|
|------------------------------ | | ------------------------------|
|
|
|
|
|
| | | 15 |
|
|
|
|
|
| | | O |
|
|
|
|
|
| | | O |
|
|
|
|
|
| | | O |
|
|
|
|
|
| | | O |
|
|
|
|
|
| | | O |
|
|
|
|
|
| | | O |
|
|
|
|
|
| | | O |
|
|
|
|
|
| | | O |
|
|
|
|
|
-------------------------------------------------------------------
|
|
|
|
|
1 2 3 4 5 6 7 8 9 10 11 12 ";
|
2024-02-09 17:47:34 +01:00
|
|
|
let mut app = App::default();
|
2024-02-17 12:55:36 +01:00
|
|
|
assert_eq!(app.display(), expected);
|
2024-02-09 17:47:34 +01:00
|
|
|
}
|
|
|
|
|
}
|