feat(game): implement Display trait for MankallaGame
This commit is contained in:
1 parent
66d2c612ea
commit
f235c57a7c
1 file changed
+25
@@ -1,3 +1,5 @@
|
|||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
pub struct MankallaGame {
|
pub struct MankallaGame {
|
||||||
// 13 12 11 10 9 8 7
|
// 13 12 11 10 9 8 7
|
||||||
// 0 1 2 3 4 5 6
|
// 0 1 2 3 4 5 6
|
||||||
@@ -12,6 +14,29 @@ pub enum Player {
|
|||||||
Player2,
|
Player2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for MankallaGame {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
let mut result: String = "".to_owned();
|
||||||
|
result.push_str(
|
||||||
|
self.fields[7..14]
|
||||||
|
.iter()
|
||||||
|
.rev()
|
||||||
|
.map(|field| format!("{:>2}", field))
|
||||||
|
.collect::<String>()
|
||||||
|
.as_str(),
|
||||||
|
);
|
||||||
|
result.push_str("\n ");
|
||||||
|
result.push_str(
|
||||||
|
self.fields[..7]
|
||||||
|
.iter()
|
||||||
|
.map(|field| format!("{:>2}", field))
|
||||||
|
.collect::<String>()
|
||||||
|
.as_str(),
|
||||||
|
);
|
||||||
|
write!(f, "{}", result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for MankallaGame {
|
impl Default for MankallaGame {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
MankallaGame {
|
MankallaGame {
|
||||||
|
|||||||
Reference in new issue
Block a user