examples: update vcasino.v (#5880)

pull/5941/head
Iman 2020-07-22 22:15:55 +04:30 committed by GitHub
parent 938e71b468
commit d820a97c83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 107 additions and 112 deletions

View File

@ -1,14 +1,13 @@
import rand import rand
import time
import os import os
const ( const (
help_text = ' Usage:\t./VCasino\n help_text = ' Usage:\t./VCasino\n
Description:\n VCasino is a little game only made to learn V.\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. 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 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. If your number is the same color as the ball one, you'll get your bet /2.
Otherwise, you will lose your bet.\n' Otherwise, you will lose your bet.\n"
odd = 'red' odd = 'red'
even = 'black' even = 'black'
) )
@ -69,7 +68,7 @@ fn get_bet_nbr() int {
fn get_bet(money int) int { fn get_bet(money int) int {
mut bet := -1 mut bet := -1
for bet <= 0 || bet > money { 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() line := os.get_line().trim_space()
if line.len < 1 { if line.len < 1 {
println('error: empty line.') println('error: empty line.')
@ -90,7 +89,7 @@ fn get_bet(money int) int {
return bet return bet
} }
fn run_wheel(bet_nbr int, _bet int) int { fn run_wheel(bet_nbr, _bet int) int {
mut bet := _bet mut bet := _bet
winning_nbr := rand.intn(50) winning_nbr := rand.intn(50)
print('Roulette Wheel spinning... and stops on the number $winning_nbr which is a ') 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 { fn is_broke(money int) bool {
if money <= 0 { if money <= 0 {
println('You\'re broke, the game is over..') println("You're broke, the game is over..")
return false return false
} else { }
quit := Options{'yes', 'y'} 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() line := os.get_line().trim_space().to_lower()
if line == quit.long_opt || line == quit.short_opt { if line == quit.long_opt || line == quit.short_opt {
return false return false
} }
}
return true return true
} }
fn game_loop() { fn game_loop() {
mut can_play := true mut can_play := true
mut money := 1000 mut money := 1000
println(g_desc) println(g_desc)
println('You start the game with $money V.\n') println('You start the game with $money V.\n')
for can_play { for can_play {
@ -142,10 +139,8 @@ fn game_loop() {
} }
fn main() { fn main() {
if os.args.len >= 2 { if os.args.len >= 2 && option_parser() {
if option_parser() {
return return
} }
}
game_loop() game_loop()
} }