|
@@ -1,3 +1,6 @@
|
|
|
|
+// Board control and interaction. The view & controller.
|
|
|
|
+//
|
|
|
|
+
|
|
extern crate pancurses;
|
|
extern crate pancurses;
|
|
use self::pancurses::{
|
|
use self::pancurses::{
|
|
initscr, endwin, noecho, has_colors, start_color, init_pair,
|
|
initscr, endwin, noecho, has_colors, start_color, init_pair,
|
|
@@ -14,18 +17,17 @@ use std::{thread, time};
|
|
use config::{Config};
|
|
use config::{Config};
|
|
use util::{copy_shuffle};
|
|
use util::{copy_shuffle};
|
|
|
|
|
|
-// Board control and interaction. The view & controller.
|
|
|
|
-
|
|
|
|
mod board {}
|
|
mod board {}
|
|
|
|
|
|
const DEFAULT_ROWS: usize = 17;
|
|
const DEFAULT_ROWS: usize = 17;
|
|
const DEFAULT_COLS: usize = 24;
|
|
const DEFAULT_COLS: usize = 24;
|
|
|
|
|
|
-// Different actions are printed to the console at different speeds (the terminal displaying output, vs the player "typing")
|
|
|
|
|
|
+// Different actions are printed to the console at different speeds: the
|
|
|
|
+// "terminal" displaying output, vs. the player "typing", for example.
|
|
const TERMINAL_PRINTING_SPEED: time::Duration = time::Duration::from_millis(20);
|
|
const TERMINAL_PRINTING_SPEED: time::Duration = time::Duration::from_millis(20);
|
|
const TYPING_SPEED: time::Duration = time::Duration::from_millis(70);
|
|
const TYPING_SPEED: time::Duration = time::Duration::from_millis(70);
|
|
|
|
|
|
-// Everything displayed to the player, + a reference to the curses window.
|
|
|
|
|
|
+// Everything displayed to the player, + a reference to the curses Window.
|
|
#[derive(Debug)]
|
|
#[derive(Debug)]
|
|
pub struct Screen {
|
|
pub struct Screen {
|
|
pub w: Window,
|
|
pub w: Window,
|
|
@@ -104,10 +106,13 @@ impl Board {
|
|
}
|
|
}
|
|
|
|
|
|
// Think of the board in word_len "chunks": place a slot for a word in each chunk
|
|
// Think of the board in word_len "chunks": place a slot for a word in each chunk
|
|
- fn place_words(&self, num_of_words: usize, word_len: usize) -> Vec<Coord> {
|
|
|
|
|
|
+ fn build_word_coords(&self, num_of_words: usize, word_len: usize) -> Vec<Coord> {
|
|
let chunk_len = self.capacity() / num_of_words;
|
|
let chunk_len = self.capacity() / num_of_words;
|
|
if chunk_len < word_len+1 {
|
|
if chunk_len < word_len+1 {
|
|
- panic!("Can't fill board");
|
|
|
|
|
|
+ panic!("Can't fill board: need {}-character long spaces for\
|
|
|
|
+ {}-character long words. But only have {}-character spaces\
|
|
|
|
+ available. Please choose smaller words or increase board size.",
|
|
|
|
+ word_len+1, word_len, chunk_len);
|
|
}
|
|
}
|
|
let mut coords: Vec<Coord> = Vec::with_capacity(num_of_words);
|
|
let mut coords: Vec<Coord> = Vec::with_capacity(num_of_words);
|
|
let mut starting_coord = 0;
|
|
let mut starting_coord = 0;
|
|
@@ -216,7 +221,7 @@ impl Screen {
|
|
panic!("{} words of length {} requires {} tiles, but an {}x{} board only allows for {} tiles", conf.words.len(), word_len, required_tiles, self.b.cols, self.b.rows, board_tiles);
|
|
panic!("{} words of length {} requires {} tiles, but an {}x{} board only allows for {} tiles", conf.words.len(), word_len, required_tiles, self.b.cols, self.b.rows, board_tiles);
|
|
}
|
|
}
|
|
|
|
|
|
- let mut coords = self.b.place_words(words.len(), word_len);
|
|
|
|
|
|
+ let mut coords = self.b.build_word_coords(words.len(), word_len);
|
|
self.b.shake_words(&mut coords);
|
|
self.b.shake_words(&mut coords);
|
|
|
|
|
|
println!("{:?}", coords);
|
|
println!("{:?}", coords);
|