@@ -6,4 +6,5 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
left-pad = "1.0.1"
|
||||||
rand = "0.9.0"
|
rand = "0.9.0"
|
||||||
|
|||||||
@@ -1,8 +1,75 @@
|
|||||||
mod models;
|
mod models;
|
||||||
use crate::models::taquin::*;
|
use crate::models::taquin::*;
|
||||||
|
use left_pad::leftpad;
|
||||||
|
use std::io::{self, Write};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
let mut taquin_game: TaquinGame = TaquinGame::new();
|
||||||
|
|
||||||
move_to();
|
taquin_game.init_grid();
|
||||||
|
draw_game(taquin_game);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw_game(game: TaquinGame) {
|
||||||
|
let grid = game.grid();
|
||||||
|
|
||||||
|
for i in 0..ROWS * 2 + 1 {
|
||||||
|
for j in 0..COLUMNS * 2 + 1 {
|
||||||
|
if i == 0 {
|
||||||
|
if j == 0 {
|
||||||
|
print!("╔");
|
||||||
|
} else if j == COLUMNS * 2 {
|
||||||
|
print!("╗");
|
||||||
|
} else if !is_even(j) {
|
||||||
|
print!("═══");
|
||||||
|
} else {
|
||||||
|
print!("╦");
|
||||||
|
}
|
||||||
|
} else if i == ROWS * 2 {
|
||||||
|
if j == 0 {
|
||||||
|
print!("╚");
|
||||||
|
} else if j == COLUMNS * 2 {
|
||||||
|
print!("╝");
|
||||||
|
} else if !is_even(j) {
|
||||||
|
print!("═══");
|
||||||
|
} else {
|
||||||
|
print!("╩");
|
||||||
|
}
|
||||||
|
} else if !is_even(i) {
|
||||||
|
if !is_even(j) {
|
||||||
|
print!("{}", leftpad(grid[i / 2][j / 2].to_string(), 3));
|
||||||
|
} else {
|
||||||
|
print!("║");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if j == 0 {
|
||||||
|
print!("╠");
|
||||||
|
} else if j == COLUMNS * 2 {
|
||||||
|
print!("╣");
|
||||||
|
} else if !is_even(j) {
|
||||||
|
print!("═══");
|
||||||
|
} else {
|
||||||
|
print!("╬");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if i == 0 {
|
||||||
|
print!("Score: {}", game.score());
|
||||||
|
} else if i == 1 {
|
||||||
|
print!("High score: {}", game.high_score());
|
||||||
|
}
|
||||||
|
|
||||||
|
let _ = io::stdout().flush();
|
||||||
|
println!("");
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Arrows to move");
|
||||||
|
println!("Q: Quit");
|
||||||
|
println!("R: Restart");
|
||||||
|
println!("S: Solve");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_even(num: usize) -> bool {
|
||||||
|
return num % 2 == 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
const COLUMNS: usize = 4;
|
pub const COLUMNS: usize = 4;
|
||||||
const ROWS: usize = 4;
|
pub const ROWS: usize = 4;
|
||||||
|
|
||||||
pub enum Directions {
|
pub enum Directions {
|
||||||
Down,
|
Down,
|
||||||
@@ -148,7 +148,7 @@ impl TaquinGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve(&mut self) {
|
pub fn resolve(&mut self) {
|
||||||
let mut value = 1;
|
let mut value = 0;
|
||||||
self.score = 0;
|
self.score = 0;
|
||||||
self.empty_coord = [ROWS - 1, COLUMNS - 1];
|
self.empty_coord = [ROWS - 1, COLUMNS - 1];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user