Browse Source

Fixed enter advancing main loop

spesk1 5 years ago
parent
commit
b17e763f1b
2 changed files with 27 additions and 18 deletions
  1. 3 3
      README.md
  2. 24 15
      src/main.rs

+ 3 - 3
README.md

@@ -4,8 +4,8 @@ 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- DONE
-* -Implement "head stash" to store money/drugs in case of arrest- DONE
+* ~~Get arrested by the cops, lose money/drugs~~ DONE
+* ~~Implement "head stash" to store money/drugs in case of arrest~~ DONE
 
 Bugs:
-* Hitting enter advances the main loop, not intended behavior
+* Need to find some more

+ 24 - 15
src/main.rs

@@ -397,7 +397,6 @@ fn cops_event(player: &mut Player) {
         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);
@@ -432,6 +431,9 @@ fn cops_event(player: &mut Player) {
             }
         }
     }
+
+    thread::sleep(one_second);
+    thread::sleep(one_second);
 }
 
 ////////////////////////////////////////
@@ -659,20 +661,6 @@ fn main() {
             while ! main_loop {
                 clear_term();
                 
-                let mut rng = rand::thread_rng();
-                let event_chance = rng.gen_range(0,9);
-                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;
@@ -706,6 +694,27 @@ fn main() {
                     go_to_location(&mut player, &mut market);
                     player.debt_interest();
                     player.decrease_loan_timer(1);
+
+                    // Only have events trigger after 'jetting'
+                    let mut rng = rand::thread_rng();
+                    let event_chance = rng.gen_range(0,9);
+                    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;
+                    }
+
                 } else if action.contains("loanshark") {
                     loan_shark(&mut player);
                 } else if action.contains("headstash") {