Compare commits

..

No commits in common. "guessing-game-dev-bevy" and "guessing-game" have entirely different histories.

View file

@ -1,71 +1,47 @@
use bevy::prelude::{warn, error};
use bevy::prelude::{Component};
use bevy::app::{App, Startup};
use rand::Rng;
use std::io;
use std::fs::{read, File};
use std::process::exit;
use bevy::DefaultPlugins;
use bevy::log::info;
use bevy::utils::{error, warn};
#[derive(Component)]
pub enum GameState {
Startup,
Menu,
InGame,
}
use std::{fs, io};
fn main() {
App::new().add_plugins(DefaultPlugins).add_systems(Startup, start).run();
start();
}
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()
}
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")
}
_ => 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.is_empty() == true {
if name.trim.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(0),
"q" => exit(1),
"e" => start(),
"s" => game_loop(1),
"s" => game_loop(),
_ => invalid_input(1),
}
}
fn game_loop(from:i8) {
info!("Ingame");
fn game_loop() {
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);
@ -77,12 +53,12 @@ fn game_loop(from:i8) {
secretnumber
);
score = score + 1;
} else if score == 32 {
}else if score == 32{
println!("You won");
break
} else {
println!("You are death");
break;
break
}
}
store();
@ -92,10 +68,9 @@ 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