Browse Source

First init

i0Ek3 2 months ago
commit
06d3e71efd
3 changed files with 52 additions and 0 deletions
  1. 2
    0
      .gitignore
  2. 10
    0
      Cargo.toml
  3. 40
    0
      src/main.rs

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
1
+/target
2
+**/*.rs.bk

+ 10
- 0
Cargo.toml View File

@@ -0,0 +1,10 @@
1
+[package]
2
+name = "guess-what"
3
+version = "0.1.0"
4
+authors = ["i0Ek3 <[email protected]>"]
5
+edition = "2018"
6
+
7
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8
+
9
+[dependencies]
10
+rand = "0.3.15"

+ 40
- 0
src/main.rs View File

@@ -0,0 +1,40 @@
1
+use std::io;
2
+use rand::Rng;
3
+use std::cmp::Ordering;
4
+
5
+fn guess() {
6
+    println!("Welcome to the game: GUESS WHAT!");
7
+    println!("You just need to input a number, are you ready?");
8
+
9
+    let secret = rand::thread_rng().gen_range(1, 51);
10
+    //println!("The secret number is: {}", secret);
11
+
12
+    loop {
13
+        println!("Please input your number:");
14
+
15
+        let mut guess = String::new();
16
+
17
+        io.stdin().read_line(&mut guess)
18
+            .expect("Cannot to read line!");
19
+
20
+        let guess: u32 = match guess.trim().parse() {
21
+            Ok(num) => num,
22
+            Err(_) => continue,
23
+        };
24
+
25
+        println!("You guessed: {}", guess);
26
+
27
+        match guess.cmp(&secret) {
28
+            Ordering::Less => println!("Just give sth big!");
29
+            Ordering::Greater => println!("Just small then!");
30
+            Ordering::Equal => {
31
+                println!("God damn, you win!");
32
+                break;
33
+            }
34
+        }
35
+    }
36
+}
37
+
38
+fn main() {
39
+    guess();
40
+}

Loading…
Cancel
Save