|
@@ -0,0 +1,75 @@
|
|
|
|
+extern crate pancurses;
|
|
|
|
+use self::pancurses::{
|
|
|
|
+ initscr, endwin, noecho, has_colors, start_color, init_pair,
|
|
|
|
+ Window,
|
|
|
|
+ COLOR_GREEN, COLOR_BLACK
|
|
|
|
+};
|
|
|
|
+use std::{thread, time};
|
|
|
|
+
|
|
|
|
+// Board control and interaction. The view & controller for the game.
|
|
|
|
+
|
|
|
|
+mod board {}
|
|
|
|
+
|
|
|
|
+pub struct Board {
|
|
|
|
+ pub w: Window
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+pub fn init_board() -> Board {
|
|
|
|
+ let window = initscr();
|
|
|
|
+ noecho();
|
|
|
|
+ window_enable_colors();
|
|
|
|
+ Board{w: window}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// Different actions are printed to the console at different speeds (the terminal displaying output, vs the player "typing")
|
|
|
|
+const TERMINAL_PRINTING_SPEED: time::Duration = time::Duration::from_millis(20);
|
|
|
|
+const TYPING_SPEED: time::Duration = time::Duration::from_millis(70);
|
|
|
|
+
|
|
|
|
+impl Board {
|
|
|
|
+ pub fn intro(&self) {
|
|
|
|
+ self.w.clear();
|
|
|
|
+ thread::sleep(time::Duration::from_millis(250));
|
|
|
|
+ self.print_with_delay(0, String::from("WELCOME TO ROBCO INDUSTRIES (TM) TERMLINK"), true, TERMINAL_PRINTING_SPEED);
|
|
|
|
+ self.move_cursor_to(1, 0);
|
|
|
|
+ thread::sleep(time::Duration::from_millis(30));
|
|
|
|
+
|
|
|
|
+ // TODO the rest of the intro
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pub fn initialize_game(&self) {
|
|
|
|
+ self.print_with_delay(0, String::from("ROBCO INDUSTRIES (TM) TERMLINK PROTOCOL"), false, TERMINAL_PRINTING_SPEED);
|
|
|
|
+ self.print_with_delay(1, String::from("ENTER PASSWORD NOW"), false, TERMINAL_PRINTING_SPEED);
|
|
|
|
+ // TODO ATTEMPTS LEFT should be a mapping or generator
|
|
|
|
+
|
|
|
|
+ // Start at some hex value
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pub fn end_window(&self) {
|
|
|
|
+ endwin();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fn move_cursor_to(&self, y: i32, x: i32) {
|
|
|
|
+ self.w.mv(y, x);
|
|
|
|
+ self.w.refresh();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fn print_with_delay(&self, line: i32, string: String, skippable: bool, delay: time::Duration) {
|
|
|
|
+ self.w.mv(line, 0);
|
|
|
|
+ for c in string.chars() {
|
|
|
|
+ self.w.addch(c);
|
|
|
|
+ self.w.refresh();
|
|
|
|
+ if skippable {
|
|
|
|
+ // TODO keyboard skip
|
|
|
|
+ }
|
|
|
|
+ thread::sleep(delay);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+fn window_enable_colors() {
|
|
|
|
+ if has_colors() {
|
|
|
|
+ start_color();
|
|
|
|
+ init_pair(1, COLOR_GREEN, COLOR_BLACK);
|
|
|
|
+ }
|
|
|
|
+}
|