From 2c96e3c3329af46546a54728cea58ca032977c65 Mon Sep 17 00:00:00 2001
From: robin <robin@noreply.localhost>
Date: Mon, 28 Oct 2024 14:59:51 +0100
Subject: [PATCH] src/main.rs aktualisiert

---
 src/main.rs | 61 +++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 43 insertions(+), 18 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 8864b9c..c223050 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,47 +1,71 @@
+use bevy::prelude::{warn, error};
+use bevy::prelude::{Component};
+use bevy::app::{App, Startup};
 use rand::Rng;
-use std::fs::{read, File};
+use std::io;
 use std::process::exit;
-use std::{fs, io};
+use bevy::DefaultPlugins;
+use bevy::log::info;
+use bevy::utils::{error, warn};
+
+#[derive(Component)]
+pub enum GameState {
+    Startup,
+    Menu,
+    InGame,
+}
 
 fn main() {
-    start();
+    App::new().add_plugins(DefaultPlugins).add_systems(Startup, start).run();
 }
 fn invalid_input(function: i8) {
     println!("Invalid Input");
+    warn!("Invalid Input");
     match function {
         1 => menu(),
         2 => store(),
-        3=> {
+        3 => {
             println!("Please input a valid name");
             start()
         }
-        _ => panic!("A fatal Error occurred"),
+        4 => {
+            println!("Please input a valid door");
+            game_loop(0)
+        }
+        _ => {
+            error!("Invalid Input got called without a trace, this will result in a crash.");
+            panic!("A fatal Error occurred")
+        }
     }
 }
 fn start() {
+    info!("Game starts");
     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{
+    if name.is_empty() == true {
         invalid_input(3)
-    }else {
-    println!("Hello {}", name);
-    menu();}
+    } else {
+        println!("Hello {}", name);
+        menu();
+    }
 }
 fn menu() {
+    info!("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),
+        "q" => exit(0),
         "e" => start(),
-        "s" => game_loop(),
+        "s" => game_loop(1),
         _ => invalid_input(1),
     }
 }
-fn game_loop() {
+fn game_loop(from:i8) {
+    info!("Ingame");
     let mut score: i8 = 0;
-    loop  {
+    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);
@@ -53,12 +77,12 @@ fn game_loop() {
                 secretnumber
             );
             score = score + 1;
-        }else if score == 32{
+        } else if score == 32 {
             println!("You won");
-            break
+
         } else {
             println!("You are death");
-            break
+            break;
         }
     }
     store();
@@ -68,9 +92,10 @@ fn input() -> i8 {
     io::stdin()
         .read_line(&mut guess)
         .expect("Failed to read line");
+
     let guess: i8 = guess.trim().parse().expect("Please type a number!");
-    return guess;
-}
+    return guess;}
+
 fn vergleich(guess: i8, secretnumber: i8) -> bool {
     if guess == secretnumber {
         true