您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關怎么在shell中打印國際象棋棋盤,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
代碼如下:
#!/bin/bash #set chess cell's width read -p "Please set the chess cell's width( two space width as unit ):" width if [[ $width =~ "^[0-9]+$" ]];then echo "wrong width setting, check your input and try again." exit fi let width=$width*2 #choose player's board cell color player="player1" PS3="Which color do you want to set for $player :" select choice in red green yellow blue purple cyan white;do case $REPLY in [1-7]) if [[ $player == player2 ]];then declare -i color2=$REPLY break else declare -i color1=$REPLY fi player="player2" PS3="Which color do you want to set for $player :" ;; *) ;; esac done if (( color1==color2 ));then echo "two player must choose different color, check your choice and try again." exit fi #print the chess board for (( i=0; i<4; i++ )); do for (( j=0; j<$width/2; j++ ));do for (( k=0; k<4; k++ ));do echo -e "\e[4${color1}m$(printf %${width}s)\e[0m\c" echo -e "\e[4${color2}m$(printf %${width}s)\e[0m\c" done echo done for (( j=0; j<$width/2; j++ ));do for (( k=0; k<4; k++ ));do echo -e "\e[4${color2}m$(printf %${width}s)\e[0m\c" echo -e "\e[4${color1}m$(printf %${width}s)\e[0m\c" done echo done done
關于怎么在shell中打印國際象棋棋盤就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。