summaryrefslogtreecommitdiff
path: root/src/minesweeper.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/minesweeper.rs')
-rw-r--r--src/minesweeper.rs18
1 files changed, 5 insertions, 13 deletions
diff --git a/src/minesweeper.rs b/src/minesweeper.rs
index a56758b..8a0ee8d 100644
--- a/src/minesweeper.rs
+++ b/src/minesweeper.rs
@@ -172,28 +172,20 @@ impl Board {
}
pub fn render(&self) -> Vec<u8> {
- const CYAN: &[u8] = &[27,b'[',b'3',b'6',b'm'];
- const YELLOW: &[u8] = &[27,b'[',b'3',b'3',b'm'];
- const GREEN: &[u8] = &[27,b'[',b'3',b'2',b'm'];
- const RED: &[u8] = &[27,b'[',b'3',b'1',b'm'];
- const FG: &[u8] = &[27,b'[',b'3',b'9',b'm'];
-
let mut ret = vec![27];
- let mut cur_clr = FG;
for y in 0..self.height {
for x in 0..self.width {
let c = &self.data[self.pos_to_off((x,y))];
match *c {
0 => ret.extend_from_slice(b"&nbsp"),
- _ if *c <= 8 => { if cur_clr != FG { ret.extend_from_slice(FG); cur_clr = FG; } ret.push(b'0' + c); },
- _ if (*c & CORRECT_BIT) > 0 => { if cur_clr != GREEN { ret.extend_from_slice(GREEN); cur_clr = GREEN; } ret.push(b'F') },
- _ if (*c & FLAGGED_BIT) > 0 => { if cur_clr != YELLOW { ret.extend_from_slice(YELLOW); cur_clr = YELLOW; } ret.push(b'F'); },
- _ if (*c & HIDDEN_BIT) > 0 => { if cur_clr != CYAN { ret.extend_from_slice(CYAN); cur_clr = CYAN; } ret.push(35); },
- _ if *c == MINE_VAL => { if cur_clr != RED { ret.extend_from_slice(RED); cur_clr = RED; } ret.push(b'O'); },
+ _ if *c <= 8 => ret.push(b'0' + c),
+ _ if (*c & CORRECT_BIT) > 0 => ret.push(b'C'),
+ _ if (*c & FLAGGED_BIT) > 0 => ret.push(b'F'),
+ _ if (*c & HIDDEN_BIT) > 0 => ret.push(b'#'),
+ _ if *c == MINE_VAL => ret.push(b'O'),
_ => ret.push(b'?'),
}
}
- ret.extend_from_slice(FG); cur_clr = FG;
ret.extend_from_slice(b"<br>");
}
ret