I originally wanted to write some shell scripts to train the trainer. I just wanted to give it a guess. so there will be a follow-up event. the most primitive guess script was first written. both functionality and aesthetics are unsatisfactory. Therefore, one version is updated iteratively, and the subsequent versions are better than the previous ones.
Through this script exercise, I understand the truth that "you cannot eat hot tofu in a hurry" remains the same. Whether you start a business or do some practical work, you can start from scratch, anyone who is proud to make perfect products at one time is impractical. good products must be refined and iterated based on user needs to withstand more severe challenges.
Guess the original digital game V1
# Given an unchangeable two-digit number, the user enters a number, the program prompts the size, follow the prompts to continue the input, until the correct number is entered, the game ends.
#!/bin/bashnum="32"while truedoread -p "Please input a "double-digit": " inputif [ $input -gt $num ] ; then echo "Try smaller!" elif [ $input -lt $num ];then echo "Try bigger!" else echo "Good! You are right!" break;fidone
Guess digital game ultimate v2
#!/bin/bashNUM=`echo $RANDOM$RANDOM |cut -c 2-3`while truedo read -p "Please input a "double-digit": " input case $input in [0-9][0-9] ) if [ $input -gt $NUM ] ;then echo "Try smaller!" elif [ $input -lt $NUM ];then echo "Try bigger!" else echo "Good! You are right!" break; fi ;; *) read -p "Please input a "double-digit": " input ;; esacdone
Guess digital game ultimate v3
The Count statistics function is added.
Adds the top 10 rankings in history.
Added the time display function.
The optimization result is displayed.
#!/bin/bashNUM=`echo $RANDOM$RANDOM |cut -c 2-3`DATE=`date +%y%m%d-%H:%M`read -p "Please input your name: " USERwhile truedo read -p "Please input a "double-digit": " inputi=$((i+1)) case $input in [0-9][0-9] ) if [ $input -gt $NUM ] ;then echo "Try smaller!" elif [ $input -lt $NUM ];then echo "Try bigger!" else echo "Good! You are right!" break; fi ;; *) read -p "Please input a "double-digit": " input ;; esacdoneprintf "%-12s %s\n" "<$USER>" "your record is $i! Try better next time! $DATE" |tee -a ./record.recordprintf "\n\n"printf "%15s %6s %-8s\n" "-----" "HISTORY RECORD" "-----"cat ./record.record |sort -k5 -g|awk -F! ‘{print $1,"!",$3}‘|head -10printf "%15s %6s %-8s\n" "-----" "HISTORY RECORD" "-----"
This article is from the statby blog, please be sure to keep this source http://statby.blog.51cto.com/7588140/1554538
Game Development History (shell digital games)