Browse Source

Lots of stuff. Basic workable game now

Spesk1 4 years ago
parent
commit
8bca6d96cd
3 changed files with 660 additions and 25 deletions
  1. 174 0
      Cargo.lock
  2. 1 0
      Cargo.toml
  3. 485 25
      src/main.rs

+ 174 - 0
Cargo.lock

@@ -1,4 +1,178 @@
+[[package]]
+name = "autocfg"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "bitflags"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "cloudabi"
+version = "0.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "dwars"
 version = "0.1.0"
+dependencies = [
+ "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "fuchsia-cprng"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "libc"
+version = "0.2.58"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "rand"
+version = "0.6.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rand_chacha"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rand_core"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rand_core"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "rand_hc"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rand_isaac"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rand_jitter"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rand_os"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rand_pcg"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rand_xorshift"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rdrand"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "winapi"
+version = "0.3.7"
+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"
 
+[metadata]
+"checksum autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf"
+"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
+"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
+"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
+"checksum libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319"
+"checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
+"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
+"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
+"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0"
+"checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4"
+"checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08"
+"checksum rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b"
+"checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071"
+"checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44"
+"checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c"
+"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
+"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770"
+"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"

+ 1 - 0
Cargo.toml

@@ -5,3 +5,4 @@ authors = ["spesk1 <spesk@pm.me>"]
 edition = "2018"
 
 [dependencies]
+rand = "0.6"

+ 485 - 25
src/main.rs

@@ -1,39 +1,202 @@
 use std::io;
 use std::io::Read;
+use rand::Rng;
+use std::{thread, time};
 
+//////////
 // Objects
+//////////
+
+struct Market {
+    // Store current values of drugs on the market
+    weed: u32,
+    cocaine: u32,
+    heroin: u32,
+    acid: u32,
+    xtc: u32,
+    ludes: u32,
+}
+
+impl Market {
+    pub fn new(weed: u32, cocaine: u32, heroin: u32, acid: u32, xtc: u32, ludes: u32) -> Self {
+        Market { weed, cocaine, heroin, acid, xtc, ludes }
+    }
+
+    // This is normal market fluctuation when moving locations, as opposed to an event that drives prices up/down
+    pub fn change_prices(&mut self) {
+
+        let mut rng = rand::thread_rng();
+        let weed_diff = rng.gen_range(90,600);
+        let cocaine_diff = rng.gen_range(19000,40000);
+        let heroin_diff = rng.gen_range(7000,20000);
+        let acid_diff = rng.gen_range(300,1500);
+        let xtc_diff = rng.gen_range(50,500);
+        let ludes_diff = rng.gen_range(15,190);
+
+        self.weed = weed_diff;
+        self.cocaine = cocaine_diff;
+        self.heroin = heroin_diff;
+        self.acid = acid_diff;
+        self.xtc = xtc_diff;
+        self.ludes = ludes_diff;
+
+    }
+
+    pub fn dump(&self) {
+        println!("Prices\nWeed: ${}\tCocaine: ${}\nHeroin: ${}\tAcid: ${}\nXTC: ${}\tLudes: ${}\n", self.weed, self.cocaine, self.heroin, self.acid, self.xtc, self.ludes);
+    }
+
+}
 
 struct Player {
     health: u32,
-    money:  u32,
-    debt:   u32,
-    weed:   u32,
+    money: u32,
+    debt: u32,
+    weed: u32,
+    cocaine: u32,
+    heroin: u32,
+    acid: u32,
+    xtc: u32,
+    ludes: u32,
     location: String,
+    loan_timer: u32,
+    stash_size: u32,
 }
 
 impl Player {
-    pub fn new(health: u32, money: u32, debt: u32, weed: u32, location: String) -> Self {
-        Player { health, money, debt, weed, location }
+    pub fn new(health: u32, money: u32, debt: u32, weed: u32, cocaine: u32, heroin: u32, acid: u32, xtc: u32, ludes: u32, location: String, loan_timer: u32, stash_size: u32 ) -> Self {
+        Player { health, money, debt, weed, cocaine, heroin, acid, xtc, ludes, location, loan_timer, stash_size }
     }
 
-    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 dump(&self) {
+        println!("Health: {}\nMoney: ${}\tDebt: ${}", self.health, self.money, self.debt);
+        println!("You're in {}\n", self.location);
+        println!("You can hold {} units in your stash",self.stash_size);
+        println!("You're holding:\nWeed: {}    Cocaine: {}\nHeroin: {}    Acid: {}\nXTC: {}    Ludes: {}\n", self.weed, self.cocaine, self.heroin, self.acid, self.xtc, self.ludes);
     }
 
     pub fn change_location(&mut self, new_location: String) {
         self.location = new_location;
     }
+
+    pub fn get_stash_amount(&self, drug: &String) -> u32 {
+        let mut amount = 0;
+        match drug.as_ref() {
+            "weed" => amount = self.weed,
+            "cocaine" => amount = self.cocaine,
+            "heroin" => amount = self.heroin,
+            "acid" => amount = self.acid,
+            "xtc" => amount = self.xtc,
+            "ludes" => amount = self.ludes,
+            _ => amount = 0,
+        }
+
+        return amount;
+    }
+
+    pub fn buy_transaction(&mut self, drug_to_buy: &String, amount_to_buy: &u32, market_price: &u32) {
+        let cost = market_price * amount_to_buy;
+        self.money -= cost;
+
+        let add_amount = amount_to_buy;
+
+        match drug_to_buy.as_ref() {
+            "weed" => self.weed += add_amount,
+            "cocaine" => self.cocaine += add_amount,
+            "heroin" => self.heroin += add_amount,
+            "acid" => self.acid += add_amount,
+            "xtc" => self.xtc += add_amount,
+            "ludes" => self.ludes += add_amount,
+            _ => panic!("buy_transaction got a drug_to_buy value that doesn't make sense"),
+        }
+    }
+
+    pub fn sell_transaction(&mut self, drug_to_sell: &String, amount_to_sell: &u32, market_price: &u32) {
+        let revenue = market_price * amount_to_sell;
+
+        match drug_to_sell.as_ref() {
+            "weed" => self.weed -= amount_to_sell,
+            "cocaine" => self.cocaine -= amount_to_sell,
+            "heroin" => self.heroin -= amount_to_sell,
+            "acid" => self.acid -= amount_to_sell,
+            "xtc" => self.xtc -= amount_to_sell,
+            "ludes" => self.ludes -= amount_to_sell,
+            _ => panic!("sell_transaction got a drug_to_sell value that doesn't make sense"),
+        }
+
+        self.money += revenue;
+    }
+
+    
+    pub fn debt_interest(&mut self) {
+        let mut interest_amount: u32;
+        match self.debt {
+            0 => interest_amount = 0,
+            _ => interest_amount = ( self.debt as f32 * 0.2 ) as u32,
+        }
+
+        self.debt += interest_amount;
+    }
+
+    pub fn remove_debt(&mut self, payback_amount: u32) {
+        if (self.debt as i32 - payback_amount as i32) < 0 {
+            self.money -= payback_amount;
+            self.debt = 0;
+        } else {
+            self.money -= payback_amount;
+            self.debt -= payback_amount;
+        }
+    }
+
+    pub fn borrow_from_shark(&mut self, borrow_amount: u32) {
+        self.money += borrow_amount;
+        self.debt += borrow_amount;
+    }
+
+    pub fn take_damage(&mut self, damage_amount: u32) {
+        if (self.health as i32 - damage_amount as i32) < 0 {
+            self.health = 0;
+        } else {
+            self.health -= damage_amount;
+        }
+    }
+
+    pub fn take_heal(&mut self, heal_amount: u32) {
+        self.health += heal_amount;
+    }
+
+    pub fn decrease_loan_timer(&mut self, timer_amount: u32) {
+        if (self.loan_timer as i32 - timer_amount as i32) < 0 {
+            self.loan_timer = 0;
+        } else {
+            self.loan_timer -= timer_amount;
+        }
+    }
+
+    pub fn increase_loan_timer(&mut self, timer_amount: u32) {
+        self.loan_timer += timer_amount;
+    }
+
+    pub fn buy_trenchcoat(&mut self, cost: u32) {
+        self.stash_size += 25;
+        self.money -= cost;
+    }
+
+    pub fn buy_body_armor(&mut self, cost: u32) {
+        self.health += 2;
+        self.money -= cost;
+    }
+
+    pub fn stash_fill(&self) -> u32 {
+        let stash_fill = self.weed + self.cocaine + self.heroin + self.xtc + self.acid + self.ludes;
+        return stash_fill;
+    }
+
 }
 
+////////////////////////////////////////////////////////
 // "Low-level" Fuctions, called by "Top-level" functions
+////////////////////////////////////////////////////////
 
 fn prompt(prompt_text: String) -> io::Result<String> {
     println!("$ {}",prompt_text);
@@ -41,32 +204,329 @@ fn prompt(prompt_text: String) -> io::Result<String> {
     std::io::stdin().read_line(&mut input);
 
     let value: String = input.trim().parse().unwrap();
-    println!("Got value: {}", value);
     Ok(value)
 }
 
+// This hurts portability but works for now
+fn clear_term() {
+
+    print!("{}[2J", 27 as char);
+
+}
+
+fn get_drug_market_value(drug_to_buy: &String, market: &Market) -> io::Result<u32> {
+
+    let market_value: u32;
+    match drug_to_buy.as_ref() {
+        "weed" => market_value = market.weed,
+        "cocaine" => market_value = market.cocaine,
+        "heroin" => market_value = market.heroin,
+        "acid" => market_value = market.acid,
+        "xtc" => market_value = market.xtc,
+        "ludes" => market_value = market.ludes,
+        _ => panic!("get_drug_market_value got a drug_to_buy value that doesn't make sense!"),
+    }
+
+    Ok(market_value)
+
+}
+
+// This is maybe stupid? Or could be more idomatic ?? TODO?
+// May should use match inside of let ?
+fn get_drug_as_string(drug: &String) -> io::Result<String> {
+
+    let mut drug_as_string: String = String::new();
+    match drug.as_ref() {
+        "weed" => drug_as_string = "weed".to_string(),
+        "cocaine" => drug_as_string = "cocaine".to_string(),
+        "heroin" => drug_as_string = "heroin".to_string(),
+        "acid" => drug_as_string = "acid".to_string(),
+        "xtc" => drug_as_string = "xtc".to_string(),
+        "ludes" => drug_as_string = "ludes".to_string(),
+        _ => drug_as_string = "null".to_string(),
+    }
+
+    Ok(drug_as_string)
+
+}
+
+////////////////////////////////////
+// Events -- happen randomly in main
+////////////////////////////////////
+
+fn trenchcoat_event(player: &mut Player) {
+
+    let mut relative_cost = ( player.money as f64 * 0.25 ) as u32;
+    if relative_cost < 200 {
+        relative_cost = 200;
+    }
+    println!("A guy is selling his trench count, it'll allow you to carry 25 more units, want to buy it for ${} ?", relative_cost);
+    println!("You have ${}", player.money);
+    let response = prompt("Yes/no?".to_string()).unwrap();
+    if response.contains("yes") {
+        if player.money < relative_cost {
+            println!("You cant afford this!");
+        } else {
+            player.buy_trenchcoat(relative_cost);
+        }
+    }
+
+}
+
+fn body_armor_event(player: &mut Player) {
+
+    let mut relative_cost = ( player.money as f64 * 0.3 ) as u32;
+    if relative_cost < 300 {
+        relative_cost = 300;
+    }
+    println!("A guy is selling some body armor, it'll increase your health by 2, want to buy it for ${} ?", relative_cost);
+    println!("You have ${}", player.money);
+    let response = prompt("Yes/no?".to_string()).unwrap();
+    if response.contains("yes") {
+        if player.money < relative_cost {
+            println!("You cant afford this!");
+        } else {
+            player.buy_body_armor(relative_cost);
+        }
+    }
+
+}
+
+fn cops_event(player: &mut Player) {
+
+    let one_second = time::Duration::from_secs(1);
+    println!("The cops found you! Run!");
+    thread::sleep(one_second);
+    let mut rng = rand::thread_rng();
+    let mut escape: u32;
+    let mut hit: u32;
+    let mut done = false;
+    while ! done {
+        escape = rng.gen_range(0,5);
+        hit = rng.gen_range(0,10);
+        if escape == 0 {
+            println!("You got away!");
+            thread::sleep(one_second);
+            done = true;
+        } else {
+            println!("You cant get away, the cops are firing!");
+            thread::sleep(one_second);
+            if hit == 0 {
+                println!("You're hit for 2 damage!");
+                player.take_damage(2);
+                thread::sleep(one_second);
+            } else {
+                println!("They miss and you keep running!");
+                thread::sleep(one_second);
+            }
+        }
+    }
+}
+
+////////////////////////////////////////
 // "Top-level" Functions, called by main
+////////////////////////////////////////
+
+fn go_to_location(player: &mut Player, market: &mut Market) {
+
+    let mut loc_loop = false;
+    while ! loc_loop {
+        let mut new_location = prompt("Select a new location, locations are\nBrooklyn Midtown Harlem CentralPark".to_string()).unwrap();
+        match new_location.as_ref() {
+            "Brooklyn" => println!("Going to Brooklyn"),
+            "Midtown" => println!("Going to Midtown"),
+            "Harlem" => println!("Going to Harlem"),
+            "CentralPark" => println!("Going to CentralPark"),
+            _ => new_location = "null".to_string(),
+        }
+
+        if new_location != "null".to_string() {
+            if new_location == player.location {
+                println!("Youre already in {}", player.location);
+            } else {
+                player.change_location(new_location);
+                market.change_prices();
+                loc_loop = true;
+            }
+        } else {
+            println!("Not a valid location, try again");
+        }
+    }
 
-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 buy_drugs(player: &mut Player, market: &mut Market) {
 
+    let mut done = false;
+    let mut drug_to_buy: String = String::new();
+    while ! done {
+        drug_to_buy = prompt("What drug will you buy?".to_string()).unwrap();
+        drug_to_buy = get_drug_as_string(&drug_to_buy).unwrap();
+        if drug_to_buy != "null".to_string() {
+            done = true;
+        } else {
+            println!("Try again");
+        }
+    }
+
+    let mut done1 = false;
+    while ! done1 {
+        let drug_market_value: u32 = get_drug_market_value(&drug_to_buy, &market).unwrap();
+        let affordable_amount: u32 = (player.money / drug_market_value) as u32;
+        println!("You can afford {} {}", affordable_amount, drug_to_buy);
+        let amount_to_buy = prompt("How many will you buy?".to_string()).unwrap();
+        let amount_to_buy_int: u32 = amount_to_buy.parse().unwrap();
+        let current_stash_fill = player.stash_fill();
+        if amount_to_buy_int > affordable_amount {
+            println!("You cant afford that many");
+        } else if amount_to_buy_int > player.stash_size {
+            println!("You cant hold that much!");
+        } else if (amount_to_buy_int + current_stash_fill) > player.stash_size {
+            println!("You cant hold that much!");
+        } else {
+            println!("Buying {} {}", amount_to_buy_int, drug_to_buy);
+            player.buy_transaction(&drug_to_buy,&amount_to_buy_int,&drug_market_value);
+            done1 = true;
+        }
+    }
 }
 
+fn sell_drugs(player: &mut Player, market: &mut Market) {
+
+    let mut done = false;
+    let mut drug_to_sell: String = String::new();
+    while ! done {
+        drug_to_sell = prompt("What drug will you sell?".to_string()).unwrap();
+        drug_to_sell = get_drug_as_string(&drug_to_sell).unwrap();
+        if drug_to_sell != "null".to_string() {
+            done = true;
+        } else {
+            println!("Try again");
+        }
+    }
+
+    let mut done1 = false;
+    let mut amount_to_sell: String = String::new();
+    while ! done1 {
+        amount_to_sell = prompt("How many to sell?".to_string()).unwrap();
+        let amount_to_sell_int: u32 = amount_to_sell.parse().unwrap();
+        let drug_market_value: u32 = get_drug_market_value(&drug_to_sell, &market).unwrap();
+        let amount_possible_to_sell: u32 = player.get_stash_amount(&drug_to_sell);
+        if amount_to_sell_int > amount_possible_to_sell {
+            println!("You don't have that many {}, try again", drug_to_sell);
+        } else {
+            println!("Selling {} {}", amount_to_sell_int, drug_to_sell);
+            player.sell_transaction(&drug_to_sell,&amount_to_sell_int,&drug_market_value);
+            done1 = true;
+        }
+    }
+}
+
+fn loan_shark(player: &mut Player) {
+
+    if player.location != "Brooklyn".to_string() {
+        println!("Can only talk to the loanshark in Brooklyn");
+    } else {
+        let mut loan_done = false;
+        while ! loan_done {
+            let action = prompt("What do you want to do? (borrow,repay)".to_string()).unwrap();
+            if action.contains("repay") {
+                let payback_amount: u32 = prompt("How much to pay back?".to_string()).unwrap().parse().unwrap();
+                if payback_amount > player.money {
+                    println!("You dont have that much money");
+                } else {
+                    player.remove_debt(payback_amount);
+                    println!("You now owe the loanshark: ${}", player.debt);
+                    loan_done = true;
+                }
+            } else if action.contains("borrow") {
+                let borrow_amount = prompt("How much do you want to borrow? (Limit 20000)".to_string()).unwrap().parse().unwrap();
+                if borrow_amount > 20000 {
+                    println!("You cant borrow that much");
+                } else {
+                    player.borrow_from_shark(borrow_amount);
+                    loan_done = true;
+                }
+            }
+        }
+
+    }
+}
+
+///////
+// Main
+///////
+
 fn main() {
-    let mut player = Player::new(100,2000,2050,0,"Brooklyn".to_string());
-    let mut objects = [player];
+    let mut player = Player::new(10,2000,2050,0,0,0,0,0,0,"Brooklyn".to_string(),10,50);
+    let mut market = Market::new(0,0,0,0,0,0);
+    Market::change_prices(&mut market);
+    // let mut objects = [player,market];
     let mut done = false;
     while ! done {
-        objects[0].dump();
-        let input = prompt("Enter quit to quit".to_string()).unwrap();
+        let input = prompt("Type start, quit, or help".to_string()).unwrap();
 
         if input == "quit".to_string() {
             done = true;
-        } else if input == "change location".to_string() {
-            go_to_location(input, &mut objects[0]);
+        } else if input == "start".to_string() {
+            println!("Starting the game");
+            let mut main_loop = false;
+            while ! main_loop {
+                clear_term();
+                
+                let mut rng = rand::thread_rng();
+                let event_chance = rng.gen_range(0,9);
+                println!("Event chance is: {}",event_chance);
+                if event_chance == 2 {
+                    trenchcoat_event(&mut player);
+                }
+
+                if event_chance == 1 {
+                    body_armor_event(&mut player);
+                }
+
+                if event_chance == 0 {
+                    cops_event(&mut player);
+                }
+
+                if player.health == 0 {
+                    println!("You died! Game over!");
+                    main_loop = true;
+                }
+
+                if player.debt != 0 {
+                    if player.loan_timer == 0 {
+                        println!("** The loan shark wants his money! He beats you to a pulp to remind you! **");
+                        player.take_damage(2);
+                        player.increase_loan_timer(5);
+                        println!("** You take 2 damage! **");
+                    }
+                }
+
+                player.dump();
+                market.dump();
+
+                if player.location == "Brooklyn".to_string() {
+                    println!("You're currently in {}, what will you do? (buy,sell,jet,loanshark)",player.location);
+                } else {
+                    println!("You're currently in {}, what will you do? (buy,sell,jet)",player.location);
+                }
 
+                let action = prompt("".to_string()).unwrap();
+                if action.contains("buy") {
+                    buy_drugs(&mut player, &mut market);
+                } else if action.contains("sell") {
+                    sell_drugs(&mut player, &mut market);
+                } else if action.contains("jet") {
+                    go_to_location(&mut player, &mut market);
+                    player.debt_interest();
+                    player.decrease_loan_timer(1);
+                } else if action.contains("loanshark") {
+                        loan_shark(&mut player);
+                } else if action == "quit".to_string() {
+                    std::process::exit(0);
+                }
+            }
         }
     }
 }