examples: update vcasino.v (#5880)
parent
938e71b468
commit
d820a97c83
|
@ -1,14 +1,13 @@
|
|||
import rand
|
||||
import time
|
||||
import os
|
||||
|
||||
const (
|
||||
help_text = ' Usage:\t./VCasino\n
|
||||
Description:\n VCasino is a little game only made to learn V.\n'
|
||||
g_desc = ' The object of Roulette is to pick the number where the spinning ball will land on the wheel.
|
||||
If your number is the good one, you\'ll get your bet x3.
|
||||
If your number is the same color as the ball one, you\'ll get your bet /2.
|
||||
Otherwise, you will lose your bet.\n'
|
||||
g_desc = " The object of Roulette is to pick the number where the spinning ball will land on the wheel.
|
||||
If your number is the good one, you'll get your bet x3.
|
||||
If your number is the same color as the ball one, you'll get your bet /2.
|
||||
Otherwise, you will lose your bet.\n"
|
||||
odd = 'red'
|
||||
even = 'black'
|
||||
)
|
||||
|
@ -69,7 +68,7 @@ fn get_bet_nbr() int {
|
|||
fn get_bet(money int) int {
|
||||
mut bet := -1
|
||||
for bet <= 0 || bet > money {
|
||||
println('You\'ve $money V. Type in the amount of your bet:')
|
||||
println('You have $money V. Type in the amount of your bet:')
|
||||
line := os.get_line().trim_space()
|
||||
if line.len < 1 {
|
||||
println('error: empty line.')
|
||||
|
@ -90,7 +89,7 @@ fn get_bet(money int) int {
|
|||
return bet
|
||||
}
|
||||
|
||||
fn run_wheel(bet_nbr int, _bet int) int {
|
||||
fn run_wheel(bet_nbr, _bet int) int {
|
||||
mut bet := _bet
|
||||
winning_nbr := rand.intn(50)
|
||||
print('Roulette Wheel spinning... and stops on the number $winning_nbr which is a ')
|
||||
|
@ -114,23 +113,21 @@ fn run_wheel(bet_nbr int, _bet int) int {
|
|||
|
||||
fn is_broke(money int) bool {
|
||||
if money <= 0 {
|
||||
println('You\'re broke, the game is over..')
|
||||
println("You're broke, the game is over..")
|
||||
return false
|
||||
} else {
|
||||
}
|
||||
quit := Options{'yes', 'y'}
|
||||
println('You\'ve $money V. Do you want to quit the casino with your winnings? (y/n)')
|
||||
println('You have $money V. Do you want to quit the casino with your winnings? (y/n)')
|
||||
line := os.get_line().trim_space().to_lower()
|
||||
if line == quit.long_opt || line == quit.short_opt {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fn game_loop() {
|
||||
mut can_play := true
|
||||
mut money := 1000
|
||||
|
||||
println(g_desc)
|
||||
println('You start the game with $money V.\n')
|
||||
for can_play {
|
||||
|
@ -142,10 +139,8 @@ fn game_loop() {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
if os.args.len >= 2 {
|
||||
if option_parser() {
|
||||
if os.args.len >= 2 && option_parser() {
|
||||
return
|
||||
}
|
||||
}
|
||||
game_loop()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue