Compare commits
3 commits
guessing-g
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
1841f6d985 | ||
|
afbcb674b7 | ||
|
00fe0f68f6 |
|
@ -1,3 +1,3 @@
|
||||||
# Rust_lernen
|
# 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
|
gessing game finished at 04.04.2024 on 21:25 Cest
|
122
src/main.rs
122
src/main.rs
|
@ -1,94 +1,34 @@
|
||||||
|
use std::io;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use std::fs::{read, File};
|
fn main(){
|
||||||
use std::process::exit;
|
let mut score:i16 = 0;
|
||||||
use std::{fs, io};
|
while score < 32 {
|
||||||
|
println!("Vor dir sind drei Türen, eine von ihnen tötet dich");
|
||||||
fn main() {
|
println!("Durch welche gehst du? Gib eine Zahl zwischen 1 und 3 ein");
|
||||||
start();
|
let secretnumber = rand::thread_rng().gen_range(1..=3);
|
||||||
}
|
let mut guess = String::new();
|
||||||
fn invalid_input(function: i8) {
|
|
||||||
println!("Invalid Input");
|
io::stdin()
|
||||||
match function {
|
.read_line(&mut guess)
|
||||||
1 => menu(),
|
.expect("Failed to read line");
|
||||||
2 => store(),
|
if guess.chars().any(|c| c.is_digit(10)){
|
||||||
3=> {
|
|
||||||
println!("Please input a valid name");
|
let guess: u32 = guess.trim().parse().expect("Please type a number!");
|
||||||
start()
|
if guess == secretnumber {
|
||||||
|
println!("Dein score: {}", score);
|
||||||
|
println!("Du bist tot");
|
||||||
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
_ => panic!("A fatal Error occurred"),
|
if guess > 4 {
|
||||||
}
|
println!("die option ist unbekannt");
|
||||||
}
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
store();
|
println!("Du hast überlebt");
|
||||||
}
|
score = score += 1;
|
||||||
fn input() -> i8 {
|
println!("Der Geist ist hinter der Tür {}", secretnumber);
|
||||||
let mut guess = String::new();
|
}}
|
||||||
io::stdin()
|
else {
|
||||||
.read_line(&mut guess)
|
println!("Die Option ist unbekannt")
|
||||||
.expect("Failed to read line");
|
}}
|
||||||
let guess: i8 = guess.trim().parse().expect("Please type a number!");
|
println!("Du hast gewonnen");
|
||||||
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()
|
|
||||||
}
|
|
Loading…
Reference in a new issue