Gessing_Game/src/main.rs

34 lines
1.1 KiB
Rust
Raw Normal View History

2024-04-04 21:30:03 +02:00
use std::io;
use rand::Rng;
fn main(){
2024-06-05 22:26:31 +02:00
let mut score:i16 = 0;
while score < 32 {
2024-06-05 22:26:31 +02:00
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");
2024-04-04 21:30:03 +02:00
let secretnumber = rand::thread_rng().gen_range(1..=3);
2024-06-05 22:26:31 +02:00
let mut guess = String::new();
2024-06-05 22:26:31 +02:00
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");
if guess.chars().any(|c| c.is_digit(10)){
2024-06-07 13:40:19 +02:00
2024-04-04 21:30:03 +02:00
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);
2024-04-04 21:30:03 +02:00
}
2024-06-05 22:26:31 +02:00
if guess > 4 {
println!("die option ist unbekannt");
2024-06-05 22:26:31 +02:00
}
2024-04-04 21:30:03 +02:00
else {
println!("Du hast überlebt");
2024-06-10 09:23:54 +02:00
score = score += 1;
2024-06-05 22:26:31 +02:00
println!("Der Geist ist hinter der Tür {}", secretnumber);
}}
else {
println!("Die Option ist unbekannt")
}}
println!("Du hast gewonnen");
}