cli display

This commit is contained in:
Henri Bourcereau 2024-02-18 18:40:45 +01:00
parent 782a6dce87
commit 68d361b562
5 changed files with 159 additions and 37 deletions

View file

@ -9,5 +9,6 @@ edition = "2021"
anyhow = "1.0.75"
bincode = "1.3.3"
pico-args = "0.5.0"
pretty_assertions = "1.4.0"
renet = "0.0.13"
store = { path = "../store" }

View file

@ -1,3 +1,4 @@
use pretty_assertions::assert_eq;
use store::GameState;
// Application.
@ -33,20 +34,9 @@ impl App {
}
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 ";
// ligne 1 à 8 : positions 24 à 13
// ligne 9 nombre exact
// ligne 10 ---
// lignes 11 à 18 : positions 1 à 12
let mut board = "".to_owned();
board = board + &self.game.board.to_display_grid(9);
board
// self.game.to_string()
}
}
@ -57,30 +47,31 @@ mod tests {
#[test]
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 ";
13 14 15 16 17 18 19 20 21 22 23 24
----------------------------------------------------------------
| | | X |
| | | X |
| | | X |
| | | X |
| | | X |
| | | X |
| | | X |
| | | X |
| | | 15 |
|----------------------------- | | ------------------------------|
| | | 15 |
| | | O |
| | | O |
| | | O |
| | | O |
| | | O |
| | | O |
| | | O |
| | | O |
----------------------------------------------------------------
12 11 10 9 8 7 6 5 4 3 2 1
";
let mut app = App::default();
assert_eq!(app.display(), expected);
self::assert_eq!(app.display(), expected);
}
}