Improve formatting setup.

Add concept of games.
This commit is contained in:
Dorian 2019-03-02 16:44:29 -05:00
parent c1608bacd1
commit 04d6837b5e
1 changed files with 24 additions and 8 deletions

View File

@ -19,7 +19,7 @@ pub enum BoardSize {
} }
impl BoardSize { impl BoardSize {
fn get_size(&self) -> u32 { fn get_size(&self) -> usize {
match &self { match &self {
BoardSize::American => 8, BoardSize::American => 8,
BoardSize::International => 10, BoardSize::International => 10,
@ -60,7 +60,7 @@ impl Board {
} }
} }
fn get_index(&self, row: u32, column: u32) -> usize { fn get_index(&self, row: usize, column: usize) -> usize {
let width = self.dimensions.get_size(); let width = self.dimensions.get_size();
(row * (width / 2) + column) as usize (row * (width / 2) + column) as usize
} }
@ -74,11 +74,8 @@ impl fmt::Display for Board {
let width = self.dimensions.get_size(); let width = self.dimensions.get_size();
// Create the top level border. // Create the top level border.
let mut column_border_chars = COLUMN_COORDINATE_BORDER.chars(); let (column_border_chars, _) = COLUMN_COORDINATE_BORDER.split_at(width + 1);
for _ in 0..width + 1 { writeln!(formatter, "{}", column_border_chars)?;
write!(formatter, "{}", column_border_chars.next().unwrap())?;
}
write!(formatter, "\n")?;
for row in 0..width { for row in 0..width {
@ -115,6 +112,25 @@ impl fmt::Display for Board {
} }
} }
pub enum GameState {
LightPlayerTurn,
DarkPlayerTurn,
LightPlayerWin,
DarkPlayerWin,
DrawGame,
}
pub struct Player {
name: String,
}
pub struct Game {
board: Board,
light_player: Player,
dark_player: Player,
state: GameState,
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {