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