shell腳本打印國際象棋棋盤
更新時(shí)間:2019年05月22日 15:55:17 作者:njohao
這篇文章主要為大家詳細(xì)介紹了shell腳本打印國際象棋棋盤,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了shell打印國際象棋棋盤的具體代碼,供大家參考,具體內(nèi)容如下
代碼如下:
#!/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
參考文章:
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
linux中編寫自己的并發(fā)隊(duì)列類(Queue 并發(fā)阻塞隊(duì)列)
這篇文章主要介紹了linux中編寫并發(fā)隊(duì)列類,功能有:并發(fā)阻塞隊(duì)列、有超時(shí)限制、有大小限制2013-12-12
linux whatis與whatis database 使用及查詢方法(man使用實(shí)例)
在學(xué)習(xí)man命令時(shí)候,估計(jì)很多朋友都發(fā)現(xiàn)有man –f ,man –k 參數(shù),可以查出很多數(shù)據(jù)。這些有的與man手冊頁相同,有些不是屬于手冊頁的。它們數(shù)據(jù)怎么收集來的,并且whatis是怎么樣工作的2015-10-10
Linux中的host命令應(yīng)用實(shí)例詳解
這篇文章主要介紹了Linux中的host命令應(yīng)用舉例的相關(guān)資料,需要的朋友可以參考下2017-07-07
實(shí)戰(zhàn)模擬監(jiān)控MySQL服務(wù)shell腳本小結(jié)
老男孩shell培訓(xùn)課上帶領(lǐng)學(xué)生練習(xí)shell開發(fā)if語句時(shí)的幾個(gè)小例子和大家分享,需要的朋友可以參考下2016-05-05

