4_blocking_error/
4_blocking_error.rs1extern crate dcss_api;
2
3use dcss_api::Webtile;
4use dcss_api::{BlockingError, Error};
5
6fn main() {
7 let mut webtile =
9 Webtile::connect("ws://localhost:8080/socket", 100, "0.32").expect("Failed to connect");
10
11 while webtile.get_message().is_some() {}
13
14 let _gameid = webtile
16 .login_with_credentials("Username", "Password")
17 .expect("Failed to login");
18
19 while webtile.get_message().is_some() {}
21
22 webtile
24 .start_game("dcss-web-trunk", "b", "f", "b")
25 .expect("Failed to start game");
26
27 while let Some(message) = webtile.get_message() {
29 println!("{:?}", message)
30 }
31
32 webtile.write_key("i").expect("");
34 webtile
35 .read_until("menu", None, None)
36 .expect("Failed to read");
37 webtile.write_key("a").expect("");
38 webtile
39 .read_until("ui-push", None, None)
40 .expect("Failed to read");
41 webtile.write_key("d").expect("");
42 webtile
43 .read_until("player", None, None)
44 .expect("Failed to read");
45 webtile.write_key("i").expect("");
46 webtile
47 .read_until("menu", None, None)
48 .expect("Failed to read");
49 webtile.write_key("b").expect("");
50 webtile
51 .read_until("ui-push", None, None)
52 .expect("Failed to read");
53 webtile.write_key("d").expect("");
54 webtile
55 .read_until("player", None, None)
56 .expect("Failed to read");
57
58 while let Some(message) = webtile.get_message() {
60 println!("{:?}", message)
61 }
62
63 webtile.write_key(",").expect("");
65
66 match webtile.read_until("input_mode", Some("mode"), Some(1)) {
72 Ok(_) => (),
73 Err(e) => match *e {
74 Error::Blocking(BlockingError::Pickup) => {
75 println!("Pickup menu pop-up -- decide what to do");
76 webtile.write_key("key_esc").expect(""); webtile
78 .read_until("msgs", None, None)
79 .expect("Failed to read");
80 }
81 _ => panic!("Unexpected Error"),
82 },
83 };
84
85 while let Some(message) = webtile.get_message() {
87 println!("{:?}", message)
88 }
89
90 webtile.quit_game().expect("Failed to quit");
92
93 while let Some(message) = webtile.get_message() {
95 println!("{:?}", message)
96 }
97
98 webtile.disconnect().expect("Failed to disconnect");
100}