Browse Source

A few small tweaks

Spesk1 5 years ago
parent
commit
4d41a087c4
2 changed files with 41 additions and 22 deletions
  1. 6 1
      README.md
  2. 35 21
      src/main.rs

+ 6 - 1
README.md

@@ -1,3 +1,8 @@
 # dwars
 
-My attempt at writing something like the classic DOS game Drug Wars in Rust.
+My attempt at writing something like the classic DOS game Drug Wars in Rust.
+
+TODO:
+* Add price fluctuation events
+* Get arrested by the cops, lose money/drugs
+* Implement "head stash" to store money/drugs in case of arrest

+ 35 - 21
src/main.rs

@@ -192,6 +192,14 @@ impl Player {
         return stash_fill;
     }
 
+    pub fn holding(&self) -> bool {
+        if self.stash_fill() == 0 {
+            return false;
+        } else {
+            return true;
+        }
+    }
+
 }
 
 ////////////////////////////////////////////////////////
@@ -295,29 +303,36 @@ fn body_armor_event(player: &mut Player) {
 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);
+    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);
+        thread::sleep(one_second);
+    } else { 
+        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!("They miss and you keep running!");
+                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(4);
+                    thread::sleep(one_second);
+                } else {
+                    println!("They miss and you keep running!");
+                    thread::sleep(one_second);
+                }
             }
         }
     }
@@ -476,7 +491,6 @@ fn main() {
                 
                 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);
                 }