Get the App
SLTechnology News&Howtos  ›  Servers  › 

Bash little script dice game

Shulou Source: shulou.com Published: 2022-06-02 06:36:31 09月16日 Update

#! / bin/bash

Echo ">"

Choice='Big'

Balance=1000

Testtimes=3

While [$choice! = 'exit']

Do

Echo-e "Please choice Big or Small:"

Read choice

If [$choice = = 'exit']

Then

Exit 0

Fi

Echo-e "How much you wanna bet:"

Read amout

While [$balance-lt $amout]

Do

Echo "Enter amout is bigger than balance, try again!"

Read amout

Testtimes=$ [$testtimes-1]

If [$testtimes-eq 1]

Then

Exit-1

Fi

Done

Function roll_dice ()

{

Echo ">"

Number=3

Points=0

While ((number > 0))

Do

Point=$ (($RANDOM%6+1))

Echo $point

Number= `expr $number- 1`

Let "points+=$point"

Done

}

Roll_dice

Function caparoll_result ()

{

If [$points-le 18] & & [$points-ge 11]

Then

Result='Big'

Elif [$points-le 10] & & [$points-ge 3]

Then

Result='Small'

Else

Echo 'Error'

Exit-1

Fi

}

Caparoll_result $points

If [$choice = = 'Big'] | | [$choice = =' Small']

Then

If [$choice = = $result]

Then

Echo "The points are $points You win!"

Let "balance+=amout"

Echo "The gained $amout, You have $balance now!"

Else

Echo "The points are $points You lose!"

Let "balance-=amout"

Echo "The lost $amout, You have $balance now!"

Fi

Else

Echo "Invalid Words"

Fi

If [$balance-eq 0]

Then

Echo "Game Over!"

Exit 0

Fi

Done

Tags: Script dice Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MariaDB Redmi Apple vpn