34 lines
1.1 KiB
Rust
34 lines
1.1 KiB
Rust
use std::io;
|
|
use rand::Rng;
|
|
fn main(){
|
|
let mut score:i16 = 0;
|
|
while score < 32 {
|
|
println!("Vor dir sind drei Türen, eine von ihnen tötet dich");
|
|
println!("Durch welche gehst du? Gib eine Zahl zwischen 1 und 3 ein");
|
|
let secretnumber = rand::thread_rng().gen_range(1..=3);
|
|
let mut guess = String::new();
|
|
|
|
io::stdin()
|
|
.read_line(&mut guess)
|
|
.expect("Failed to read line");
|
|
if guess.chars().any(|c| c.is_digit(10)){
|
|
|
|
let guess: u32 = guess.trim().parse().expect("Please type a number!");
|
|
if guess == secretnumber {
|
|
println!("Dein score: {}", score);
|
|
println!("Du bist tot");
|
|
std::process::exit(0);
|
|
}
|
|
if guess > 4 {
|
|
println!("die option ist unbekannt");
|
|
}
|
|
else {
|
|
println!("Du hast überlebt");
|
|
score = score += 1;
|
|
println!("Der Geist ist hinter der Tür {}", secretnumber);
|
|
}}
|
|
else {
|
|
println!("Die Option ist unbekannt")
|
|
}}
|
|
println!("Du hast gewonnen");
|
|
} |