From 2f9687126ecb538f40b57bd6963129b406786175 Mon Sep 17 00:00:00 2001 From: stale Date: Tue, 3 May 2022 05:39:13 -0300 Subject: lazy commit, buncha stuff --- src/minesweeper.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'src/minesweeper.rs') 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 { - 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" "), - _ 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"
"); } ret -- cgit v1.2.3