Create a separate Ui struct
This commit is contained in:
28
rs/src/ui.rs
28
rs/src/ui.rs
@@ -1,5 +1,6 @@
|
||||
use crate::board;
|
||||
use crate::board::GridAxis;
|
||||
use std::io::BufRead;
|
||||
|
||||
impl std::fmt::Display for board::Color {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
@@ -52,3 +53,30 @@ impl std::fmt::Display for board::Board {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Ui {
|
||||
board: board::Board,
|
||||
}
|
||||
|
||||
impl Ui {
|
||||
pub fn new() -> Self {
|
||||
let mut board = board::Board::new();
|
||||
board.reset();
|
||||
Ui {
|
||||
board,
|
||||
}
|
||||
}
|
||||
pub fn run(&mut self) -> Result<(), ()> {
|
||||
let stdin = std::io::stdin();
|
||||
let mut input_lines = stdin.lock().lines();
|
||||
loop {
|
||||
match input_lines.next() {
|
||||
None => break Ok(()),
|
||||
Some(line) => match &line.unwrap()[..] {
|
||||
"get_state" => println!("{}", self.board),
|
||||
_ => break Err(()),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user