Oh hi, so, i’ve been looking to learn rust recently and since i don’t want to be stuck in “tutorial hell”, i’ve decided to create a little project to learn in more practical manners. This project is just a small text-based RPG game in the terminal, could help alot to understand user inputs, loops and etc. To begin with, i would like to create a title start screen, it shows the title and its the means to start the game by just pressing an input. Thus where my problem lies, i would like to know how i can bind the ENTER key to start the game, so the user would need to press enter to start the first chapter.
So far what i’ve learned from rust regarding user input is read_line, but it doesn’t really work the way i want, yes the user can still just press enter and start but its an instance of a string aswell, which means he can just type anything and it would look weird, not really how these things work in games.
Here’s the code so far:
`use std::io;
fn main() {
let mut enter = String::new();
println!("###################");
println!(" MY GAME ");
println!("###################");
println!();
println!("Press enter to begin.");
io::stdin()
.read_line(&mut enter)
.expect("Invalid input.");
print!("{}[2J", 27 as char); //This is a screen cleaner
}`
that’s the gist of it, would like to know if this is possible and how to do it, any feedback in the current state of the code would be great too!
Matt2code is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.