|
@@ -10,7 +10,6 @@ use self::pancurses::{
|
|
|
|
|
|
extern crate rand;
|
|
|
use self::rand::Rng;
|
|
|
-use self::rand::prelude::SliceRandom;
|
|
|
|
|
|
use std::{thread, time};
|
|
|
|
|
@@ -73,20 +72,16 @@ impl Screen {
|
|
|
let shuffled_words = copy_shuffle(&conf.words);
|
|
|
let words = &shuffled_words[..conf.choose];
|
|
|
|
|
|
- let coord = self.board.randomly_add_words(words);
|
|
|
+ let coords = self.board.randomly_add_words(words);
|
|
|
|
|
|
// The board of words + garbage characters has been built: now the screen must be displayed.
|
|
|
- // Take the board
|
|
|
-
|
|
|
let mut screen_buffer = Grid::new(Some(self.board.rows), Some(self.board.cols + (2 * BORDER_HEX_WIDTH) + 3));
|
|
|
let border_hex = border_hex_gen(self.board.rows, self.board.cols);
|
|
|
self.add_border_hex_to_grid(&mut screen_buffer, &border_hex);
|
|
|
self.add_board_to_grid(&mut screen_buffer);
|
|
|
|
|
|
// Debugging
|
|
|
- endwin();
|
|
|
- trace!("Words:\n{}", self.board.dump());
|
|
|
- trace!("Hex:\n{}", screen_buffer.dump());
|
|
|
+ trace!("Screen:\n{}", screen_buffer.dump());
|
|
|
}
|
|
|
|
|
|
pub fn end_window(&self) {
|
|
@@ -125,7 +120,7 @@ impl Screen {
|
|
|
}
|
|
|
|
|
|
// Half the board, plus characters for the first hex values, plus 2 spaces of padding.
|
|
|
- let right_hand_offset = grid.cols / 2;
|
|
|
+ let right_hand_offset = (grid.cols / 2) + 1;
|
|
|
for (row, hex_val) in right_side {
|
|
|
trace!("Printing 0x{:x} at {}, {}", hex_val, row, right_hand_offset);
|
|
|
grid.set_rowcol_str(row, right_hand_offset, &format!("0x{:x}", hex_val));
|
|
@@ -136,6 +131,23 @@ impl Screen {
|
|
|
// TODO
|
|
|
// The board is pressed to the right of each column
|
|
|
// Where to start placing the board on each row: (grid.cols / 2) - (self.board.cols / 2)
|
|
|
+
|
|
|
+ // TODO this should dynamically check size
|
|
|
+
|
|
|
+ let left_side_start = (grid.cols / 2) - (self.board.cols / 2);
|
|
|
+ let right_side_start = (grid.cols) - (self.board.cols / 2);
|
|
|
+
|
|
|
+ let mut board_iter = self.board.iter();
|
|
|
+ for row in 0..self.board.rows {
|
|
|
+ for col in 0..(self.board.cols / 2) {
|
|
|
+ grid.set_rowcol(row, left_side_start + col, *board_iter.next().unwrap());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for row in 0..self.board.rows {
|
|
|
+ for col in 0..(self.board.cols / 2) {
|
|
|
+ grid.set_rowcol(row, right_side_start + col, *board_iter.next().unwrap());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -150,7 +162,7 @@ fn window_enable_colors() {
|
|
|
fn border_hex_gen(rows: usize, cols: usize) -> Vec<u32> {
|
|
|
// Build the hex values, printed alongside the text and garbage.
|
|
|
// The vector will be of length rows * 2
|
|
|
- // TODO: this would make a nice generator, once those are stable.
|
|
|
+ // TODO: this would make a nice iterator, or generator, once those are stable.
|
|
|
let mut rng = rand::thread_rng();
|
|
|
let mut hex = rng.gen_range(0,200) + 63744;
|
|
|
|