409
※上記の広告は60日以上更新のないWIKIに表示されています。更新することで広告が下部へ移動します。

#!/bin/bash
# THE SHELLTORI 2.1
# written by takafu3
# USAGE
# DEFAULT MODE # shelltori
# DEMO MODE   # shelltori demo or -d
# TAISENMODE  # shelltori taisen or -t
# DIR FILE CONFIG
DIR=~
KOMANDO=${DIR}/komando.txt
TMP=${DIR}/tmp$$
LOG=${DIR}/torilog.txt
MODE=DEFAULT
PHASE=PLAYER
> $KOMANDO 
> $TMP
> $LOG
# COLOR
GREEN=$'\e[0;32m'
BLACK=$'\e[0;30m'
RED=$'\e[0;31m'
BLUE=$'\e[0;34m'
# MAKE KOMANDO FILE
i=1
while [ 0 ]
do
	ls -F `echo $PATH |\
	cut -f $i -d ":"` >>\
	$TMP
	i=`expr $i + 1`
	[ `echo $PATH |\
	cut -f $i -d ":" |\
	grep -c .`  -eq 0 ] &&\
	break
done
cut -f 1 -d \* $TMP |\
grep -v @ |\
grep -v / |\
grep -v [0-9]$ |\
grep -v ^[0-9] |\
sort -u |\
grep -v "\." >> $KOMANDO
rm $TMP
# SET MODE
echo $1 |\
[ `grep -c taisen` -gt 0 ] &&\
MODE=TAISEN
echo $1 |\
[ `grep -c "-"` -gt 0 ] &&\
echo $1 |\
[ `grep -c "t"` -gt 0 ] &&\
MODE=TAISEN
echo $1 |\
[ `grep -c demo` -gt 0 ] &&\
MODE=DEMO &&\
PHASE=COMPUTER
echo $1 |\
[ `grep -c "-"` -gt 0 ] &&\
echo $1 |\
[ `grep -c "d"` -gt 0 ] &&\
MODE=DEMO &&\
PHASE=COMPUTER
# GAME START
echo "This is SHIRITORI by unix commands"
echo "If you Give up, Type OTEAGE"
GYOSU=`grep -c . $KOMANDO`
SAISYO=`expr $RANDOM % $GYOSU + 1`
TORI=`grep -n . $KOMANDO |\
grep $SAISYO |\
head -n 1 |\
cut -f 2 -d ":"`
echo "$GREEN"1st command is "$RED"${TORI}"$BLACK"
# GAME LOOP
while [ 0 ]
do
	SIRI=`echo ${TORI} |\
	cut -c ${#TORI}`
    while [ $PHASE == "PLAYER" ]
    do
		[ $MODE == TAISEN ] &&\
		echo +++ "$BLUE" PLAYER PHASE" $BLACK" +++
		echo "$GREEN"Input a command start from "$RED"${SIRI}"$BLUE"
		[ $MODE != DEMO ] &&\
		read TORI
		[ ${#TORI} -eq 0 ] &&\
		continue
		[ $TORI == "OTEAGE" ] &&\
		break
		[ `echo $TORI | cut -c 1` == ${SIRI} ] &&\
		break
		echo "$RED"WRANG HEAD WORD"$BLACK"
    done
	if [ $PHASE == "COMPUTER" ]
	then
		[ $MODE == TAISEN ] &&\
		echo "$BLACK"+++ "$RED"COMPUTER PHASE"$BLACK" +++
		[ $MODE == DEMO ] &&\
		echo "$GREEN"Input a command start from "$RED"${SIRI}"$BLACK"
		sleep 5
		NUMBER=`grep -c ^$SIRI $KOMANDO`
		FARST=`grep -n ^$SIRI $KOMANDO |\
		head -n 1 |\
		cut -f 1 -d :`
		LINE=`expr $FARST + $RANDOM % $NUMBER`
		TORI=`head -n $LINE $KOMANDO |\
		tail -n 1`
		echo "$RED"$TORI"$BLACK"
	fi
# GIVE UP
	[ $TORI == "OTEAGE" ] &&\
	STATUS=OTEAGE &&\
	break
# SEARCH FROM KOMANDO FILE
	[ `grep -c ^${TORI}$ $KOMANDO` -eq 0 ] &&\
	STATUS=NOLITED &&\
	break
# SEARCH FROM LOG FILE
	[ `grep -c ^${TORI}$ $LOG` -ne 0 ] &&\
	STATUS=SAME &&\
	break
# OUTPUT TO LOG FILE
	echo $TORI >> $LOG
	MAN=`man "$TORI" 2>/dev/null |\
	sed '/^$/d' |\
	head -n 3 |\
	tail -n 1`
	[ ${#MAN} -ne 0 ] && echo $MAN
	[ $MODE != TAISEN ] &&\
	continue
# PHASE CHANGE
	[ $PHASE == PLAYER ] &&\
	PHASE=COMPUTER &&\
	continue
	PHASE=PLAYER
done
# GAME OVER
SCORE=`grep -c . $LOG`
[ $MODE == "TAISEN" ] &&\
SCORE=`expr $SCORE / 2`
echo "$BLACK"-----------------------------------------
[ $MODE != TAISEN ] &&\
echo GAME OVER
[ $MODE == TAISEN ] &&\
[ $PHASE == PLAYER ] &&\
echo "$RED"YOU LOSE"$BLACK"
[ $MODE == TAISEN ] &&\
[ $PHASE == COMPUTER ] &&\
echo "$BLUE"YOU WIN"$BLACK"
[ $STATUS == "OTEAGE" ] &&\
echo "$RED"OTEAGE"$BLACK"
[ $STATUS == "NOLITED" ] &&\
echo "$RED"NO LISTED WORD"$BLACK"
[ $STATUS == "SAME" ] &&\
echo "$RED"SAME WORD"$BLACK"
echo Your Score is $SCORE
echo -----------------------------------------
[ $PHASE == "COMPUTER" ] &&\
exit 0
echo + Answer Example +
NUMBER=`grep -c ^$SIRI $KOMANDO`
FARST=`grep -n ^$SIRI $KOMANDO |\
head -n 1 |\
cut -f 1 -d :`
for i in U S P
do
	LINE=`expr $FARST + $RANDOM % $NUMBER`
	head -n $LINE $KOMANDO |\
	tail -n 1
done
exit 0
 
最終更新:2010年04月22日 17:17