mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-23 07:29:02 -08:00
init
working on draw methods
This commit is contained in:
27
90_Tower/rust/src/disk.rs
Normal file
27
90_Tower/rust/src/disk.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
pub struct Disk {
|
||||
size: u8,
|
||||
}
|
||||
|
||||
impl Disk {
|
||||
pub fn new(size: u8) -> Self {
|
||||
Disk { size }
|
||||
}
|
||||
|
||||
pub fn draw(&self) {
|
||||
let space_amount = (15 - self.size) / 2;
|
||||
|
||||
let draw_space = || {
|
||||
if space_amount > 0 {
|
||||
for _ in 0..space_amount {
|
||||
print!(" ");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
draw_space();
|
||||
for _ in 0..self.size {
|
||||
print!("*");
|
||||
}
|
||||
draw_space();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user