main.rs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. use std::io;
  2. use rand::Rng;
  3. use std::{thread, time};
  4. //////////
  5. // Objects
  6. //////////
  7. struct Market {
  8. // Store current values of drugs on the market
  9. weed: u32,
  10. cocaine: u32,
  11. heroin: u32,
  12. acid: u32,
  13. xtc: u32,
  14. ludes: u32,
  15. }
  16. impl Market {
  17. pub fn new(weed: u32, cocaine: u32, heroin: u32, acid: u32, xtc: u32, ludes: u32) -> Self {
  18. Market { weed, cocaine, heroin, acid, xtc, ludes }
  19. }
  20. // This is normal market fluctuation when moving locations, as opposed to an event that drives prices up/down
  21. pub fn change_prices(&mut self) {
  22. let mut rng = rand::thread_rng();
  23. let weed_diff = rng.gen_range(90,600);
  24. let cocaine_diff = rng.gen_range(19000,40000);
  25. let heroin_diff = rng.gen_range(7000,20000);
  26. let acid_diff = rng.gen_range(300,1500);
  27. let xtc_diff = rng.gen_range(50,500);
  28. let ludes_diff = rng.gen_range(15,190);
  29. self.weed = weed_diff;
  30. self.cocaine = cocaine_diff;
  31. self.heroin = heroin_diff;
  32. self.acid = acid_diff;
  33. self.xtc = xtc_diff;
  34. self.ludes = ludes_diff;
  35. }
  36. pub fn dump(&self) {
  37. println!("Prices\nWeed: ${}\tCocaine: ${}\nHeroin: ${}\tAcid: ${}\nXTC: ${}\tLudes: ${}\n", self.weed, self.cocaine, self.heroin, self.acid, self.xtc, self.ludes);
  38. }
  39. }
  40. struct HeadStash {
  41. weed: u32,
  42. cocaine: u32,
  43. heroin: u32,
  44. acid: u32,
  45. xtc: u32,
  46. ludes: u32,
  47. money: u32,
  48. }
  49. impl HeadStash {
  50. pub fn new(weed: u32, cocaine: u32, heroin: u32, acid: u32, xtc: u32, ludes: u32, money: u32) -> Self {
  51. HeadStash { weed, cocaine, heroin, acid, xtc, ludes, money }
  52. }
  53. pub fn dump(&self) {
  54. println!("You've got ${} in your head stash",self.money);
  55. println!("You're head stash has:\nWeed: {} Cocaine: {}\nHeroin: {} Acid: {}\nXTC: {} Ludes: {}\n", self.weed, self.cocaine, self.heroin, self.acid, self.xtc, self.ludes);
  56. }
  57. pub fn move_drug_to_stash(&mut self, drug_to_move: &String, amount_to_move: &u32) {
  58. match drug_to_move.as_ref() {
  59. "weed" => self.weed += amount_to_move,
  60. "cocaine" => self.cocaine += amount_to_move,
  61. "heroin" => self.heroin += amount_to_move,
  62. "acid" => self.acid += amount_to_move,
  63. "xtc" => self.xtc += amount_to_move,
  64. "ludes" => self.ludes += amount_to_move,
  65. _ => panic!("move_drug_to_stash got a drug_to_move value that doesn't make sense"),
  66. }
  67. }
  68. pub fn grab_from_stash(&mut self, drug_to_grab: &String, amount_to_grab: &u32) {
  69. match drug_to_grab.as_ref() {
  70. "weed" => self.weed -= amount_to_grab,
  71. "cocaine" => self.cocaine -= amount_to_grab,
  72. "heroin" => self.heroin -= amount_to_grab,
  73. "acid" => self.acid -= amount_to_grab,
  74. "xtc" => self.xtc -= amount_to_grab,
  75. "ludes" => self.ludes -= amount_to_grab,
  76. _ => panic!("sell_transaction got a drug_to_sell value that doesn't make sense"),
  77. }
  78. }
  79. pub fn bank_stash(&mut self, amount_to_bank: &u32) {
  80. self.money += amount_to_bank;
  81. }
  82. pub fn withdraw_stash(&mut self, amount_to_withdraw: &u32) {
  83. self.money -= amount_to_withdraw;
  84. }
  85. pub fn get_head_stash_amount(&self, drug: &String) -> u32 {
  86. let amount;
  87. match drug.as_ref() {
  88. "weed" => amount = self.weed,
  89. "cocaine" => amount = self.cocaine,
  90. "heroin" => amount = self.heroin,
  91. "acid" => amount = self.acid,
  92. "xtc" => amount = self.xtc,
  93. "ludes" => amount = self.ludes,
  94. _ => amount = 0,
  95. }
  96. return amount;
  97. }
  98. }
  99. struct Player {
  100. health: u32,
  101. money: u32,
  102. debt: u32,
  103. weed: u32,
  104. cocaine: u32,
  105. heroin: u32,
  106. acid: u32,
  107. xtc: u32,
  108. ludes: u32,
  109. location: String,
  110. loan_timer: u32,
  111. stash_size: u32,
  112. }
  113. // TODO
  114. // A lot of the functions for Player duplicate code, need to make some "generic" functions
  115. impl Player {
  116. 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 {
  117. Player { health, money, debt, weed, cocaine, heroin, acid, xtc, ludes, location, loan_timer, stash_size }
  118. }
  119. pub fn dump(&self) {
  120. println!("Health: {}\nMoney: ${}\tDebt: ${}", self.health, self.money, self.debt);
  121. println!("You're in {}\n", self.location);
  122. println!("You can hold {} units in your stash",self.stash_size);
  123. println!("You're holding:\nWeed: {} Cocaine: {}\nHeroin: {} Acid: {}\nXTC: {} Ludes: {}\n", self.weed, self.cocaine, self.heroin, self.acid, self.xtc, self.ludes);
  124. }
  125. pub fn change_location(&mut self, new_location: String) {
  126. self.location = new_location;
  127. }
  128. pub fn get_stash_amount(&self, drug: &String) -> u32 {
  129. let amount;
  130. match drug.as_ref() {
  131. "weed" => amount = self.weed,
  132. "cocaine" => amount = self.cocaine,
  133. "heroin" => amount = self.heroin,
  134. "acid" => amount = self.acid,
  135. "xtc" => amount = self.xtc,
  136. "ludes" => amount = self.ludes,
  137. _ => amount = 0,
  138. }
  139. return amount;
  140. }
  141. pub fn buy_transaction(&mut self, drug_to_buy: &String, amount_to_buy: &u32, market_price: &u32) {
  142. let cost = market_price * amount_to_buy;
  143. self.money -= cost;
  144. let add_amount = amount_to_buy;
  145. self.gain_drug(&drug_to_buy,&add_amount);
  146. }
  147. pub fn sell_transaction(&mut self, drug_to_sell: &String, amount_to_sell: &u32, market_price: &u32) {
  148. let revenue = market_price * amount_to_sell;
  149. self.lose_drug(&drug_to_sell,&amount_to_sell);
  150. self.money += revenue;
  151. }
  152. pub fn debt_interest(&mut self) {
  153. let interest_amount: u32;
  154. match self.debt {
  155. 0 => interest_amount = 0,
  156. _ => interest_amount = ( self.debt as f32 * 0.2 ) as u32,
  157. }
  158. self.debt += interest_amount;
  159. }
  160. pub fn remove_debt(&mut self, payback_amount: u32) {
  161. if (self.debt as i32 - payback_amount as i32) < 0 {
  162. self.money -= payback_amount;
  163. self.debt = 0;
  164. } else {
  165. self.money -= payback_amount;
  166. self.debt -= payback_amount;
  167. }
  168. }
  169. pub fn borrow_from_shark(&mut self, borrow_amount: u32) {
  170. self.money += borrow_amount;
  171. self.debt += borrow_amount;
  172. }
  173. pub fn take_damage(&mut self, damage_amount: u32) {
  174. if (self.health as i32 - damage_amount as i32) < 0 {
  175. self.health = 0;
  176. } else {
  177. self.health -= damage_amount;
  178. }
  179. }
  180. pub fn decrease_loan_timer(&mut self, timer_amount: u32) {
  181. if (self.loan_timer as i32 - timer_amount as i32) < 0 {
  182. self.loan_timer = 0;
  183. } else {
  184. self.loan_timer -= timer_amount;
  185. }
  186. }
  187. pub fn increase_loan_timer(&mut self, timer_amount: u32) {
  188. self.loan_timer += timer_amount;
  189. }
  190. pub fn buy_trenchcoat(&mut self, cost: u32) {
  191. self.stash_size += 25;
  192. self.money -= cost;
  193. }
  194. pub fn buy_body_armor(&mut self, cost: u32) {
  195. self.health += 2;
  196. self.money -= cost;
  197. }
  198. pub fn stash_fill(&self) -> u32 {
  199. let stash_fill = self.weed + self.cocaine + self.heroin + self.xtc + self.acid + self.ludes;
  200. return stash_fill;
  201. }
  202. pub fn holding(&self) -> bool {
  203. if self.stash_fill() == 0 {
  204. return false;
  205. } else {
  206. return true;
  207. }
  208. }
  209. pub fn arrested(&mut self) {
  210. self.money = 0;
  211. self.weed = 0;
  212. self.cocaine = 0;
  213. self.heroin = 0;
  214. self.xtc = 0;
  215. self.acid = 0;
  216. self.ludes = 0;
  217. }
  218. pub fn lose_money(&mut self, amount: &u32) {
  219. self.money -= amount;
  220. }
  221. pub fn gain_money(&mut self, amount: &u32) {
  222. self.money += amount;
  223. }
  224. pub fn lose_drug(&mut self, drug: &String, amount: &u32) {
  225. match drug.as_ref() {
  226. "weed" => self.weed -= amount,
  227. "cocaine" => self.cocaine -= amount,
  228. "heroin" => self.heroin -= amount,
  229. "acid" => self.acid -= amount,
  230. "xtc" => self.xtc -= amount,
  231. "ludes" => self.ludes -= amount,
  232. _ => panic!("lose_drug got a drug value that doesn't make sense"),
  233. }
  234. }
  235. pub fn gain_drug(&mut self, drug: &String, amount: &u32) {
  236. match drug.as_ref() {
  237. "weed" => self.weed += amount,
  238. "cocaine" => self.cocaine += amount,
  239. "heroin" => self.heroin += amount,
  240. "acid" => self.acid += amount,
  241. "xtc" => self.xtc += amount,
  242. "ludes" => self.ludes += amount,
  243. _ => panic!("lose_drug got a drug value that doesn't make sense"),
  244. }
  245. }
  246. }
  247. ////////////////////////////////////////////////////////
  248. // "Low-level" Fuctions, called by "Top-level" functions
  249. ////////////////////////////////////////////////////////
  250. fn prompt(prompt_text: String) -> io::Result<String> {
  251. println!("$ {}",prompt_text);
  252. let mut input = String::new();
  253. std::io::stdin().read_line(&mut input)?;
  254. let value: String = input.trim().parse().unwrap();
  255. Ok(value)
  256. }
  257. // This hurts portability but works for now
  258. fn clear_term() {
  259. print!("{}[2J", 27 as char);
  260. }
  261. fn get_drug_market_value(drug_to_buy: &String, market: &Market) -> io::Result<u32> {
  262. let market_value: u32;
  263. match drug_to_buy.as_ref() {
  264. "weed" => market_value = market.weed,
  265. "cocaine" => market_value = market.cocaine,
  266. "heroin" => market_value = market.heroin,
  267. "acid" => market_value = market.acid,
  268. "xtc" => market_value = market.xtc,
  269. "ludes" => market_value = market.ludes,
  270. _ => panic!("get_drug_market_value got a drug_to_buy value that doesn't make sense!"),
  271. }
  272. Ok(market_value)
  273. }
  274. // This is maybe stupid? Or could be more idomatic ?? TODO?
  275. // This honestly might not even be needed? Don't really
  276. // understand why I made this
  277. // May should use match inside of let ?
  278. fn get_drug_as_string(drug: &String) -> io::Result<String> {
  279. let mut drug_as_string: String;
  280. match drug.as_ref() {
  281. "weed" => drug_as_string = "weed".to_string(),
  282. "cocaine" => drug_as_string = "cocaine".to_string(),
  283. "heroin" => drug_as_string = "heroin".to_string(),
  284. "acid" => drug_as_string = "acid".to_string(),
  285. "xtc" => drug_as_string = "xtc".to_string(),
  286. "ludes" => drug_as_string = "ludes".to_string(),
  287. _ => drug_as_string = "null".to_string(),
  288. }
  289. Ok(drug_as_string)
  290. }
  291. ////////////////////////////////////
  292. // Events -- happen randomly in main
  293. ////////////////////////////////////
  294. fn trenchcoat_event(player: &mut Player) {
  295. let mut relative_cost = ( player.money as f64 * 0.25 ) as u32;
  296. if relative_cost < 200 {
  297. relative_cost = 200;
  298. }
  299. println!("A guy is selling his trench count, it'll allow you to carry 25 more units, want to buy it for ${} ?", relative_cost);
  300. println!("You have ${}", player.money);
  301. let response = prompt("Yes/no?".to_string()).unwrap();
  302. if response.contains("yes") {
  303. if player.money < relative_cost {
  304. println!("You cant afford this!");
  305. } else {
  306. player.buy_trenchcoat(relative_cost);
  307. }
  308. }
  309. }
  310. fn body_armor_event(player: &mut Player) {
  311. let mut relative_cost = ( player.money as f64 * 0.3 ) as u32;
  312. if relative_cost < 300 {
  313. relative_cost = 300;
  314. }
  315. println!("A guy is selling some body armor, it'll increase your health by 2, want to buy it for ${} ?", relative_cost);
  316. println!("You have ${}", player.money);
  317. let response = prompt("Yes/no?".to_string()).unwrap();
  318. if response.contains("yes") {
  319. if player.money < relative_cost {
  320. println!("You cant afford this!");
  321. } else {
  322. player.buy_body_armor(relative_cost);
  323. }
  324. }
  325. }
  326. fn cops_event(player: &mut Player) {
  327. let one_second = time::Duration::from_secs(1);
  328. if ! player.holding() {
  329. println!("The cops found you, but you're not holding so it's chill.");
  330. thread::sleep(one_second);
  331. thread::sleep(one_second);
  332. } else {
  333. println!("The cops found you! Run!");
  334. thread::sleep(one_second);
  335. let mut rng = rand::thread_rng();
  336. let mut escape: u32;
  337. let mut hit: u32;
  338. let mut done = false;
  339. while ! done {
  340. escape = rng.gen_range(0,5);
  341. hit = rng.gen_range(0,3);
  342. if escape == 0 {
  343. println!("You got away!");
  344. thread::sleep(one_second);
  345. done = true;
  346. } else {
  347. println!("You cant get away, the cops are firing!");
  348. thread::sleep(one_second);
  349. if hit == 0 {
  350. println!("You're hit for 4 damage!");
  351. player.take_damage(4);
  352. thread::sleep(one_second);
  353. let arrest = rng.gen_range(0,1);
  354. if arrest == 0 {
  355. println!("The cops got you! They confiscate your cash and stash!");
  356. player.arrested();
  357. done = true;
  358. }
  359. } else {
  360. println!("They miss and you keep running!");
  361. thread::sleep(one_second);
  362. }
  363. }
  364. }
  365. }
  366. thread::sleep(one_second);
  367. thread::sleep(one_second);
  368. }
  369. ////////////////////////////////////////
  370. // "Top-level" Functions, called by main
  371. ////////////////////////////////////////
  372. fn go_to_location(player: &mut Player, market: &mut Market) {
  373. let mut loc_loop = false;
  374. while ! loc_loop {
  375. let mut new_location = prompt("Select a new location, locations are\nBrooklyn Midtown Harlem CentralPark".to_string()).unwrap();
  376. match new_location.as_ref() {
  377. "Brooklyn" => println!("Going to Brooklyn"),
  378. "Midtown" => println!("Going to Midtown"),
  379. "Harlem" => println!("Going to Harlem"),
  380. "CentralPark" => println!("Going to CentralPark"),
  381. _ => new_location = "null".to_string(),
  382. }
  383. if new_location != "null".to_string() {
  384. if new_location == player.location {
  385. println!("Youre already in {}", player.location);
  386. } else {
  387. player.change_location(new_location);
  388. market.change_prices();
  389. loc_loop = true;
  390. }
  391. } else {
  392. println!("Not a valid location, try again");
  393. }
  394. }
  395. }
  396. fn buy_drugs(player: &mut Player, market: &mut Market) {
  397. let mut done = false;
  398. let mut drug_to_buy: String = String::new();
  399. while ! done {
  400. drug_to_buy = prompt("What drug will you buy?".to_string()).unwrap();
  401. drug_to_buy = get_drug_as_string(&drug_to_buy).unwrap();
  402. if drug_to_buy != "null".to_string() {
  403. done = true;
  404. } else {
  405. println!("Try again");
  406. }
  407. }
  408. let mut done1 = false;
  409. while ! done1 {
  410. let drug_market_value: u32 = get_drug_market_value(&drug_to_buy, &market).unwrap();
  411. let affordable_amount: u32 = (player.money / drug_market_value) as u32;
  412. println!("You can afford {} {}", affordable_amount, drug_to_buy);
  413. let amount_to_buy = prompt("How many will you buy?".to_string()).unwrap();
  414. let amount_to_buy_int: u32 = amount_to_buy.parse().unwrap();
  415. let current_stash_fill = player.stash_fill();
  416. if amount_to_buy_int > affordable_amount {
  417. println!("You cant afford that many");
  418. } else if amount_to_buy_int > player.stash_size {
  419. println!("You cant hold that much!");
  420. } else if (amount_to_buy_int + current_stash_fill) > player.stash_size {
  421. println!("You cant hold that much!");
  422. } else {
  423. println!("Buying {} {}", amount_to_buy_int, drug_to_buy);
  424. player.buy_transaction(&drug_to_buy,&amount_to_buy_int,&drug_market_value);
  425. done1 = true;
  426. }
  427. }
  428. }
  429. fn sell_drugs(player: &mut Player, market: &mut Market) {
  430. let mut done = false;
  431. let mut drug_to_sell: String = String::new();
  432. while ! done {
  433. drug_to_sell = prompt("What drug will you sell?".to_string()).unwrap();
  434. drug_to_sell = get_drug_as_string(&drug_to_sell).unwrap();
  435. if drug_to_sell != "null".to_string() {
  436. done = true;
  437. } else {
  438. println!("Try again");
  439. }
  440. }
  441. let mut done1 = false;
  442. let mut amount_to_sell: String;
  443. while ! done1 {
  444. amount_to_sell = prompt("How many to sell?".to_string()).unwrap();
  445. let amount_to_sell_int: u32 = amount_to_sell.parse().unwrap();
  446. let drug_market_value: u32 = get_drug_market_value(&drug_to_sell, &market).unwrap();
  447. let amount_possible_to_sell: u32 = player.get_stash_amount(&drug_to_sell);
  448. if amount_to_sell_int > amount_possible_to_sell {
  449. println!("You don't have that many {}, try again", drug_to_sell);
  450. } else {
  451. println!("Selling {} {}", amount_to_sell_int, drug_to_sell);
  452. player.sell_transaction(&drug_to_sell,&amount_to_sell_int,&drug_market_value);
  453. done1 = true;
  454. }
  455. }
  456. }
  457. fn loan_shark(player: &mut Player) {
  458. if player.location != "Brooklyn".to_string() {
  459. println!("Can only talk to the loanshark in Brooklyn");
  460. } else {
  461. let mut loan_done = false;
  462. while ! loan_done {
  463. let action = prompt("What do you want to do? (borrow,repay)".to_string()).unwrap();
  464. if action.contains("repay") {
  465. let payback_amount: u32 = prompt("How much to pay back?".to_string()).unwrap().parse().unwrap();
  466. if payback_amount > player.money {
  467. println!("You dont have that much money");
  468. } else {
  469. player.remove_debt(payback_amount);
  470. println!("You now owe the loanshark: ${}", player.debt);
  471. loan_done = true;
  472. }
  473. } else if action.contains("borrow") {
  474. let borrow_amount = prompt("How much do you want to borrow? (Limit 20000)".to_string()).unwrap().parse().unwrap();
  475. if borrow_amount > 20000 {
  476. println!("You cant borrow that much");
  477. } else {
  478. player.borrow_from_shark(borrow_amount);
  479. loan_done = true;
  480. }
  481. }
  482. }
  483. }
  484. }
  485. fn head_stash_op(player: &mut Player, head_stash: &mut HeadStash) {
  486. if player.location != "Brooklyn".to_string() {
  487. println!("Your head stash is in Brooklyn");
  488. } else {
  489. let mut head_stash_done = false;
  490. while ! head_stash_done {
  491. let action = prompt("What do you want to do? (bank,withdraw)".to_string()).unwrap();
  492. if action.contains("bank") {
  493. let bank_type = prompt("What do you want to bank? (cash,drugs)".to_string()).unwrap();
  494. if bank_type.contains("cash") {
  495. let bank_amount: u32 = prompt("How much do you want to bank?".to_string()).unwrap().parse().unwrap();
  496. if bank_amount > player.money {
  497. println!("You don't have that much money on you!");
  498. } else {
  499. head_stash.bank_stash(&bank_amount);
  500. player.lose_money(&bank_amount);
  501. head_stash_done = true;
  502. }
  503. }
  504. if bank_type.contains("drugs") {
  505. let mut drug_type = prompt("What drug to you want to stash?".to_string()).unwrap();
  506. drug_type = get_drug_as_string(&drug_type).unwrap();
  507. if drug_type != "null".to_string() {
  508. let stash_amount: u32 = prompt("How much do you want to stash?".to_string()).unwrap().parse().unwrap();
  509. if stash_amount > player.get_stash_amount(&drug_type) {
  510. println!("You don't have that much in your stash!");
  511. } else {
  512. head_stash.move_drug_to_stash(&drug_type,&stash_amount);
  513. player.lose_drug(&drug_type,&stash_amount);
  514. head_stash_done = true;
  515. }
  516. } else {
  517. println!("Try again");
  518. }
  519. }
  520. }
  521. if action.contains("withdraw") {
  522. let withdraw_type = prompt("What do you want to withdraw? (cash,drugs)".to_string()).unwrap();
  523. if withdraw_type.contains("cash") {
  524. let withdraw_amount: u32 = prompt("How much do you want to withdraw?".to_string()).unwrap().parse().unwrap();
  525. if withdraw_amount > head_stash.money {
  526. println!("You don't have that much money in the stash!");
  527. } else {
  528. head_stash.withdraw_stash(&withdraw_amount);
  529. player.gain_money(&withdraw_amount);
  530. head_stash_done = true;
  531. }
  532. }
  533. if withdraw_type.contains("drugs") {
  534. let mut drug_type = prompt("What drug to you want to withdraw?".to_string()).unwrap();
  535. drug_type = get_drug_as_string(&drug_type).unwrap();
  536. if drug_type != "null".to_string() {
  537. let withdraw_amount: u32 = prompt("How much do you want to stash?".to_string()).unwrap().parse().unwrap();
  538. if withdraw_amount > head_stash.get_head_stash_amount(&drug_type) {
  539. println!("You dont have that much {} in your stash!",&drug_type);
  540. } else {
  541. head_stash.grab_from_stash(&drug_type,&withdraw_amount);
  542. player.gain_drug(&drug_type,&withdraw_amount);
  543. head_stash_done = true;
  544. }
  545. } else {
  546. println!("Try again");
  547. }
  548. }
  549. }
  550. }
  551. }
  552. }
  553. ///////
  554. // Main
  555. ///////
  556. fn main() {
  557. let mut player = Player::new(10,2000,2050,0,0,0,0,0,0,"Brooklyn".to_string(),10,50);
  558. let mut market = Market::new(0,0,0,0,0,0);
  559. let mut head_stash = HeadStash::new(0,0,0,0,0,0,0);
  560. Market::change_prices(&mut market);
  561. let mut done = false;
  562. while ! done {
  563. let input = prompt("Type start, quit, or help".to_string()).unwrap();
  564. if input == "quit".to_string() {
  565. done = true;
  566. } else if input == "start".to_string() {
  567. println!("Starting the game");
  568. let mut main_loop = false;
  569. while ! main_loop {
  570. clear_term();
  571. if player.health == 0 {
  572. println!("You died! Game over!");
  573. main_loop = true;
  574. }
  575. if player.debt != 0 {
  576. if player.loan_timer == 0 {
  577. println!("** The loan shark wants his money! He beats you to a pulp to remind you! **");
  578. player.take_damage(2);
  579. player.increase_loan_timer(5);
  580. println!("** You take 2 damage! **");
  581. }
  582. }
  583. player.dump();
  584. head_stash.dump();
  585. market.dump();
  586. if player.location == "Brooklyn".to_string() {
  587. println!("You're currently in {}, what will you do? (buy,sell,jet,loanshark,headstash)",player.location);
  588. } else {
  589. println!("You're currently in {}, what will you do? (buy,sell,jet)",player.location);
  590. }
  591. let action = prompt("".to_string()).unwrap();
  592. if action.contains("buy") {
  593. buy_drugs(&mut player, &mut market);
  594. } else if action.contains("sell") {
  595. sell_drugs(&mut player, &mut market);
  596. } else if action.contains("jet") {
  597. go_to_location(&mut player, &mut market);
  598. player.debt_interest();
  599. player.decrease_loan_timer(1);
  600. // Only have events trigger after 'jetting'
  601. let mut rng = rand::thread_rng();
  602. let event_chance = rng.gen_range(0,9);
  603. if event_chance == 2 {
  604. trenchcoat_event(&mut player);
  605. }
  606. if event_chance == 1 {
  607. body_armor_event(&mut player);
  608. }
  609. if event_chance == 0 {
  610. cops_event(&mut player);
  611. }
  612. if player.health == 0 {
  613. println!("You died! Game over!");
  614. main_loop = true;
  615. }
  616. } else if action.contains("loanshark") {
  617. loan_shark(&mut player);
  618. } else if action.contains("headstash") {
  619. head_stash_op(&mut player, &mut head_stash);
  620. } else if action == "quit".to_string() {
  621. std::process::exit(0);
  622. }
  623. }
  624. }
  625. }
  626. }