src/main.rs aktualisiert
This commit is contained in:
parent
ae920f8598
commit
7b47cdc1a6
82
src/main.rs
82
src/main.rs
|
@ -1,35 +1,67 @@
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use std::io;
|
use std::fs::{read, File};
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
use std::{fs, io};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
game_loop();
|
start();
|
||||||
|
}
|
||||||
|
fn invalid_input(function: i8) {
|
||||||
|
println!("Invalid Input");
|
||||||
|
match function {
|
||||||
|
1 => menu(),
|
||||||
|
2 => store(),
|
||||||
|
3=> {
|
||||||
|
println!("Please input a valid name");
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
_ => panic!("A fatal Error occurred"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn start() {
|
||||||
|
println!("Hello what is your Name?");
|
||||||
|
let mut name = String::new();
|
||||||
|
io::stdin().read_line(&mut name).expect("error");
|
||||||
|
if name.is_empty() == true{
|
||||||
|
invalid_input(3)
|
||||||
|
}else {
|
||||||
|
println!("Hello {}", name);
|
||||||
|
menu();}
|
||||||
|
}
|
||||||
|
fn menu() {
|
||||||
|
println!("Start the Game:s Quit:q let somebody else play:e ");
|
||||||
|
let mut doing = String::new();
|
||||||
|
io::stdin().read_line(&mut doing).expect("An fatal error");
|
||||||
|
match doing.trim() {
|
||||||
|
"q" => exit(1),
|
||||||
|
"e" => start(),
|
||||||
|
"s" => game_loop(),
|
||||||
|
_ => invalid_input(1),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn game_loop() {
|
fn game_loop() {
|
||||||
let mut score: i8 = 0;
|
let mut score: i8 = 0;
|
||||||
while score < 32 {
|
loop {
|
||||||
println!("Dein score ist: {}", score);
|
println!("Your score is: {}", score);
|
||||||
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!("In front of you are three doors, one of them kills you.Which one do you choose? Enter a number between 1 and 3.");
|
||||||
let secretnumber: i8 = rand::thread_rng().gen_range(1..=3);
|
let secretnumber: i8 = rand::thread_rng().gen_range(1..=3);
|
||||||
let guess = input();
|
let guess = input();
|
||||||
let ergebnis = vergleich(guess, secretnumber);
|
let ergebnis = vergleich(guess, secretnumber);
|
||||||
if ergebnis == false {
|
if ergebnis == false {
|
||||||
println!(
|
println!(
|
||||||
"Du hast überlebt, der Geist war hinter der Tür {}",
|
"You survived, the ghost was behind the {} door",
|
||||||
secretnumber
|
secretnumber
|
||||||
);
|
);
|
||||||
score = score + 1;
|
score = score + 1;
|
||||||
|
}else if score == 32{
|
||||||
|
println!("You won");
|
||||||
|
break
|
||||||
} else {
|
} else {
|
||||||
println!("Du bist tot");
|
println!("You are death");
|
||||||
score = 0;
|
break
|
||||||
let mut idk: bool = idk();
|
|
||||||
if idk == true {
|
|
||||||
} else {
|
|
||||||
panic!()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("Du hast gewonnen ");
|
store();
|
||||||
}
|
}
|
||||||
fn input() -> i8 {
|
fn input() -> i8 {
|
||||||
let mut guess = String::new();
|
let mut guess = String::new();
|
||||||
|
@ -46,17 +78,17 @@ fn vergleich(guess: i8, secretnumber: i8) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn store() {
|
||||||
|
println!("Where do you want to store your score? Server: s/ lokal: l");
|
||||||
|
let mut storage = String::new();
|
||||||
|
io::stdin()
|
||||||
|
.read_line(&mut storage)
|
||||||
|
.expect("fatal error accorded");
|
||||||
|
match storage.trim() {
|
||||||
|
"s" => println!("sorry but this is not avalibil"),
|
||||||
|
|
||||||
fn idk() -> bool {
|
"l" => println!("sorry but this is not avalibil"),
|
||||||
println!("Wilst du das Spiel nocheinmal spielen (y/n)");
|
_ => invalid_input(2),
|
||||||
let mut idks = String::new();
|
|
||||||
io::stdin().read_line(&mut idks).expect("A Error eccurt");
|
|
||||||
match idks {
|
|
||||||
y => return true,
|
|
||||||
n => return false,
|
|
||||||
_ => panic!(),
|
|
||||||
}
|
}
|
||||||
}
|
menu()
|
||||||
fn quit() {
|
|
||||||
panic!()
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue