Josh Bicking 4 yıl önce
işleme
ee250ebc91
4 değiştirilmiş dosya ile 263 ekleme ve 0 silme
  1. 3 0
      .gitignore
  2. 137 0
      Cargo.lock
  3. 9 0
      Cargo.toml
  4. 114 0
      src/main.rs

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+
+/target
+**/*.rs.bk

+ 137 - 0
Cargo.lock

@@ -0,0 +1,137 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "argparse"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "cc"
+version = "1.0.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "cfg-if"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "fallout-terminal"
+version = "0.1.0"
+dependencies = [
+ "argparse 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pancurses 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "yaml-rust 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "gcc"
+version = "0.3.54"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "libc"
+version = "0.2.42"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "linked-hash-map"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "log"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "ncurses"
+version = "5.92.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "pancurses"
+version = "0.16.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "ncurses 5.92.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pdcurses-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winreg 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "pdcurses-sys"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "cc 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "pkg-config"
+version = "0.3.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "winapi"
+version = "0.3.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "winapi-i686-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "winapi-x86_64-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "winreg"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "yaml-rust"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "linked-hash-map 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[metadata]
+"checksum argparse 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "37bb99f5e39ee8b23b6e227f5b8f024207e8616f44aa4b8c76ecd828011667ef"
+"checksum cc 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "49ec142f5768efb5b7622aebc3fdbdbb8950a4b9ba996393cb76ef7466e8747d"
+"checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18"
+"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb"
+"checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1"
+"checksum linked-hash-map 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "70fb39025bc7cdd76305867c4eccf2f2dcf6e9a57f5b21a93e1c2d86cd03ec9e"
+"checksum log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6fddaa003a65722a7fb9e26b0ce95921fe4ba590542ced664d8ce2fa26f9f3ac"
+"checksum ncurses 5.92.0 (registry+https://github.com/rust-lang/crates.io-index)" = "536b7d9e89b5f571a2db383b790524d649cf7a3465d9381fe8159bf8dfd4be7e"
+"checksum pancurses 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cedc1409ecbb0a789f39e2a90ae052df6670c1e1c17724587e1872e6ec270e56"
+"checksum pdcurses-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "90e12bfe55b7080fdfa0742f7a22ce7d5d1da250ca064ae6b81c843a2084fa2a"
+"checksum pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "110d5ee3593dbb73f56294327fe5668bcc997897097cbc76b51e7aed3f52452f"
+"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd"
+"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
+"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
+"checksum winreg 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a27a759395c1195c4cc5cda607ef6f8f6498f64e78f7900f5de0a127a424704a"
+"checksum yaml-rust 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "57ab38ee1a4a266ed033496cf9af1828d8d6e6c1cfa5f643a2809effcae4d628"

+ 9 - 0
Cargo.toml

@@ -0,0 +1,9 @@
+[package]
+name = "fallout-terminal"
+version = "0.1.0"
+authors = ["Josh Bicking <[email protected]>"]
+
+[dependencies]
+pancurses = "0.16.0"
+argparse = "0.2.1"
+yaml-rust = "0.4"

+ 114 - 0
src/main.rs

@@ -0,0 +1,114 @@
+extern crate argparse;
+extern crate pancurses;
+extern crate yaml_rust;
+
+use std::fs::{File};
+use std::io::prelude::*;
+use std::process::exit;
+use std::{thread, time};
+
+use argparse::{ArgumentParser, Store};
+use pancurses::{
+    initscr, endwin, noecho, has_colors, start_color, init_pair,
+    Window,
+    COLOR_GREEN, COLOR_BLACK
+};
+use yaml_rust::{YamlLoader, YamlEmitter};
+
+fn main() {
+
+    // Argument handling
+    let mut difficulty = String::from("");
+    let mut config_location = String::from("~/.config/fallout-terminal.yaml");
+    let config_help = format!("Config file location, default {}", config_location);
+    {
+        let mut ap = ArgumentParser::new();
+        ap.set_description("A Fallout terminal minigame inspired game.");
+        ap.refer(&mut difficulty)
+            .add_option(&["--difficulty"], Store, "The game's difficulty (veryEasy [default], \
+                                                   easy, average, hard, or veryHard)");
+
+        ap.refer(&mut config_location)
+            .add_option(
+                &["--config"],
+                Store,
+                config_help.as_str()
+            );
+        ap.parse_args_or_exit();
+    }
+
+    match difficulty.as_str() {
+        "" | "veryEasy" => {
+            println!("veryEasy");
+        },
+        _ => println!("Invalid difficulty, see --help")
+    }
+
+
+    // Config file handling
+    let mut config_file = match File::open(config_location.as_str()) {
+        Ok(config_file) => config_file,
+        Err(ref e) if e.kind() == std::io::ErrorKind::NotFound => {
+            // Write the file if it doesn't exist
+            let mut new_config_file = match File::create(config_location.as_str()) {
+                Ok(f) => f,
+                Err(e) => {
+                    println!("Could not create {}: {}", config_location, e);
+                    exit(1);
+                }
+            };
+            // TODO write yaml
+            new_config_file.write_all(b"");
+            new_config_file
+        }
+        Err(e) => {
+            println!("Could not open {}: {}", config_location, e);
+            exit(1);
+        }
+    };
+
+    let mut config_content = String::new();
+    match config_file.read_to_string(&mut config_content) {
+        Ok(_) => (),
+        Err(e) => {
+            println!("Could not read {}: {}", config_location, e);
+            exit(1);
+        }
+    };
+
+    let window = initscr();
+    noecho();
+    // window.printw("Hello from Rust");
+    window_prep();
+    intro(&window);
+    window.refresh();
+    window.getch();
+    endwin();
+}
+
+fn window_prep () {
+    if has_colors() {
+        start_color();
+        init_pair(1,COLOR_GREEN, COLOR_BLACK);
+    }
+}
+
+fn intro (w: &Window) {
+    fn slow_print(w: &Window, line: i32, string: String) {
+        w.mv(line, 0);
+        for c in string.chars() {
+            w.addch(c);
+            w.refresh();
+            // TODO keyboard skip
+            thread::sleep(time::Duration::from_millis(20));
+        }
+    }
+
+    w.clear();
+    thread::sleep(time::Duration::from_millis(250));
+    slow_print(&w, 0, String::from("WELCOME TO ROBCO INDUSTRIES (TM) TERMLINK"));
+
+    w.mv(1, 0);
+    w.refresh();
+    thread::sleep(time::Duration::from_millis(30));
+}