Create a separate Ui struct
This commit is contained in:
@@ -1,19 +1,6 @@
|
|||||||
use std::io::BufRead;
|
|
||||||
mod board;
|
mod board;
|
||||||
mod ui;
|
mod ui;
|
||||||
|
|
||||||
fn main() -> Result<(), ()> {
|
fn main() -> Result<(), ()> {
|
||||||
let mut board = board::Board::new();
|
ui::Ui::new().run()
|
||||||
board.reset();
|
|
||||||
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!("{}", board),
|
|
||||||
_ => break Err(()),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
28
rs/src/ui.rs
28
rs/src/ui.rs
@@ -1,5 +1,6 @@
|
|||||||
use crate::board;
|
use crate::board;
|
||||||
use crate::board::GridAxis;
|
use crate::board::GridAxis;
|
||||||
|
use std::io::BufRead;
|
||||||
|
|
||||||
impl std::fmt::Display for board::Color {
|
impl std::fmt::Display for board::Color {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
@@ -52,3 +53,30 @@ impl std::fmt::Display for board::Board {
|
|||||||
Ok(())
|
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