src/main.rs aktualisiert
Added restart funktion, which restarts the if you die
This commit is contained in:
parent
320cc799c0
commit
00fe0f68f6
74
src/main.rs
74
src/main.rs
|
@ -1,34 +1,48 @@
|
||||||
use std::io;
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
fn main(){
|
use std::io;
|
||||||
let mut score:i16 = 0;
|
use std::process::exit;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
game_loop();
|
||||||
|
}
|
||||||
|
fn game_loop() {
|
||||||
|
let mut score = 0;
|
||||||
while score < 32 {
|
while score < 32 {
|
||||||
println!("Vor dir sind drei Türen, eine von ihnen tötet dich");
|
println!("Dein score ist: {}",score);
|
||||||
println!("Durch welche gehst du? Gib eine Zahl zwischen 1 und 3 ein");
|
println!("Vor dir sind drei Türen, eine von ihnen tötet dich. Durch welche gehst du? Gib eine Zahl zwischen 1 und 3 ein");
|
||||||
let secretnumber = rand::thread_rng().gen_range(1..=3);
|
let secretnumber: i8 = rand::thread_rng().gen_range(1..=3);
|
||||||
let mut guess = String::new();
|
let guess = input();
|
||||||
|
let ergebnis = vergleich(guess, secretnumber);
|
||||||
io::stdin()
|
if ergebnis == false {
|
||||||
.read_line(&mut guess)
|
println!(
|
||||||
.expect("Failed to read line");
|
"Du hast überlebt, der Geist war hinter der Tür {}",
|
||||||
if guess.chars().any(|c| c.is_digit(10)){
|
secretnumber
|
||||||
|
);
|
||||||
let guess: u32 = guess.trim().parse().expect("Please type a number!");
|
score = score + 1;
|
||||||
if guess == secretnumber {
|
} else {
|
||||||
println!("Dein score: {}", score);
|
|
||||||
println!("Du bist tot");
|
println!("Du bist tot");
|
||||||
std::process::exit(0);
|
println!("Game restarts");
|
||||||
|
restart();
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
if guess > 4 {
|
}
|
||||||
println!("die option ist unbekannt");
|
println!("Du hast gewonnen ");
|
||||||
}
|
}
|
||||||
else {
|
fn input() -> i8 {
|
||||||
println!("Du hast überlebt");
|
let mut guess = String::new();
|
||||||
score = score += 1;
|
io::stdin()
|
||||||
println!("Der Geist ist hinter der Tür {}", secretnumber);
|
.read_line(&mut guess)
|
||||||
}}
|
.expect("Failed to read line");
|
||||||
else {
|
let guess: i8 = guess.trim().parse().expect("Please type a number!");
|
||||||
println!("Die Option ist unbekannt")
|
return guess;
|
||||||
}}
|
}
|
||||||
println!("Du hast gewonnen");
|
fn vergleich(guess: i8, secretnumber: i8) -> bool {
|
||||||
}
|
if guess == secretnumber {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn restart(){
|
||||||
|
game_loop()
|
||||||
|
}
|
Loading…
Reference in a new issue