Struct GameSetting

Source
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>

Source

pub fn new(command_name: &str) -> Self

Build GameSetting object with command name(like rogue).

Examples found in repository?
examples/rogue.rs (line 29)
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}
Source

pub fn columns(self, u: usize) -> Self

Set screen width of curses widow

Examples found in repository?
examples/rogue.rs (line 32)
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}
Source

pub fn lines(self, u: usize) -> Self

Set screen height of curses window

Examples found in repository?
examples/rogue.rs (line 31)
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}
Source

pub fn arg(self, s: &'a str) -> Self

Add command line argument

Source

pub fn env(self, s: &'a str, t: &'a str) -> Self

Set environmental variable

Examples found in repository?
examples/rogue.rs (line 30)
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}
Source

pub fn args<I>(self, i: I) -> Self
where I: IntoIterator<Item = &'a str>,

Set multiple command line arguments

Source

pub fn envs<I>(self, i: I) -> Self
where I: IntoIterator<Item = (&'a str, &'a str)>,

Set multiple environmental variables

Source

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?
examples/rogue.rs (line 35)
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}
Source

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?
examples/rogue.rs (line 33)
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}
Source

pub fn debug_level(self, s: Severity) -> Self

You can set debug level of this crate. This is mainly for developper of this crate:)

Source

pub fn timeout(self, d: Duration) -> Self

You can set timeout to game output. It’s setted to 0.1s by default.

Source

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?
examples/rogue.rs (line 34)
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}
Source

pub fn build(self) -> GameEnv

Consume game setting and build GameEnv

Examples found in repository?
examples/rogue.rs (line 36)
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>

Source§

fn clone(&self) -> GameSetting<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for GameSetting<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for GameSetting<'a>

§

impl<'a> RefUnwindSafe for GameSetting<'a>

§

impl<'a> Send for GameSetting<'a>

§

impl<'a> Sync for GameSetting<'a>

§

impl<'a> Unpin for GameSetting<'a>

§

impl<'a> UnwindSafe for GameSetting<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> SendSyncUnwindSafe for T
where T: Send + Sync + UnwindSafe + ?Sized,