55 lines
1.3 KiB
Rust
55 lines
1.3 KiB
Rust
use Direction::{Left, Right};
|
|
|
|
use crate::Direction;
|
|
use crate::movable::Movable;
|
|
use crate::terminal::{clear_pos, print_str_at, TANK_ROW, WIDTH};
|
|
|
|
const TANK_STR: &str = "⊆≡≣🠭≣≡⊇";
|
|
|
|
pub struct Tank {
|
|
column: u16,
|
|
}
|
|
|
|
impl Movable<Tank> for Tank {
|
|
fn create() -> Tank {
|
|
let column = (WIDTH - (TANK_STR.len() as u16)) / 2;
|
|
let tank = Tank { column };
|
|
tank.draw();
|
|
tank
|
|
}
|
|
|
|
fn mov(&mut self, direction: Direction) {
|
|
clear(self, &direction);
|
|
match direction {
|
|
Left => { todo!("Implement moving left") }
|
|
Right => { todo!("Implement moving right") }
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
fn draw(&self) {
|
|
print_str_at(self.column, TANK_ROW, TANK_STR);
|
|
}
|
|
|
|
fn is_on_screen(&self) -> bool {
|
|
todo!("Implement tank visibility check")
|
|
}
|
|
}
|
|
|
|
fn clear(tank: &Tank, direction: &Direction) {
|
|
match direction {
|
|
Left => {
|
|
let right_col = tank.column + (TANK_STR.len() as u16) - 1;
|
|
if right_col >= TANK_STR.len() as u16 && right_col < WIDTH {
|
|
clear_pos(right_col, TANK_ROW);
|
|
}
|
|
}
|
|
Right => {
|
|
if tank.column < WIDTH - (TANK_STR.len() as u16) {
|
|
clear_pos(tank.column, TANK_ROW);
|
|
}
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|