Added the prints of the game to the screen

This commit is contained in:
thatscringebro 2024-12-19 11:31:02 -05:00
parent 98842df868
commit d0d7163921

View File

@ -1,11 +1,32 @@
use rand::prelude::*;
use std::{thread, time::Duration};
const COLORS: [&str; 5] = [
"\x1b[42m", // Green background
"\x1b[41m", // Red background
"\x1b[43m", // Yellow background
"\x1b[44m", // Blue background
"\x1b[47m", // White background
];
// Define the reset color escape code
const RESET: &str = "\x1b[0m";
// Define the squares content
const SQUARES: [[&str; 3]; 4] = [
[" ", " 1 ", " "],
[" ", " 2 ", " "],
[" ", " 3 ", " "],
[" ", " 4 ", " "],
];
fn main() {
let turns: Vec<i8> = gen_turn_array();
let mut amnt: i8 = 0;
let good_answer: bool = true;
show_base("Press any button to start the game".to_string());
while good_answer {
show_game(amnt, turns.clone());
amnt += 1;
@ -26,22 +47,264 @@ fn gen_turn_array() -> Vec<i8> {
fn show_game(amnt: i8, turns: Vec<i8>) {
for i in 0..amnt {
print!("{esc}[2J{esc}[1;1H", esc = 27 as char); //Clear the screen
println!("============== Simon Game ==============");
let turn: i8 = turns[i as usize];
match turn {
1 => {
println!("VERT");
println!(
"{}{}{}|{}{}{}|{}{}{}|{}{}{}",
COLORS[4],
SQUARES[0][0],
RESET,
COLORS[1],
SQUARES[1][0],
RESET,
COLORS[2],
SQUARES[2][0],
RESET,
COLORS[3],
SQUARES[3][0],
RESET
);
println!(
"{}{}{}|{}{}{}|{}{}{}|{}{}{}",
COLORS[4],
SQUARES[0][1],
RESET,
COLORS[1],
SQUARES[1][1],
RESET,
COLORS[2],
SQUARES[2][1],
RESET,
COLORS[3],
SQUARES[3][1],
RESET
);
println!(
"{}{}{}|{}{}{}|{}{}{}|{}{}{}",
COLORS[4],
SQUARES[0][2],
RESET,
COLORS[1],
SQUARES[1][2],
RESET,
COLORS[2],
SQUARES[2][2],
RESET,
COLORS[3],
SQUARES[3][2],
RESET
);
}
2 => {
println!("ROUGE");
println!(
"{}{}{}|{}{}{}|{}{}{}|{}{}{}",
COLORS[0],
SQUARES[0][0],
RESET,
COLORS[4],
SQUARES[1][0],
RESET,
COLORS[2],
SQUARES[2][0],
RESET,
COLORS[3],
SQUARES[3][0],
RESET
);
println!(
"{}{}{}|{}{}{}|{}{}{}|{}{}{}",
COLORS[0],
SQUARES[0][1],
RESET,
COLORS[4],
SQUARES[1][1],
RESET,
COLORS[2],
SQUARES[2][1],
RESET,
COLORS[3],
SQUARES[3][1],
RESET
);
println!(
"{}{}{}|{}{}{}|{}{}{}|{}{}{}",
COLORS[0],
SQUARES[0][2],
RESET,
COLORS[4],
SQUARES[1][2],
RESET,
COLORS[2],
SQUARES[2][2],
RESET,
COLORS[3],
SQUARES[3][2],
RESET
);
}
3 => {
println!("JAUNE");
println!(
"{}{}{}|{}{}{}|{}{}{}|{}{}{}",
COLORS[0],
SQUARES[0][0],
RESET,
COLORS[1],
SQUARES[1][0],
RESET,
COLORS[4],
SQUARES[2][0],
RESET,
COLORS[3],
SQUARES[3][0],
RESET
);
println!(
"{}{}{}|{}{}{}|{}{}{}|{}{}{}",
COLORS[0],
SQUARES[0][1],
RESET,
COLORS[1],
SQUARES[1][1],
RESET,
COLORS[4],
SQUARES[2][1],
RESET,
COLORS[3],
SQUARES[3][1],
RESET
);
println!(
"{}{}{}|{}{}{}|{}{}{}|{}{}{}",
COLORS[0],
SQUARES[0][2],
RESET,
COLORS[1],
SQUARES[1][2],
RESET,
COLORS[4],
SQUARES[2][2],
RESET,
COLORS[3],
SQUARES[3][2],
RESET
);
}
4 => {
println!("BLEU");
println!(
"{}{}{}|{}{}{}|{}{}{}|{}{}{}",
COLORS[0],
SQUARES[0][0],
RESET,
COLORS[1],
SQUARES[1][0],
RESET,
COLORS[2],
SQUARES[2][0],
RESET,
COLORS[4],
SQUARES[3][0],
RESET
);
println!(
"{}{}{}|{}{}{}|{}{}{}|{}{}{}",
COLORS[0],
SQUARES[0][1],
RESET,
COLORS[1],
SQUARES[1][1],
RESET,
COLORS[2],
SQUARES[2][1],
RESET,
COLORS[4],
SQUARES[3][1],
RESET
);
println!(
"{}{}{}|{}{}{}|{}{}{}|{}{}{}",
COLORS[0],
SQUARES[0][2],
RESET,
COLORS[1],
SQUARES[1][2],
RESET,
COLORS[2],
SQUARES[2][2],
RESET,
COLORS[4],
SQUARES[3][2],
RESET
);
}
_ => println!("Error parsing turn."),
}
println!("========================================");
println!("Animating...");
thread::sleep(Duration::from_millis(1000));
}
show_base("Animation finished!".to_string());
}
fn show_base(message: String) {
print!("{esc}[2J{esc}[1;1H", esc = 27 as char); //Clear the screen
println!("============== Simon Game ==============");
println!(
"{}{}{}|{}{}{}|{}{}{}|{}{}{}",
COLORS[0],
SQUARES[0][0],
RESET,
COLORS[1],
SQUARES[1][0],
RESET,
COLORS[2],
SQUARES[2][0],
RESET,
COLORS[3],
SQUARES[3][0],
RESET
);
println!(
"{}{}{}|{}{}{}|{}{}{}|{}{}{}",
COLORS[0],
SQUARES[0][1],
RESET,
COLORS[1],
SQUARES[1][1],
RESET,
COLORS[2],
SQUARES[2][1],
RESET,
COLORS[3],
SQUARES[3][1],
RESET
);
println!(
"{}{}{}|{}{}{}|{}{}{}|{}{}{}",
COLORS[0],
SQUARES[0][2],
RESET,
COLORS[1],
SQUARES[1][2],
RESET,
COLORS[2],
SQUARES[2][2],
RESET,
COLORS[3],
SQUARES[3][2],
RESET
);
println!("========================================");
println!("{}", message);
}