昔、携帯電話に「ヘビ」や「ヘビ」などと呼ばれるゲームがあり、基本的には矢印キーでヘビの方向を変えることができたと思います。ヘビは自分自身(またはゲームオーバー)に触れることはできませんが、マップの端に触れると、反対側に表示されます。ゲームの目的は、ヘビに食べ物を食べさせることでしたが、食べ物を食べるたびに(それを食べるたびにどこか別の場所に表示されますが、通常は一度に1つずつ)ヘビは少し長くなりますゲームをプレイするのが難しい。
皆さんがこのゲームに精通していると確信しているので、このゲームのバージョンがTerminalにあるのではないかと思っていました(このゲームを見逃して、奇妙な3Dバージョンしか見つけられないので)。私はそれがオリジナルに固執し、おそらくASCIIの線に沿って何かをすることを望んでいましたか?
Ubuntu GNOME 16.04.1をGNOME 3.20で実行していますが、公式リポジトリにそのような無料のアプリケーションがありますか(そこから入手したいのですが)。
このゲームはcentipede
と呼ばれ、その詳細はこちらにあります: http://wp.subnetzero.org/?p=269 。これは、ダウンロードを必要としないbashゲームであり、bashスクリプトに興味がある人には興味深い研究です。
次の変数を変更することにより、画面のサイズを変更して、画面をより小さく、より難しくすることができます。
LASTCOL=40 # Last col of game area
LASTROW=20 # Last row of game area
コードは次のとおりです。
#!/bin/bash
#
# Centipede game
#
# v2.0
#
# Author: [email protected]
#
# Functions
drawborder() {
# Draw top
tput setf 6
tput cup $FIRSTROW $FIRSTCOL
x=$FIRSTCOL
while [ "$x" -le "$LASTCOL" ];
do
printf %b "$WALLCHAR"
x=$(( $x + 1 ));
done
# Draw sides
x=$FIRSTROW
while [ "$x" -le "$LASTROW" ];
do
tput cup $x $FIRSTCOL; printf %b "$WALLCHAR"
tput cup $x $LASTCOL; printf %b "$WALLCHAR"
x=$(( $x + 1 ));
done
# Draw bottom
tput cup $LASTROW $FIRSTCOL
x=$FIRSTCOL
while [ "$x" -le "$LASTCOL" ];
do
printf %b "$WALLCHAR"
x=$(( $x + 1 ));
done
tput setf 9
}
Apple() {
# Pick coordinates within the game area
APPLEX=$[( $RANDOM % ( $[ $AREAMAXX - $AREAMINX ] + 1 ) ) + $AREAMINX ]
APPLEY=$[( $RANDOM % ( $[ $AREAMAXY - $AREAMINY ] + 1 ) ) + $AREAMINY ]
}
drawapple() {
# Check we haven't picked an occupied space
LASTEL=$(( ${#LASTPOSX[@]} - 1 ))
x=0
Apple
while [ "$x" -le "$LASTEL" ];
do
if [ "$APPLEX" = "${LASTPOSX[$x]}" ] && [ "$APPLEY" = "${LASTPOSY[$x]}" ];
then
# Invalid coords... in use
x=0
Apple
else
x=$(( $x + 1 ))
fi
done
tput setf 4
tput cup $APPLEY $APPLEX
printf %b "$APPLECHAR"
tput setf 9
}
growsnake() {
# Pad out the arrays with oldest position 3 times to make snake bigger
LASTPOSX=( ${LASTPOSX[0]} ${LASTPOSX[0]} ${LASTPOSX[0]} ${LASTPOSX[@]} )
LASTPOSY=( ${LASTPOSY[0]} ${LASTPOSY[0]} ${LASTPOSY[0]} ${LASTPOSY[@]} )
RET=1
while [ "$RET" -eq "1" ];
do
Apple
RET=$?
done
drawapple
}
move() {
case "$DIRECTION" in
u) POSY=$(( $POSY - 1 ));;
d) POSY=$(( $POSY + 1 ));;
l) POSX=$(( $POSX - 1 ));;
r) POSX=$(( $POSX + 1 ));;
esac
# Collision detection
( sleep $DELAY && kill -ALRM $$ ) &
if [ "$POSX" -le "$FIRSTCOL" ] || [ "$POSX" -ge "$LASTCOL" ] ; then
tput cup $(( $LASTROW + 1 )) 0
stty echo
echo " GAME OVER! You hit a wall!"
gameover
Elif [ "$POSY" -le "$FIRSTROW" ] || [ "$POSY" -ge "$LASTROW" ] ; then
tput cup $(( $LASTROW + 1 )) 0
stty echo
echo " GAME OVER! You hit a wall!"
gameover
fi
# Get Last Element of Array ref
LASTEL=$(( ${#LASTPOSX[@]} - 1 ))
#tput cup $ROWS 0
#printf "LASTEL: $LASTEL"
x=1 # set starting element to 1 as pos 0 should be undrawn further down (end of tail)
while [ "$x" -le "$LASTEL" ];
do
if [ "$POSX" = "${LASTPOSX[$x]}" ] && [ "$POSY" = "${LASTPOSY[$x]}" ];
then
tput cup $(( $LASTROW + 1 )) 0
echo " GAME OVER! YOU ATE YOURSELF!"
gameover
fi
x=$(( $x + 1 ))
done
# clear the oldest position on screen
tput cup ${LASTPOSY[0]} ${LASTPOSX[0]}
printf " "
# truncate position history by 1 (get rid of oldest)
LASTPOSX=( `echo "${LASTPOSX[@]}" | cut -d " " -f 2-` $POSX )
LASTPOSY=( `echo "${LASTPOSY[@]}" | cut -d " " -f 2-` $POSY )
tput cup 1 10
#echo "LASTPOSX array ${LASTPOSX[@]} LASTPOSY array ${LASTPOSY[@]}"
tput cup 2 10
echo "SIZE=${#LASTPOSX[@]}"
# update position history (add last to highest val)
LASTPOSX[$LASTEL]=$POSX
LASTPOSY[$LASTEL]=$POSY
# plot new position
tput setf 2
tput cup $POSY $POSX
printf %b "$SNAKECHAR"
tput setf 9
# Check if we hit an Apple
if [ "$POSX" -eq "$APPLEX" ] && [ "$POSY" -eq "$APPLEY" ]; then
growsnake
updatescore 10
fi
}
updatescore() {
SCORE=$(( $SCORE + $1 ))
tput cup 2 30
printf "SCORE: $SCORE"
}
randomchar() {
[ $# -eq 0 ] && return 1
n=$(( ($RANDOM % $#) + 1 ))
eval DIRECTION=\${$n}
}
gameover() {
tput cvvis
stty echo
sleep $DELAY
trap exit ALRM
tput cup $ROWS 0
exit
}
###########################END OF FUNCS##########################
# Prettier characters but not supported
# by all termtypes/locales
#SNAKECHAR="\0256" # Character to use for snake
#WALLCHAR="\0244" # Character to use for wall
#APPLECHAR="\0362" # Character to use for apples
#
# Normal boring ASCII Chars
SNAKECHAR="@" # Character to use for snake
WALLCHAR="X" # Character to use for wall
APPLECHAR="o" # Character to use for apples
#
SNAKESIZE=3 # Initial Size of array aka snake
DELAY=0.2 # Timer delay for move function
FIRSTROW=3 # First row of game area
FIRSTCOL=1 # First col of game area
LASTCOL=40 # Last col of game area
LASTROW=20 # Last row of game area
AREAMAXX=$(( $LASTCOL - 1 )) # Furthest right play area X
AREAMINX=$(( $FIRSTCOL + 1 )) # Furthest left play area X
AREAMAXY=$(( $LASTROW - 1 )) # Lowest play area Y
AREAMINY=$(( $FIRSTROW + 1)) # Highest play area Y
ROWS=`tput lines` # Rows in terminal
ORIGINX=$(( $LASTCOL / 2 )) # Start point X - use bc as it will round
ORIGINY=$(( $LASTROW / 2 )) # Start point Y - use bc as it will round
POSX=$ORIGINX # Set POSX to start pos
POSY=$ORIGINY # Set POSY to start pos
# Pad out arrays
ZEROES=`echo |awk '{printf("%0"'"$SNAKESIZE"'"d\n",$1)}' | sed 's/0/0 /g'`
LASTPOSX=( $ZEROES ) # Pad with zeroes to start with
LASTPOSY=( $ZEROES ) # Pad with zeroes to start with
SCORE=0 # Starting score
clear
echo "
Keys:
W - UP
S - DOWN
A - LEFT
D - RIGHT
X - QUIT
If characters do not display properly, consider changing
SNAKECHAR, APPLECHAR and WALLCHAR variables in script.
Characters supported depend upon your terminal setup.
Press Return to continue
"
stty -echo
tput civis
read RTN
tput setb 0
tput bold
clear
drawborder
updatescore 0
# Draw the first Apple on the screen
# (has collision detection to ensure we don't draw
# over snake)
drawapple
sleep 1
trap move ALRM
# Pick a random direction to start moving in
DIRECTIONS=( u d l r )
randomchar "${DIRECTIONS[@]}"
sleep 1
move
while :
do
read -s -n 1 key
case "$key" in
w) DIRECTION="u";;
s) DIRECTION="d";;
a) DIRECTION="l";;
d) DIRECTION="r";;
x) tput cup $COLS 0
echo "Quitting..."
tput cvvis
stty echo
tput reset
printf "Bye Bye!\n"
trap exit ALRM
sleep $DELAY
exit 0
;;
esac
done
bsdgames
と呼ばれるコマンドラインゲームのコレクションがあります。
Sudo apt-get install bsdgames
またはSudo apt install bsdgames
と入力してインストールできます。
正常にインストールされたら、このリストからゲームを起動できます(端末に名前を入力するだけです)
adventure (6) - an exploration game
sol (6) - a collection of card games which are easy to play with the aid of a mouse.
arithmetic (6) - quiz on simple arithmetic
atc (6) - air traffic controller game
backgammon (6) - the game of backgammon
battlestar (6) - a tropical adventure game
bcd (6) - "reformat input as punch cards, paper tape or morse code"
boggle (6) - Word search game
caesar (6) - decrypt caesar ciphers
canfield (6) - the solitaire card game canfield
cfscores (6) - the solitaire card game canfield
chkfont (6) - checks figlet 2.0 and up font files for format errors
countmail (6) - be obnoxious about how much mail you have
cowsay (6) - configurable speaking/thinking cow (and a bit more)
cribbage (6) - the card game cribbage
dab (6) - Dots and Boxes game
espdiff (6) - apply the appropriate transformation to a set of patches
figlet-figlet (6) - display large characters made up of ordinary screen characters
figlist (6) - lists figlet fonts and control files
fortune (6) - print a random, hopefully interesting, adage
gnome-mahjongg (6) - A matching game played with Mahjongg tiles
gnome-mines (6) - The popular logic puzzle minesweeper
gnome-sudoku (6) - puzzle game for the popular Japanese sudoku logic puzzle
go-fish (6) - play "Go Fish"
gomoku (6) - game of 5 in a row
hack (6) - exploring The Dungeons of Doom
hangman (6) - computer version of the game hangman
hunt (6) - a multi-player multi-terminal game
huntd (6) - hunt daemon, back-end for hunt game
intro (6) - introduction to games
lolcat (6) - Rainbow coloring for text
mille (6) - play Mille Bornes
monop (6) - Monopoly game
morse (6) - "reformat input as punch cards, paper tape or morse code"
number (6) - convert Arabic numerals to English
phantasia (6) - an interterminal fantasy game
pig (6) - eformatray inputway asway Igpay Atinlay
pom (6) - display the phase of the moon
ppt (6) - "reformat input as punch cards, paper tape or morse code"
primes (6) - generate primes
quiz (6) - random knowledge tests
rain (6) - animated raindrops display
random (6) - random lines from a file or random numbers
robots (6) - fight off villainous robots
rot13 (6) - decrypt caesar ciphers
sail (6) - multi-user wooden ships and iron men
snake (6) - display chase game
snscore (6) - display chase game
teachgammon (6) - learn to play backgammon
tetris-bsd (6) - the game of tetris
trek (6) - trekkie game
wargames (6) - shall we play a game?
worm (6) - Play the growing worm game
worms (6) - animate worms on a display terminal
wtf (6) - translates acronyms for you
wump (6) - hunt the wumpus in an underground cave
これらのゲームは通常、を押すと終了します Ctrl+C