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