27、趣味 Shell 脚本游戏大揭秘
2026/5/5 1:00:37 网站建设 项目流程

趣味 Shell 脚本游戏大揭秘

1. 美国州首府问答游戏

1.1 游戏介绍与准备

当你拥有从文件中随机选择一行内容的工具时,就能编写各种问答游戏。这里有一个美国 50 个州首府的问答游戏,所需的数据文件state.capitals.txt可从 http://www.nostarch.com/wcss2/ 下载。下载后将文件保存到/usr/lib/games目录。

1.2 代码实现

#!/bin/bash # states--A state capital guessing game. Requires the state capitals # data file state.capitals.txt. db="/usr/lib/games/state.capitals.txt" # Format is State[tab]City. if [ ! -r "$db" ] ; then echo "$0: Can't open $db for reading." >&2 echo "(get state.capitals.txt" >&2 echo "save the file as $db and you're ready to play!)" >&2 exit 1 fi guesses=0; correct=0; total=0 whi

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询