Barrier
, Condvar
, RwLock
UdpSocket
, TcpStream
, TcpListener
)
str::len
брои байтове, не char-ове — .chars().count()
ви трябваше
GameOver
, после BadGuess
unwrap()
-ове?Пълния код: rust-hangman
fn main() {
// ???
}
Парсене на команди
Option
вместо Result
, и позволява оператори-въпросчета?
Как избираме дума?
[dependencies]
rand = "*"
$HOME/.hangman_words.txt
$ hangman wordlist.txt
include_str!
cargo install
, а ако вече е било викнато, cargo install --force
~/.cargo/bin/
hangman wordlist.txt
pub fn clear_screen() {
if env::var("DEBUG").is_ok() {
return;
}
print!("{}[2J", 27 as char);
print!("{}[1;1H", 27 as char);
}
DEBUG=1 cargo run some-file.txt DEBUG=1 hangman some-file.txt
[dependencies]
rand = "*"
structopt = "*"
structopt-derive = "*"
$ hangman --wordlist=words.txt --attempts=10 --debug $ hangman -w words.txt -a 10 -d $ hangman --help $ hangman --version
extern crate structopt;
#[macro_use]
extern crate structopt_derive;
use structopt::StructOpt;
#[derive(StructOpt, Debug)]
#[structopt(name="hangman", about="A game of Hangman")]
pub struct Options {
#[structopt(short="w", long="wordlist", help="The path to a word list")]
wordlist_path: Option<String>,
#[structopt(short="a", long="attempts", help="The number of attempts to guess the word", default_value="10")]
attempts: u32,
#[structopt(short="d", long="debug", help="Show debug info")]
debug: bool,
}