commit 3eb035b6fce10d99cb310ad30ec058c53ba00fc6
Author: spesk1 <spesk@pm.me>
Date: Mon Jun 3 21:54:18 2019 -0400
Added price fluctuation events
diff --git a/README.md b/README.md
index bc3ffa5..dbc2b40 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,8 @@
My attempt at writing something like the classic DOS game Drug Wars in Rust.
TODO:
-* Add price fluctuation events
+* Clean up code, make things more concise/less messy
+* ~~Add price fluctuation events~~ DONE
* ~~Get arrested by the cops, lose money/drugs~~ DONE
* ~~Implement "head stash" to store money/drugs in case of arrest~~ DONE
diff --git a/src/main.rs b/src/main.rs
index f780454..c589b9f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -8,6 +8,18 @@ use std::{thread, time};
struct Market {
// Store current values of drugs on the market
+ weed_min: u32,
+ weed_max: u32,
+ cocaine_min: u32,
+ cocaine_max: u32,
+ heroin_min: u32,
+ heroin_max: u32,
+ acid_min: u32,
+ acid_max: u32,
+ xtc_min: u32,
+ xtc_max: u32,
+ ludes_min: u32,
+ ludes_max: u32,
weed: u32,
cocaine: u32,
heroin: u32,
@@ -16,21 +28,23 @@ struct Market {
ludes: u32,
}
+// Market::new(100,600,18000,28000,3000,10000,700,2000,120,500,15,200,0,0,0,0,0,0)
+
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 }
+ pub fn new(weed_min: u32, weed_max: u32, cocaine_min: u32, cocaine_max: u32, heroin_min: u32, heroin_max: u32, acid_min: u32, acid_max: u32, xtc_min: u32, xtc_max: u32, ludes_min: u32, ludes_max: u32, weed: u32, cocaine: u32, heroin: u32, acid: u32, xtc: u32, ludes: u32) -> Self {
+ Market { weed_min, weed_max, cocaine_min, cocaine_max, heroin_min, heroin_max, acid_min, acid_max, xtc_min, xtc_max, ludes_min, ludes_max, 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);
+ let weed_diff = rng.gen_range(self.weed_min,self.weed_max);
+ let cocaine_diff = rng.gen_range(self.cocaine_min,self.cocaine_max);
+ let heroin_diff = rng.gen_range(self.heroin_min,self.heroin_max);
+ let acid_diff = rng.gen_range(self.acid_min,self.acid_max);
+ let xtc_diff = rng.gen_range(self.xtc_min,self.xtc_max);
+ let ludes_diff = rng.gen_range(self.ludes_min,self.ludes_max);
self.weed = weed_diff;
self.cocaine = cocaine_diff;
@@ -44,6 +58,63 @@ impl Market {
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);
}
+
+ pub fn set_price(&mut self, drug_to_set: &String, price_to_set: u32) {
+ match drug_to_set.as_ref() {
+ "weed" => self.weed = price_to_set,
+ "cocaine" => self.cocaine = price_to_set,
+ "heroin" => self.heroin = price_to_set,
+ "acid" => self.acid = price_to_set,
+ "xtc" => self.xtc = price_to_set,
+ "ludes" => self.ludes = price_to_set,
+ _ => panic!("Market::set_price got a drug_to_set value that doesn't make sense"),
+ }
+ }
+
+ pub fn get_current_price(&self, drug_to_get: &String) -> u32 {
+ let current_price: u32;
+ match drug_to_get.as_ref() {
+ "weed" => current_price = self.weed,
+ "cocaine" => current_price = self.cocaine,
+ "heroin" => current_price = self.heroin,
+ "acid" => current_price = self.acid,
+ "xtc" => current_price = self.xtc,
+ "ludes" => current_price = self.ludes,
+ _ => panic!("Market::get_current_price got a drug_to_get value that doesn't make sense"),
+ }
+
+ return current_price;
+ }
+
+ pub fn get_min_price(&self, drug_to_get: &String) -> u32 {
+ let min_price: u32;
+ match drug_to_get.as_ref() {
+ "weed" => min_price = self.weed_min,
+ "cocaine" => min_price = self.cocaine_min,
+ "heroin" => min_price = self.heroin_min,
+ "acid" => min_price = self.acid_min,
+ "xtc" => min_price = self.xtc_min,
+ "ludes" => min_price = self.ludes_min,
+ _ => panic!("Market::get_min_price got a drug_to_get value that doesn't make sense"),
+ }
+
+ return min_price;
+ }
+
+ pub fn get_max_price(&self, drug_to_get: &String) -> u32 {
+ let max_price: u32;
+ match drug_to_get.as_ref() {
+ "weed" => max_price = self.weed_max,
+ "cocaine" => max_price = self.cocaine_max,
+ "heroin" => max_price = self.heroin_max,
+ "acid" => max_price = self.acid_max,
+ "xtc" => max_price = self.xtc_max,
+ "ludes" => max_price = self.ludes_max,
+ _ => panic!("Market::get_min_price got a drug_to_get value that doesn't make sense"),
+ }
+
+ return max_price;
+ }
}
struct HeadStash {
@@ -395,8 +466,7 @@ fn cops_event(player: &mut Player) {
let one_second = time::Duration::from_secs(1);
if ! player.holding() {
println!("The cops found you, but you're not holding so it's chill.");
- thread::sleep(one_second);
- thread::sleep(one_second);
+ let _placeholder = prompt("".to_string());
} else {
println!("The cops found you! Run!");
thread::sleep(one_second);
@@ -409,7 +479,7 @@ fn cops_event(player: &mut Player) {
hit = rng.gen_range(0,3);
if escape == 0 {
println!("You got away!");
- thread::sleep(one_second);
+ let _placeholder = prompt("".to_string());
done = true;
} else {
println!("You cant get away, the cops are firing!");
@@ -422,6 +492,7 @@ fn cops_event(player: &mut Player) {
if arrest == 0 {
println!("The cops got you! They confiscate your cash and stash!");
player.arrested();
+ let _placeholder = prompt("".to_string());
done = true;
}
} else {
@@ -431,11 +502,41 @@ fn cops_event(player: &mut Player) {
}
}
}
+}
+
+fn price_event(market: &mut Market) {
+
+ let mut rng = rand::thread_rng();
+ let raise_drop = rng.gen_range(0,2);
+ let choose_drug = rng.gen_range(0,5);
+ let drug_to_edit: String;
+ match choose_drug {
+ 0 => drug_to_edit = "weed".to_string(),
+ 1 => drug_to_edit = "cocaine".to_string(),
+ 2 => drug_to_edit = "heroin".to_string(),
+ 3 => drug_to_edit = "acid".to_string(),
+ 4 => drug_to_edit = "xtc".to_string(),
+ 5 => drug_to_edit = "ludes".to_string(),
+ _ => panic!("drug_to_edit match in price_drop_event got a match that doesn't make sense"),
+ }
+
+ if raise_drop == 0 {
+ // Price drop
+ println!("A new shipment has flooded the market and caused the price of {} to dive!",drug_to_edit);
+ let temp_price = (market.get_current_price(&drug_to_edit) as f64 * 0.2) as u32;
+ market.set_price(&drug_to_edit,temp_price);
+ let _placeholder = prompt("".to_string());
+ } else {
+ // Price raise
+ println!("A bust has caused the price of {} to soar!",drug_to_edit);
+ let temp_price = market.get_current_price(&drug_to_edit) + market.get_max_price(&drug_to_edit);
+ market.set_price(&drug_to_edit,temp_price);
+ let _placeholder = prompt("".to_string());
+ }
- thread::sleep(one_second);
- thread::sleep(one_second);
}
+
////////////////////////////////////////
// "Top-level" Functions, called by main
////////////////////////////////////////
@@ -646,7 +747,8 @@ fn head_stash_op(player: &mut Player, head_stash: &mut HeadStash) {
fn main() {
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);
+ // let mut market = Market::new(0,0,0,0,0,0);
+ let mut market = Market::new(100,600,18000,28000,3000,10000,700,2000,120,500,15,200,0,0,0,0,0,0);
let mut head_stash = HeadStash::new(0,0,0,0,0,0,0);
Market::change_prices(&mut market);
let mut done = false;
@@ -662,16 +764,19 @@ fn main() {
clear_term();
if player.health == 0 {
+ clear_term();
println!("You died! Game over!");
+ let _placeholder = prompt("".to_string());
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! **");
+ 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! **");
+ println!("You take 2 damage!");
+ let _placeholder = prompt("".to_string());
}
}
@@ -698,6 +803,10 @@ fn main() {
// Only have events trigger after 'jetting'
let mut rng = rand::thread_rng();
let event_chance = rng.gen_range(0,9);
+ if event_chance == 3 {
+ price_event(&mut market);
+ }
+
if event_chance == 2 {
trenchcoat_event(&mut player);
}
@@ -711,7 +820,9 @@ fn main() {
}
if player.health == 0 {
+ clear_term();
println!("You died! Game over!");
+ let _placeholder = prompt("".to_string());
main_loop = true;
}