diff options
| author | tslil clingman <> | 2020-01-26 20:57:55 -0800 |
|---|---|---|
| committer | tslil clingman <> | 2020-01-26 20:57:55 -0800 |
| commit | 3a1c20ebba57632392443a050fc10d44e3048843 (patch) | |
| tree | 3f70bcbc43a40d64f58f8454e92d6da6bac7b3f7 /src/gui.rs | |
| parent | 1930b067982a5ee324cd2832ace295e67603d2dc (diff) | |
Playing against the computer actually works!
Diffstat (limited to 'src/gui.rs')
| -rw-r--r-- | src/gui.rs | 47 |
1 files changed, 29 insertions, 18 deletions
@@ -117,10 +117,9 @@ pub struct BoardGUI { black_colour: u8, } -#[derive(PartialEq)] pub enum BGAction { Quit, - None, + Selected(Action), } impl BoardGUI { @@ -194,11 +193,21 @@ impl BoardGUI { fn draw_stack(&self, pos: &Position, stack: &Stack) { if let Some(win) = self.cell_windows.get(self.pos_to_idx(pos)) { win.clear(); - let l = stack.len() as i32; - if l > 0 { - for i in 0..l { - let piece = &stack[i as usize]; - self.draw_stone(win, i == l - 1, &piece.player, &piece.stone); + let height = stack.len() as usize; + if height > 0 { + let carry_capacity = self.size as usize; + let tall = height > carry_capacity; + if tall { + win.attrset(Attribute::Normal); + win.addch('('); + } + for i in 0..height { + let piece = &stack[i]; + self.draw_stone(win, i + 1 == height, &piece.player, &piece.stone); + if tall && i + 2 == carry_capacity { + win.attrset(Attribute::Normal); + win.addch(')'); + } } } win.refresh(); @@ -208,14 +217,6 @@ impl BoardGUI { pub fn update(&self, game: &Game, squares: Vec<Position>) { // Is this really the `best' way? assert!(game.get_size() == self.size); - // for x in 0..self.size { - // for y in 0..self.size { - // let pos = Position { x: x, y: y }; - // if let Some(stack) = game.query_square(&pos) { - // self.draw_stack(&pos, stack); - // } - // } - // } for p in squares { if let Some(stack) = game.query_square(&p) { self.draw_stack(&p, stack); @@ -369,9 +370,19 @@ impl ActionEntry { Character('\n') => return result, KeyEnter => return result, // TODO: is this ever used? Character(c) => { - if result.len() < self.max_len { - result.push(c); - self.window.addch(c); + // Annoyingly there are two backspace possibilities + let ascii = c as usize; + if !result.is_empty() && (ascii == 127) || (ascii == 8) { + result.pop(); + let (y, x) = (self.window.get_cur_y(), self.window.get_cur_x()); + self.window.mv(y, x - 1); + self.window.addch('_'); + self.window.mv(y, x - 1); + } else { + if result.len() < self.max_len { + result.push(c); + self.window.addch(c); + } } } KeyBackspace => { |
