pub struct GameSetting<'a> { /* private fields */ }Expand description
Game process builder, providing control over how a new process should be spawned.
Like std::process::Command, A default configuration can be
generated using Gamesetting::new(command name) and other settings
can be added by builder methods.
§Example
extern crate curses_game_wrapper as cgw;
use cgw::{Reactor, ActionResult, AsciiChar, GameSetting, Severity};
use std::time::Duration;
fn main() {
let loopnum = 50;
let gs = GameSetting::new("rogue")
.env("ROGUEUSER", "EmptyAI")
.lines(24)
.columns(80)
.debug_file("debug.txt")
.max_loop(loopnum + 1)
.draw_on(Duration::from_millis(200));
let game = gs.build();
}Implementations§
Source§impl<'a> GameSetting<'a>
impl<'a> GameSetting<'a>
Sourcepub fn new(command_name: &str) -> Self
pub fn new(command_name: &str) -> Self
Build GameSetting object with command name(like rogue).
Examples found in repository?
4fn main() {
5 struct EmptyAI {
6 loopnum: usize,
7 };
8 impl Reactor for EmptyAI {
9 fn action(&mut self, _screen: ActionResult, turn: usize) -> Option<Vec<u8>> {
10 let mut res = Vec::new();
11 match turn {
12 val if val == self.loopnum - 1 => res.push(AsciiChar::CarriageReturn.as_byte()),
13 val if val == self.loopnum - 2 => res.push(b'y'),
14 val if val == self.loopnum - 3 => res.push(b'Q'),
15 _ => {
16 let c = match (turn % 4) as u8 {
17 0u8 => b'h',
18 1u8 => b'j',
19 2u8 => b'k',
20 _ => b'l',
21 };
22 res.push(c);
23 }
24 };
25 Some(res)
26 }
27 }
28 let loopnum = 50;
29 let gs = GameSetting::new("rogue")
30 .env("ROGUEUSER", "EmptyAI")
31 .lines(24)
32 .columns(80)
33 .debug_file("debug.txt")
34 .max_loop(loopnum + 1)
35 .draw_on(Duration::from_millis(100));
36 let game = gs.build();
37 let mut ai = EmptyAI { loopnum: loopnum };
38 game.play(&mut ai);
39}Sourcepub fn columns(self, u: usize) -> Self
pub fn columns(self, u: usize) -> Self
Set screen width of curses widow
Examples found in repository?
4fn main() {
5 struct EmptyAI {
6 loopnum: usize,
7 };
8 impl Reactor for EmptyAI {
9 fn action(&mut self, _screen: ActionResult, turn: usize) -> Option<Vec<u8>> {
10 let mut res = Vec::new();
11 match turn {
12 val if val == self.loopnum - 1 => res.push(AsciiChar::CarriageReturn.as_byte()),
13 val if val == self.loopnum - 2 => res.push(b'y'),
14 val if val == self.loopnum - 3 => res.push(b'Q'),
15 _ => {
16 let c = match (turn % 4) as u8 {
17 0u8 => b'h',
18 1u8 => b'j',
19 2u8 => b'k',
20 _ => b'l',
21 };
22 res.push(c);
23 }
24 };
25 Some(res)
26 }
27 }
28 let loopnum = 50;
29 let gs = GameSetting::new("rogue")
30 .env("ROGUEUSER", "EmptyAI")
31 .lines(24)
32 .columns(80)
33 .debug_file("debug.txt")
34 .max_loop(loopnum + 1)
35 .draw_on(Duration::from_millis(100));
36 let game = gs.build();
37 let mut ai = EmptyAI { loopnum: loopnum };
38 game.play(&mut ai);
39}Sourcepub fn lines(self, u: usize) -> Self
pub fn lines(self, u: usize) -> Self
Set screen height of curses window
Examples found in repository?
4fn main() {
5 struct EmptyAI {
6 loopnum: usize,
7 };
8 impl Reactor for EmptyAI {
9 fn action(&mut self, _screen: ActionResult, turn: usize) -> Option<Vec<u8>> {
10 let mut res = Vec::new();
11 match turn {
12 val if val == self.loopnum - 1 => res.push(AsciiChar::CarriageReturn.as_byte()),
13 val if val == self.loopnum - 2 => res.push(b'y'),
14 val if val == self.loopnum - 3 => res.push(b'Q'),
15 _ => {
16 let c = match (turn % 4) as u8 {
17 0u8 => b'h',
18 1u8 => b'j',
19 2u8 => b'k',
20 _ => b'l',
21 };
22 res.push(c);
23 }
24 };
25 Some(res)
26 }
27 }
28 let loopnum = 50;
29 let gs = GameSetting::new("rogue")
30 .env("ROGUEUSER", "EmptyAI")
31 .lines(24)
32 .columns(80)
33 .debug_file("debug.txt")
34 .max_loop(loopnum + 1)
35 .draw_on(Duration::from_millis(100));
36 let game = gs.build();
37 let mut ai = EmptyAI { loopnum: loopnum };
38 game.play(&mut ai);
39}Sourcepub fn env(self, s: &'a str, t: &'a str) -> Self
pub fn env(self, s: &'a str, t: &'a str) -> Self
Set environmental variable
Examples found in repository?
4fn main() {
5 struct EmptyAI {
6 loopnum: usize,
7 };
8 impl Reactor for EmptyAI {
9 fn action(&mut self, _screen: ActionResult, turn: usize) -> Option<Vec<u8>> {
10 let mut res = Vec::new();
11 match turn {
12 val if val == self.loopnum - 1 => res.push(AsciiChar::CarriageReturn.as_byte()),
13 val if val == self.loopnum - 2 => res.push(b'y'),
14 val if val == self.loopnum - 3 => res.push(b'Q'),
15 _ => {
16 let c = match (turn % 4) as u8 {
17 0u8 => b'h',
18 1u8 => b'j',
19 2u8 => b'k',
20 _ => b'l',
21 };
22 res.push(c);
23 }
24 };
25 Some(res)
26 }
27 }
28 let loopnum = 50;
29 let gs = GameSetting::new("rogue")
30 .env("ROGUEUSER", "EmptyAI")
31 .lines(24)
32 .columns(80)
33 .debug_file("debug.txt")
34 .max_loop(loopnum + 1)
35 .draw_on(Duration::from_millis(100));
36 let game = gs.build();
37 let mut ai = EmptyAI { loopnum: loopnum };
38 game.play(&mut ai);
39}Sourcepub fn args<I>(self, i: I) -> Selfwhere
I: IntoIterator<Item = &'a str>,
pub fn args<I>(self, i: I) -> Selfwhere
I: IntoIterator<Item = &'a str>,
Set multiple command line arguments
Sourcepub fn draw_on(self, d: Duration) -> Self
pub fn draw_on(self, d: Duration) -> Self
Draw game on terminal(Default: off). You hanve to set duration of drawing.
Examples found in repository?
4fn main() {
5 struct EmptyAI {
6 loopnum: usize,
7 };
8 impl Reactor for EmptyAI {
9 fn action(&mut self, _screen: ActionResult, turn: usize) -> Option<Vec<u8>> {
10 let mut res = Vec::new();
11 match turn {
12 val if val == self.loopnum - 1 => res.push(AsciiChar::CarriageReturn.as_byte()),
13 val if val == self.loopnum - 2 => res.push(b'y'),
14 val if val == self.loopnum - 3 => res.push(b'Q'),
15 _ => {
16 let c = match (turn % 4) as u8 {
17 0u8 => b'h',
18 1u8 => b'j',
19 2u8 => b'k',
20 _ => b'l',
21 };
22 res.push(c);
23 }
24 };
25 Some(res)
26 }
27 }
28 let loopnum = 50;
29 let gs = GameSetting::new("rogue")
30 .env("ROGUEUSER", "EmptyAI")
31 .lines(24)
32 .columns(80)
33 .debug_file("debug.txt")
34 .max_loop(loopnum + 1)
35 .draw_on(Duration::from_millis(100));
36 let game = gs.build();
37 let mut ai = EmptyAI { loopnum: loopnum };
38 game.play(&mut ai);
39}Sourcepub fn debug_file(self, s: &str) -> Self
pub fn debug_file(self, s: &str) -> Self
You can set debug file of this crate. This is mainly for developper of this crate:)
Examples found in repository?
4fn main() {
5 struct EmptyAI {
6 loopnum: usize,
7 };
8 impl Reactor for EmptyAI {
9 fn action(&mut self, _screen: ActionResult, turn: usize) -> Option<Vec<u8>> {
10 let mut res = Vec::new();
11 match turn {
12 val if val == self.loopnum - 1 => res.push(AsciiChar::CarriageReturn.as_byte()),
13 val if val == self.loopnum - 2 => res.push(b'y'),
14 val if val == self.loopnum - 3 => res.push(b'Q'),
15 _ => {
16 let c = match (turn % 4) as u8 {
17 0u8 => b'h',
18 1u8 => b'j',
19 2u8 => b'k',
20 _ => b'l',
21 };
22 res.push(c);
23 }
24 };
25 Some(res)
26 }
27 }
28 let loopnum = 50;
29 let gs = GameSetting::new("rogue")
30 .env("ROGUEUSER", "EmptyAI")
31 .lines(24)
32 .columns(80)
33 .debug_file("debug.txt")
34 .max_loop(loopnum + 1)
35 .draw_on(Duration::from_millis(100));
36 let game = gs.build();
37 let mut ai = EmptyAI { loopnum: loopnum };
38 game.play(&mut ai);
39}Sourcepub fn debug_level(self, s: Severity) -> Self
pub fn debug_level(self, s: Severity) -> Self
You can set debug level of this crate. This is mainly for developper of this crate:)
Sourcepub fn timeout(self, d: Duration) -> Self
pub fn timeout(self, d: Duration) -> Self
You can set timeout to game output. It’s setted to 0.1s by default.
Sourcepub fn max_loop(self, t: usize) -> Self
pub fn max_loop(self, t: usize) -> Self
You can set max_loop of game. It’s setted to 100 by default.
Examples found in repository?
4fn main() {
5 struct EmptyAI {
6 loopnum: usize,
7 };
8 impl Reactor for EmptyAI {
9 fn action(&mut self, _screen: ActionResult, turn: usize) -> Option<Vec<u8>> {
10 let mut res = Vec::new();
11 match turn {
12 val if val == self.loopnum - 1 => res.push(AsciiChar::CarriageReturn.as_byte()),
13 val if val == self.loopnum - 2 => res.push(b'y'),
14 val if val == self.loopnum - 3 => res.push(b'Q'),
15 _ => {
16 let c = match (turn % 4) as u8 {
17 0u8 => b'h',
18 1u8 => b'j',
19 2u8 => b'k',
20 _ => b'l',
21 };
22 res.push(c);
23 }
24 };
25 Some(res)
26 }
27 }
28 let loopnum = 50;
29 let gs = GameSetting::new("rogue")
30 .env("ROGUEUSER", "EmptyAI")
31 .lines(24)
32 .columns(80)
33 .debug_file("debug.txt")
34 .max_loop(loopnum + 1)
35 .draw_on(Duration::from_millis(100));
36 let game = gs.build();
37 let mut ai = EmptyAI { loopnum: loopnum };
38 game.play(&mut ai);
39}Sourcepub fn build(self) -> GameEnv
pub fn build(self) -> GameEnv
Consume game setting and build GameEnv
Examples found in repository?
4fn main() {
5 struct EmptyAI {
6 loopnum: usize,
7 };
8 impl Reactor for EmptyAI {
9 fn action(&mut self, _screen: ActionResult, turn: usize) -> Option<Vec<u8>> {
10 let mut res = Vec::new();
11 match turn {
12 val if val == self.loopnum - 1 => res.push(AsciiChar::CarriageReturn.as_byte()),
13 val if val == self.loopnum - 2 => res.push(b'y'),
14 val if val == self.loopnum - 3 => res.push(b'Q'),
15 _ => {
16 let c = match (turn % 4) as u8 {
17 0u8 => b'h',
18 1u8 => b'j',
19 2u8 => b'k',
20 _ => b'l',
21 };
22 res.push(c);
23 }
24 };
25 Some(res)
26 }
27 }
28 let loopnum = 50;
29 let gs = GameSetting::new("rogue")
30 .env("ROGUEUSER", "EmptyAI")
31 .lines(24)
32 .columns(80)
33 .debug_file("debug.txt")
34 .max_loop(loopnum + 1)
35 .draw_on(Duration::from_millis(100));
36 let game = gs.build();
37 let mut ai = EmptyAI { loopnum: loopnum };
38 game.play(&mut ai);
39}Trait Implementations§
Source§impl<'a> Clone for GameSetting<'a>
impl<'a> Clone for GameSetting<'a>
Source§fn clone(&self) -> GameSetting<'a>
fn clone(&self) -> GameSetting<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more