Browse Source

Beginnings of basic frame

spesk1 4 years ago
parent
commit
61624e95e3
4 changed files with 84 additions and 0 deletions
  1. 1 0
      .gitignore
  2. 4 0
      Cargo.lock
  3. 7 0
      Cargo.toml
  4. 72 0
      src/main.rs

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+/target

+ 4 - 0
Cargo.lock

@@ -0,0 +1,4 @@
+[[package]]
+name = "dwars"
+version = "0.1.0"
+

+ 7 - 0
Cargo.toml

@@ -0,0 +1,7 @@
+[package]
+name = "dwars"
+version = "0.1.0"
+authors = ["spesk1 <spesk@pm.me>"]
+edition = "2018"
+
+[dependencies]

+ 72 - 0
src/main.rs

@@ -0,0 +1,72 @@
+use std::io;
+use std::io::Read;
+
+// Objects
+
+struct Player {
+    health: u32,
+    money:  u32,
+    debt:   u32,
+    weed:   u32,
+    location: String,
+}
+
+impl Player {
+    pub fn new(health: u32, money: u32, debt: u32, weed: u32, location: String) -> Self {
+        Player { health, money, debt, weed, location }
+    }
+
+    pub fn add_weed(&mut self, add_amount: u32) {
+        self.weed += add_amount;
+    }
+
+    pub fn dump(&mut self) {
+        println!("Health: {}", self.health);
+        println!("Money: {}", self.money);
+        println!("Debt: {}", self.debt);
+        println!("Weed: {}", self.weed);
+        println!("Location: {}", self.location);
+    }
+
+    pub fn change_location(&mut self, new_location: String) {
+        self.location = new_location;
+    }
+}
+
+// "Low-level" Fuctions, called by "Top-level" functions
+
+fn prompt(prompt_text: String) -> io::Result<String> {
+    println!("$ {}",prompt_text);
+    let mut input = String::new();
+    std::io::stdin().read_line(&mut input);
+
+    let value: String = input.trim().parse().unwrap();
+    println!("Got value: {}", value);
+    Ok(value)
+}
+
+// "Top-level" Functions, called by main
+
+fn go_to_location(target_location: String, player: &mut Player) {
+
+    let new_location = prompt("Select a new location, locations are\n\tBrooklyn\n\tManhatten".to_string()).unwrap();
+    player.change_location(new_location);
+
+}
+
+fn main() {
+    let mut player = Player::new(100,2000,2050,0,"Brooklyn".to_string());
+    let mut objects = [player];
+    let mut done = false;
+    while ! done {
+        objects[0].dump();
+        let input = prompt("Enter quit to quit".to_string()).unwrap();
+
+        if input == "quit".to_string() {
+            done = true;
+        } else if input == "change location".to_string() {
+            go_to_location(input, &mut objects[0]);
+
+        }
+    }
+}