marion 4 years ago
parent
commit
310b3c571f
4 changed files with 52 additions and 1083 deletions
  1. 13 1072
      Cargo.lock
  2. 1 8
      Cargo.toml
  3. 33 0
      src/guessing_game/mod.rs
  4. 5 3
      src/main.rs

File diff suppressed because it is too large
+ 13 - 1072
Cargo.lock


+ 1 - 8
Cargo.toml

@@ -7,11 +7,4 @@ edition = "2018"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-actix-web = "2"
-actix-rt = "1"
-actix-files = "0.2"
-
-env_logger = "0.7"
-serde = { version = "1.0", features = ["derive"] }
-serde_json = "1.0"
-bytes = "0.5"
+rand = "0.7.3"

+ 33 - 0
src/guessing_game/mod.rs

@@ -0,0 +1,33 @@
+use std::io;
+use rand::Rng;
+use std::cmp::Ordering;
+
+pub fn main() {
+    println!("Guess the number!");
+    let secret_number = rand::thread_rng().gen_range(1, 101);
+
+    loop {
+        println!("Please input your guess.");
+
+        let mut guess = String::new();
+
+        io::stdin().read_line(&mut guess)
+            .expect("Failed to read line");
+
+        let guess: u32 = match guess.trim().parse() {
+            Ok(num) => num,
+            Err(_) => continue,
+        };
+
+        println!("You guessed: {}", guess);
+
+        match guess.cmp(&secret_number) {
+            Ordering::Less => println!("Too small!"),
+            Ordering::Greater => println!("Too big!"),
+            Ordering::Equal   => {
+                println!("You win!");
+                break;
+            }
+        }
+    }
+}

+ 5 - 3
src/main.rs

@@ -6,17 +6,19 @@
 // mod keygen_test;
 // mod qr_code_test;
 // mod spider_test;
-mod actix_test;
+// mod actix_test;
+mod guessing_game;
 
 // 将其他模块的成员声明为当前模块直接可用的,等同于java的静态引用
 // 若省略这句,使用时就需要加上模块名,如random_test::Random
 // use self::random_test::{test, Random};
 
-fn main() -> std::io::Result<()> {
+fn main()  {
     // random_test::test();
     // keygen_test::test();
     // qr_code_test::test(2, 3);
     // spider_test::test("https://www.baidu.com").unwrap();
-    actix_test::http_listener()
+    // actix_test::http_listener() // return -> std::io::Result<()>
+    guessing_game::main();
 }
 

Some files were not shown because too many files changed in this diff