怎么在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
关于怎么在shell中打印国际象棋棋盘就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
本文题目:怎么在shell中打印国际象棋棋盘-创新互联
文章出自:http://cdiso.cn/article/jegjp.html