-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
67 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
use super::game::Game; | ||
use super::player::{Player, PlayerSymbol}; | ||
|
||
use crate::io::input::Input; | ||
|
||
/// Initializes players and starts the game loop | ||
pub fn start() { | ||
pub fn start(input: &dyn Input) { | ||
println!("Welcome to Tic-Tac-Toe!"); | ||
let player_one = Player { | ||
symbol: PlayerSymbol::X, | ||
}; | ||
let player_two = Player { | ||
symbol: PlayerSymbol::O, | ||
}; | ||
Game::new(&player_one).run(&player_one, &player_two); | ||
Game::new(&player_one, input).run(&player_one, &player_two); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
pub trait Input { | ||
fn read(&self) -> std::io::Result<String>; | ||
} | ||
|
||
pub struct StdinInput; | ||
|
||
impl Input for StdinInput { | ||
fn read(&self) -> std::io::Result<String> { | ||
let mut user_input = String::new(); | ||
std::io::stdin().read_line(&mut user_input)?; | ||
Ok(user_input) | ||
} | ||
} | ||
|
||
pub struct MockInput { | ||
pub input: String, | ||
} | ||
|
||
impl Input for MockInput { | ||
fn read(&self) -> std::io::Result<String> { | ||
Ok(self.input.clone()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod input; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
mod game; | ||
mod io; | ||
|
||
fn main() { | ||
game::session::start(); | ||
let input = io::input::StdinInput; | ||
game::session::start(&input); | ||
} |