Shell脚本实现猜数字游戏
本文实例为大家分享了Shell实现猜数字游戏的具体代码,供大家参考,具体内容如下
这里的guem可以随便写,比如A、B之类的也可以
vim guem.sh
编辑脚本
#!/bin/bash init() { echo " 猜数字游戏!!! " } game() { number=$[$RANDOM%100] while : do read -p "输入你要猜测的数字: " n1 n2=`echo $n1 | sed 's/[0-9]//g'` if [ ! -z $n2 ] then echo "你输入的不是一个数字." continue fi if [ $n1 == $number ] then echo "你猜对了." read -p "你还想再玩一次么?(yes/no)" an1 while true do case $an1 in yes) game break ;; no) break ;; *) exit esac done break #!/bin/bash init() { echo " " echo " 猜数字游戏!!! " } game() { number=$[$RANDOM%100] while : do read -p "输入你要猜测的数字: " n1 n2=`echo $n1 | sed 's/[0-9]//g'` if [ ! -z $n2 ] then echo "你输入的不是一个数字." continue fi if [ $n1 == $number ] then echo "你猜对了." read -p "你还想再玩一次么?(yes/no)" an1 while true do case $an1 in yes) game break ;; no) break ;; *) exit esac done break break ;; no) break ;; *) exit esac done break elif [ $n1 -gt $number ] then echo "猜大了." continue else echo "猜小了." continue fi done } while true do init echo "1: 开始游戏 " echo "0: 退出游戏 " read -p " 请输入 0或者1:" NUM case $NUM in 1) game break ;; 0) break ;; esac done
相关推荐
libao 2020-09-16
xiaonamylove 2020-08-16
yoshubom 2020-07-18
Zaratustra 2020-07-18
赵家小少爷 2020-07-18
CARBON 2020-06-08
firefaith 2020-06-14
CARBON 2020-06-14
流年浅滩 2020-05-26
CARBON 2020-05-18
xiaobater 2020-04-29
gcong 2020-04-10
酷云的csdn 2020-03-25
onetozero 2020-03-08
SciRui 2020-02-21
higheels 2020-02-13
fendou00sd 2020-01-29