Shell script game: scissors stone Cloth

Source: Internet
Author: User
Tags case statement

#!/bin/bash#author: The Adventures of Tintin (Jacob) #定义数组, save all the possibilities of Punch game= (stone   scissors   cloth) num=$[random%3]computer=${game[$num]}# Get the punch of a computer by random number # The possibility of a punch is saved in an array, game[0],game[1],game[2] is 3 different possible  echo  "Please choose your punch gesture according to the following tips" echo  "1. Stone "echo " 2. Scissors "echo " 3. Cloth " read  -p  " Please select 1-3: "  person# prompts the user to punch, According to the prompt Punch can be # again through the case statement to determine whether the user input value is 1 or 2 or 3, according to different inputs to determine the different results case   $person   in1)         if [  $num  -eq 0 ];then               echo  "Draw"        elif  [  $num  -eq 1 ];then               echo  "You Win"        else               echo  "Computer wins"         fi;; 2)    &NBsp;       if [  $num  -eq 0 ];then               echo  "Computer wins"         elif [  $num  -eq 1 ];then               echo  "Draw"        else               echo  "You Win"         fi;; 3)        if [  $num  -eq 0 ];then               echo  "You Win"         elif [  $num  -eq 1 ];then               echo  "Computer Win"        ELSE&NBsp;             echo  "Draw"         fi;; *)        echo  "must enter 1-3 number" Esac

This article is from the "Ding Ding Adventures" blog, please be sure to keep this source http://manual.blog.51cto.com/3300438/1967775

Shell script game: scissors stone Cloth

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.