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

