命令行蛇游戏?


14

我记得很久以前有一部旧手机,上面有一个游戏,我相信它被称为“ Snake”或“ Snakes”之类的东西,基本上,您可以使用箭头键更改蛇的方向,蛇不能碰自己(或游戏结束),但是如果碰到地图的边缘,它只会出现在另一侧。游戏的目的是让蛇吃东西,但是每吃一点食物(每次吃更多的东西都会出现在其他地方,但通常一次出现),蛇会变得更长一点。玩游戏更难。

我确定你们都会熟悉这个游戏,所以我想知道(因为我想念这个游戏,只能找到奇数的3D版本)终端中是否有这个游戏的版本?我希望它能坚持原来的样子,也许会遵循ASCII的含义?

我在GNOME 3.20上运行Ubuntu GNOME 16.04.1,官方存储库中是否有这样的免费应用程序(我希望它来自哪里)?

Answers:


20

“,官方存储库中是否有这样的免费应用程序(我希望它来自哪里)?”

首先是nsnake应该完全满足您的需求

sudo apt-get install nsnake

在此处输入图片说明

我发现还有两个是snake4在新窗口中打开的,所以不是终端游戏,gnibbles但是我无法运行它。


gnibbles只是为了轻松升级到过渡包gnome-nibbles,与游戏实际的包是gnome-nibbles

@ParanoidPanda解释了这一点:)我将在短期内对此进行一些更新。
Mark Kirby

是的,您知道吗?是nsnake至少可以使某些墙壁不位于其中并允许蛇穿过它们并出现在地图另一端的水平或设置吗?我看了一下,看起来好像不对,但只想检查一下!

我也找不到任何选项@ParanoidPanda这是devs页面,联系方式为github.com/alexdantas/nSnake,他们可能知道如何通过源禁用墙。
马克·柯比

我想我可能会建议给他们一个选择,因为我记得原始游戏中有这个选择,而且我认为它需要比一个小的调整多一些实现,因为蛇也必须出现在另一侧,具体取决于他们对所有代码进行了编码,可能还需要进行一些小的更改。我不知道,我还没有看到代码。但我认为我会建议他们作为向用户提供的一种选择。

7

该游戏被称为“游戏” 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: sol@subnetzero.org
#
# 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

0

有一系列名为的命令行游戏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

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.