basic loop done

- print check tODO
This commit is contained in:
Uğur Küpeli
2022-05-08 13:27:05 +03:00
parent d566a7df48
commit cd7ed8c3fb
2 changed files with 66 additions and 4 deletions

View File

@@ -35,9 +35,9 @@ fn main() {
let msg = format!("NUMBER {}?", i);
let bet_input =
morristown::prompt_multi_number::<usize>(msg.as_str(), ",", Some((2, 2)));
let (num, bet) = (bet_input[0], bet_input[1]);
let (bet_num, wager) = (bet_input[0], bet_input[1]);
if num <= 50 && bet < 500 && bet <= player && bet > 0 {
if bet_num > 0 && bet_num <= 50 && wager > 5 && wager < 500 && wager <= player {
bets.push(bet_input);
} else if bets.contains(&bet_input) {
println!("YOU MADE THAT BET ONCE ALREADY, DUM-DUM");
@@ -51,6 +51,35 @@ fn main() {
println!("\nSPINNING");
let spin: u8 = rand::thread_rng().gen_range(1..=38);
let color = if util::REDS.contains(&spin) {
"RED"
} else {
"BLACK"
};
println!("\n{} {}", spin, color);
for (i, bet) in bets.iter().enumerate() {
let (bet_num, wager) = (bet[0] as u8, bet[1]);
let (win, payoff) = util::process_bet(bet_num, spin);
let msg = if win {
let wager = wager * payoff as usize;
player += wager;
house -= wager;
"WIN"
} else {
player -= wager;
house += wager;
"LOSE"
};
println!("YOU {msg} {wager} DOLLARS ON BET {}", i + 1);
}
println!("TOTALS\tME\tYOU");
println!("\t\t{house}\t{player}");
if player <= 0 {
println!("OOPS! YOU JUST SPENT YOUR LAST DOLLAR");
println!("THANKS FOR YOUR MONEY");

View File

@@ -1,3 +1,5 @@
use std::ops::RangeInclusive;
pub const INSTRUCTIONS: [&str; 38] = [
"\nTHIS IS THE BETTING LAYOUT",
"\n(*=RED)\n",
@@ -39,8 +41,39 @@ pub const INSTRUCTIONS: [&str; 38] = [
"MINIMUM BET IS $5,MAXIMUM IS $500\n",
];
pub const REDS: [u8; 18] = [
1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36,
];
pub fn print_check(money: usize) {
let name = morristown::prompt_string("TO WHOM SHALL I MAKE THE CHECK?");
let check_no; // random
/*PRINT THE CHECK */
//let _check_no; // random
/*PRINT THE CHECK */
todo!()
}
pub fn process_bet(bet_num: u8, spin: u8) -> (bool, u8) {
match bet_num {
1..=36 => (bet_num == spin, 35),
37 => (is_within_range(1..=12, spin), 2),
38 => (is_within_range(13..=24, spin), 2),
39 => (is_within_range(25..=36, spin), 2),
40 => (spin % 3 == 1, 2),
41 => (spin % 3 == 2, 2),
42 => (spin % 3 == 0, 2),
43 => (is_within_range(1..=18, spin), 1),
44 => (is_within_range(19..=36, spin), 1),
45 => (spin % 2 == 0, 1),
46 => (spin % 2 == 1, 1),
47 => (REDS.contains(&spin), 1),
48 => (!REDS.contains(&spin), 1),
_ => {
println!("##INVALID BET##");
return (false, 0);
}
}
}
fn is_within_range(r: RangeInclusive<u8>, n: u8) -> bool {
r.contains(&n)
}