-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathscore.rs
More file actions
35 lines (29 loc) · 699 Bytes
/
Copy pathscore.rs
File metadata and controls
35 lines (29 loc) · 699 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::frame::{Drawable, Frame, Reset};
#[derive(Default)]
pub struct Score {
count: u16,
}
impl Score {
pub fn new() -> Self {
Self { count: 0 }
}
pub fn add_points(&mut self, amount: u16) {
self.count += amount;
}
}
impl Reset for Score {
fn reset(&mut self) {
*self = Score::default();
}
}
impl Drawable for Score {
fn draw(&self, frame: &mut Frame) {
// format our score string
let formatted = format!("SCORE: {:0>4}", self.count);
// iterate over all characters
for (i, c) in formatted.chars().enumerate() {
// put them in the first row
frame[i][0] = c;
}
}
}