Compare commits

..

3 commits

Author SHA1 Message Date
robin 1841f6d985 README.md aktualisiert 2024-08-17 20:26:44 +02:00
robin afbcb674b7 committed to the wrong Branch 2024-07-01 11:33:35 +02:00
robin 00fe0f68f6 src/main.rs aktualisiert
Added restart funktion, which restarts the if you die
2024-06-29 16:27:24 +02:00
2 changed files with 32 additions and 92 deletions

View file

@ -1,3 +1,3 @@
# Rust_lernen
Ich versuche rust zu lernen ich hoffe das ich mehr google als viridian frage
Ich versuche rust zu lernen ich hoffe das ich mehr google als Viridian frage
gessing game finished at 04.04.2024 on 21:25 Cest

View file

@ -1,94 +1,34 @@
use std::io;
use rand::Rng;
use std::fs::{read, File};
use std::process::exit;
use std::{fs, io};
fn main() {
start();
}
fn invalid_input(function: i8) {
println!("Invalid Input");
match function {
1 => menu(),
2 => store(),
3=> {
println!("Please input a valid name");
start()
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);
}
_ => 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.trim.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() {
let mut score: i8 = 0;
loop {
println!("Your score is: {}", score);
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 guess = input();
let ergebnis = vergleich(guess, secretnumber);
if ergebnis == false {
println!(
"You survived, the ghost was behind the {} door",
secretnumber
);
score = score + 1;
}else if score == 32{
println!("You won");
break
} else {
println!("You are death");
break
if guess > 4 {
println!("die option ist unbekannt");
}
}
store();
}
fn input() -> i8 {
let mut guess = String::new();
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");
let guess: i8 = guess.trim().parse().expect("Please type a number!");
return guess;
}
fn vergleich(guess: i8, secretnumber: i8) -> bool {
if guess == secretnumber {
true
} else {
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"),
"l" => println!("sorry but this is not avalibil"),
_ => invalid_input(2),
}
menu()
}
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");
}