Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Bash little script dice game

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

#! / 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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report