Josh Bicking 4 年 前
コミット
6d271de01f
4 ファイル変更90 行追加65 行削除
  1. 75 0
      src/board.rs
  2. 10 6
      src/main.rs
  3. 5 0
      src/model.rs
  4. 0 59
      src/screen.rs

+ 75 - 0
src/board.rs

@@ -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);
+    }
+}

+ 10 - 6
src/main.rs

@@ -1,7 +1,7 @@
 extern crate argparse;
 
 mod config;
-mod screen;
+mod board;
 
 use self::argparse::{ArgumentParser, Store};
 use std::process::{exit};
@@ -42,9 +42,13 @@ fn main() {
     let mut config = config::load_config_file(config_location);
     println!("{:?}", config);
 
-    let screen = screen::init_screen();
-    screen.intro();
-    screen.w.refresh();
-    screen.w.getch();
-    screen.end_window();
+    // TODO config overrides
+
+    let board = board::init_board();
+    board.intro();
+
+    // Lower-level stuff
+    board.w.refresh();
+    board.w.getch();
+    board.end_window();
 }

+ 5 - 0
src/model.rs

@@ -0,0 +1,5 @@
+// The "logic" module. Manipulates game states.
+
+// The board preps state from reads & other on-screen information: this handles
+// processing and rule following.
+

+ 0 - 59
src/screen.rs

@@ -1,59 +0,0 @@
-extern crate pancurses;
-use self::pancurses::{
-    initscr, endwin, noecho, has_colors, start_color, init_pair,
-    Window,
-    COLOR_GREEN, COLOR_BLACK
-};
-use std::{thread, time};
-
-// Screen control functionality. Essentially just handling the heavy lifting
-// pancurses involves.
-
-// A Screen object here is just a wrapper around pancurses' Window.
-
-mod screen {}
-
-pub struct Screen {
-    pub w: Window
-}
-
-
-pub fn init_screen() -> Screen {
-    let window = initscr();
-    noecho();
-    window_enable_colors();
-    Screen{w: window}
-}
-
-impl Screen {
-    pub fn intro (&self) {
-        self.w.clear();
-        thread::sleep(time::Duration::from_millis(250));
-        self.slow_print(0, String::from("WELCOME TO ROBCO INDUSTRIES (TM) TERMLINK"));
-
-        self.w.mv(1, 0);
-        self.w.refresh();
-        thread::sleep(time::Duration::from_millis(30));
-    }
-
-    pub fn end_window(&self) {
-        endwin();
-    }
-
-    fn slow_print(&self, line: i32, string: String) {
-        self.w.mv(line, 0);
-        for c in string.chars() {
-            self.w.addch(c);
-            self.w.refresh();
-            // TODO keyboard skip
-            thread::sleep(time::Duration::from_millis(20));
-        }
-    }
-}
-
-fn window_enable_colors() {
-    if has_colors() {
-        start_color();
-        init_pair(1, COLOR_GREEN, COLOR_BLACK);
-    }
-}