Use std::process::exit instead of calling panic!
This commit is contained in:
parent
83737c1d36
commit
8f69a1b684
14
src/main.rs
14
src/main.rs
|
@ -1,5 +1,5 @@
|
||||||
use std::io;
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
use std::io;
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut score: u32 = 0;
|
let mut score: u32 = 0;
|
||||||
loop {
|
loop {
|
||||||
|
@ -9,25 +9,23 @@ fn main(){
|
||||||
println!("Gib eine Zahl zwischen 1 und 3 ein");
|
println!("Gib eine Zahl zwischen 1 und 3 ein");
|
||||||
let secretnumber = rand::thread_rng().gen_range(1..=3);
|
let secretnumber = rand::thread_rng().gen_range(1..=3);
|
||||||
let mut guess = String::new();
|
let mut guess = String::new();
|
||||||
let _input= io::stdin()
|
println!("{}", secretnumber);
|
||||||
.read_line(&mut guess);
|
let _input = io::stdin().read_line(&mut guess);
|
||||||
println!("Der Geist ist hinter der Tür {}", secretnumber);
|
println!("Der Geist ist hinter der Tür {}", secretnumber);
|
||||||
let guess: u32 = guess.trim().parse().expect("Please type a number!");
|
let guess: u32 = guess.trim().parse().expect("Please type a number!");
|
||||||
if guess == secretnumber {
|
if guess == secretnumber {
|
||||||
println!("Dein score: {}", score);
|
println!("Dein score: {}", score);
|
||||||
panic!("Du bist tot")
|
panic!("Du bist tot")
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
println!("Du hast überlebt");
|
println!("Du hast überlebt");
|
||||||
}
|
}
|
||||||
let _score = score += 1;
|
score += 1;
|
||||||
if score == 32 {
|
if score == 32 {
|
||||||
win(32);
|
win(32);
|
||||||
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
fn win(w: i32) {
|
fn win(w: i32) {
|
||||||
println!("Du hast mit {w} gewonnen");
|
println!("Du hast mit {w} gewonnen");
|
||||||
panic!()
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue