rendu textuel closes #4
This commit is contained in:
parent
2139de2fcd
commit
50a4038aa6
|
|
@ -1,6 +1,9 @@
|
||||||
use bot::Bot;
|
use bot::Bot;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use store::{CheckerMove, Color, Dice, DiceRoller, GameEvent, GameState, PlayerId, TurnStage};
|
use std::fmt;
|
||||||
|
use store::{
|
||||||
|
CheckerMove, Color, Dice, DiceRoller, GameEvent, GameState, PlayerId, Stage, TurnStage,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct AppArgs {
|
pub struct AppArgs {
|
||||||
|
|
@ -167,18 +170,34 @@ impl App {
|
||||||
|
|
||||||
pub fn display(&mut self) -> String {
|
pub fn display(&mut self) -> String {
|
||||||
let mut output = "-------------------------------".to_owned();
|
let mut output = "-------------------------------".to_owned();
|
||||||
output = output
|
output += format!(
|
||||||
+ "\nWaiting for player "
|
"\n{:?} > {} > {:?}",
|
||||||
+ &self
|
self.game.state.stage,
|
||||||
.game
|
self.game
|
||||||
.state
|
.state
|
||||||
.who_plays()
|
.who_plays()
|
||||||
.map(|pl| &pl.name)
|
.map(|pl| &pl.name)
|
||||||
.unwrap_or(&"?".to_owned());
|
.unwrap_or(&"?".to_owned()),
|
||||||
|
self.game.state.turn_stage
|
||||||
|
)
|
||||||
|
.as_str();
|
||||||
|
|
||||||
output = output + "\nRolled dice : " + &self.game.state.dice.to_display_string();
|
output = output + "\nRolled dice : " + &self.game.state.dice.to_display_string();
|
||||||
output = output + "\n-------------------------------";
|
|
||||||
output = output + "\n" + &self.game.state.board.to_display_grid(9);
|
if self.game.state.stage != Stage::PreGame {
|
||||||
|
// display players points
|
||||||
|
output += format!("\n\n{:<11} :: {:<5} :: {}", "Player", "holes", "points").as_str();
|
||||||
|
for (player_id, player) in self.game.state.players.iter() {
|
||||||
|
output += format!(
|
||||||
|
"\n{}. {:<8} :: {:<5} :: {}",
|
||||||
|
&player_id, &player.name, &player.holes, &player.points
|
||||||
|
)
|
||||||
|
.as_str();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output += "\n-------------------------------\n";
|
||||||
|
output += &self.game.state.board.to_display_grid(9);
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -190,7 +209,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_display() {
|
fn test_display() {
|
||||||
let expected = "-------------------------------
|
let expected = "-------------------------------
|
||||||
Waiting for player ?
|
PreGame > ? > RollDice
|
||||||
Rolled dice : 0 & 0
|
Rolled dice : 0 & 0
|
||||||
-------------------------------
|
-------------------------------
|
||||||
|
|
||||||
|
|
@ -225,8 +244,12 @@ Rolled dice : 0 & 0
|
||||||
#[test]
|
#[test]
|
||||||
fn test_move() {
|
fn test_move() {
|
||||||
let expected = "-------------------------------
|
let expected = "-------------------------------
|
||||||
Waiting for player myself
|
InGame > myself > RollDice
|
||||||
Rolled dice : 4 & 6
|
Rolled dice : 4 & 6
|
||||||
|
|
||||||
|
Player :: holes :: points
|
||||||
|
1. myself :: 0 :: 0
|
||||||
|
2. bot :: 0 :: 0
|
||||||
-------------------------------
|
-------------------------------
|
||||||
|
|
||||||
13 14 15 16 17 18 19 20 21 22 23 24
|
13 14 15 16 17 18 19 20 21 22 23 24
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use crate::player::{Color, Player, PlayerId};
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
// use itertools::Itertools;
|
// use itertools::Itertools;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
@ -49,6 +50,10 @@ pub struct GameState {
|
||||||
impl fmt::Display for GameState {
|
impl fmt::Display for GameState {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
|
s.push_str(&format!(
|
||||||
|
"Stage: {:?} / {:?}\n",
|
||||||
|
self.stage, self.turn_stage
|
||||||
|
));
|
||||||
s.push_str(&format!("Dice: {:?}\n", self.dice));
|
s.push_str(&format!("Dice: {:?}\n", self.dice));
|
||||||
// s.push_str(&format!("Who plays: {}\n", self.who_plays().map(|player| &player.name ).unwrap_or("")));
|
// s.push_str(&format!("Who plays: {}\n", self.who_plays().map(|player| &player.name ).unwrap_or("")));
|
||||||
s.push_str(&format!("Board: {:?}\n", self.board));
|
s.push_str(&format!("Board: {:?}\n", self.board));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue