In a previous lesson, we were able to Add the C51 Train, and in the last lesson, Create a Function to Read ASCII-art from Text File, we moved that code into a function to make it usable for other ASCII-art images. This should make it pretty trivial to add another train. Let's add the "Little" train.
Create a new file named "src/little.txt", and paste the following art (from the C-version of "sl"'s "sl.h" file) into the new "src/little.txt" file.
" ++ +------ ____ ____________________ " " || |+-+ | | \@@@@@@@@@@@ | ___ ___ ___ ___ | " " /---------|| | | | \@@@@@@@@@@@@@_ | |_| |_| |_| |_| | " " + ======== +-+ | | | |__________________| " " _|--O========O~\-+ |__________________| |__________________| " "//// \_/ \_/ (O) (O) (O) (O) " " ++ +------ ____ ____________________ " " || |+-+ | | \@@@@@@@@@@@ | ___ ___ ___ ___ | " " /---------|| | | | \@@@@@@@@@@@@@_ | |_| |_| |_| |_| | " " + ======== +-+ | | | |__________________| " " _|--/O========O\-+ |__________________| |__________________| " "//// \_/ \_/ (O) (O) (O) (O) " " ++ +------ ____ ____________________ " " || |+-+ | | \@@@@@@@@@@@ | ___ ___ ___ ___ | " " /---------|| | | | \@@@@@@@@@@@@@_ | |_| |_| |_| |_| | " " + ======== +-+ | | | |__________________| " " _|--/~O========O-+ |__________________| |__________________| " "//// \_/ \_/ (O) (O) (O) (O) " " ++ +------ ____ ____________________ " " || |+-+ | | \@@@@@@@@@@@ | ___ ___ ___ ___ | " " /---------|| | | | \@@@@@@@@@@@@@_ | |_| |_| |_| |_| | " " + ======== +-+ | | | |__________________| " " _|--/~\------/~\-+ |__________________| |__________________| " "//// \_O========O (O) (O) (O) (O) " " ++ +------ ____ ____________________ " " || |+-+ | | \@@@@@@@@@@@ | ___ ___ ___ ___ | " " /---------|| | | | \@@@@@@@@@@@@@_ | |_| |_| |_| |_| | " " + ======== +-+ | | | |__________________| " " _|--/~\------/~\-+ |__________________| |__________________| " "//// \O========O/ (O) (O) (O) (O) " " ++ +------ ____ ____________________ " " || |+-+ | | \@@@@@@@@@@@ | ___ ___ ___ ___ | " " /---------|| | | | \@@@@@@@@@@@@@_ | |_| |_| |_| |_| | " " + ======== +-+ | | | |__________________| " " _|--/~\------/~\-+ |__________________| |__________________| " "//// O========O_/ (O) (O) (O) (O) "
Now, in "src/extras.rs", in the "draw_image()" function, make this little change:
...
let image = match kind.as_str() {
// Which image are we supposed to draw?
"D51" => get_d51(),
"C51" => get_image("./c51.txt"),
"LITTLE" => get_image("./little.txt"),
&_ => {
// If the user enters an unknown image name (say, "racecar") ...
println!(
"Invalid kind. You entered '{}'; the default was used instead.",
kind
);
get_d51()
}
...
Give it a try -- cargo run -- --kind little --speed medium. It'll even fly if you tell it to!
Easy, no?
And what if you wanted to Add a Jumping Jack?