Windows新終端中玩轉ASCII和Emoji游戲的正確姿勢


前一段時間,我搬運了幾個Windows Terminal中玩游戲的視頻,詳情請看 發布在即!來一睹官方團隊如何玩轉 Windows Terminal - 知乎.

今天我來給大家展示一下具體的玩法~


Emoji版雙人碰碰球

目前有個現成的 .NET core 項目可以直接用,地址是:

mbcrump/pongemoji: A implementation of Pong using the new Windows Terminal announced during Build
https://github.com/mbcrump/pongemoji

只需要在Windows Terminal的CMD 或 PowerShell Tab中輸入如下命令:

D:\Coding\pongemoji>git clone https://github.com/mbcrump/pongemoji

D:\Coding\pongemoji>cd pongemoji 

D:\Coding\pongemoji>dotnet build

D:\Coding\pongemoji>dotnet run

運行效果如下:

pong1

玩家 1 : 使用鍵盤上的 WASD 來控制 ↑,←,↓,→ 4個方向.

玩家 2 : 直接使用鍵盤上的方向鍵控制↑,←,↓,→ 4個方向.

游戲中一方先滿5分,游戲會重新開始。目前該游戲還有一點bug噢~


ASCII 水族箱(ASCII quarium)

目前有個基於Perl的項目可以用,地址是:

cmatsuoka/asciiquarium: Enjoy the mysteries of the sea from the safety of your own terminal!

https://github.com/cmatsuoka/asciiquarium

只需要在Windows Terminal的WSL類(我自己安裝是Ubuntu)的Tab中依次進行如下步驟:

  • 安裝 Perl 相關庫
$ sudo apt-get install libcurses-perl
  • 安裝cpan並進行相應配置
$ cpan
Loading internal null logger. Install Log::Log4perl for logging messages

CPAN.pm requires configuration, but most of it can be done automatically.
If you answer 'no' below, you will enter an interactive dialog for each
configuration option instead.

Would you like to configure as much as possible automatically? [yes] yes

...

What approach do you want?  (Choose 'local::lib', 'sudo' or 'manual')
 [local::lib] sudo


Autoconfiguration complete.

commit: wrote '/home/bruce/.cpan/CPAN/MyConfig.pm'

You can re-run configuration any time with 'o conf init' in the CPAN shell
Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v2.18)
Enter 'h' for help.
cpan[1]> ^CCaught SIGINT, trying to continue                                                                                                                                 ^Z
[2]+  Stopped                 cpan

$ sudo cpan Term::Animation
  • 拉取ASCII quarium v1.1的代碼並執行
$ git clone https://github.com/cmatsuoka/asciiquarium.git                                 $ ls    
$ cd asciiquarium/          
$ ./asciiquarium 

運行效果如下:

AsciiQ


ASCII字符游戲 母牛說 “Hi”

還記得 Debian 下“Super Cow Powers” (超級牛力)這個有名的彩蛋嗎?
Cowsay 是個 Perl 寫成的文字過濾腳本,如果你把任何文字傳給 cowsay,一只 ASCII 母牛就會幫你傳達這個消息~

事實上,我們可以直接在Windows Terminal中玩轉它喔~

只需在Windows Terminal的Ubuntu Tab中依次輸入如下命令:

$ sudo apt-get install cowsay
$ sudo apt-get install fortune-mod

接下來,如果輸入fortune | cowsay,得到的是:

cowSay

當然你也可以輸入echo 'Hi!' | cowsay 讓他說"Hi".

如果讓牛思考,你可以輸入uptime | cowthink

當然你還可以輸入uptime | cowthink -f tux讓它變回企鵝(Linux Logo).

此外,cowsay 還有很多可選參數,能顯示更有趣的效果:

  • -d 死掉的母牛
  • -b 瞎眼母牛?
  • -g 財迷母牛
  • -p 多疑的母牛
  • -s 喝醉的母牛
  • -t 疲勞母牛
  • -w 吃驚的母牛
  • -y 小母牛

有興趣的可以繼續玩噢~


.NET版2048

在github中,我發現了一個.NET Framework版的游戲2048.

只需在Windows Terminal的CMD Tab中依次進行如下操作:

  • 從github拉取代碼
C:\Users\Bruce>git clone https://github.com/kflu/2048.git
  • 編譯項目

    如果你在Windows上安裝了Visual Studio,請直接用VS編譯~

    如果沒裝 VS,就使用MSBuild來編譯吧,首先你得找對MSBuild的位置,如果已經為MSBuild設置了系統變量,這一步可以跳過~

    C:\Users\Bruce>cd C:\Windows\Microsoft.NET\Framework
    
    
    C:\Windows\Microsoft.NET\Framework>dir
    
     驅動器 C 中的卷是 Windows
    
     卷的序列號是 74E0-8254
    
    
    
     C:\Windows\Microsoft.NET\Framework 的目錄
    
    ...
    
    2019/03/19  12:52    <DIR>          v1.0.3705
    
    2019/03/19  12:52    <DIR>          v1.1.4322
    
    2019/05/19  00:05    <DIR>          v2.0.50727
    
    2019/05/12  01:33    <DIR>          v3.0
    
    2019/05/12  01:33    <DIR>          v3.5
    
    2019/06/26  21:58    <DIR>          v4.0.30319
    
    ​              18 個文件        272,280 字節
    
    ​               9 個目錄 70,716,755,968 可用字節
    
    
    C:\Windows\Microsoft.NET\Framework>cd v4.0.30319
    

用MSBuild編譯 project 可以用下面幾種命令中的任意一種:

C:\Windows\Microsoft.NET\Framework\v4.0.30319>MSBuild D:\Coding\2048\2048.csproj

C:\Windows\Microsoft.NET\Framework\v4.0.30319>MSBuild D:\Coding\2048\2048.csproj /t:Build 

C:\Windows\Microsoft.NET\Framework\v4.0.30319>MSBuild D:\Coding\2048\2048.csproj /t:Build /p:Configuration=Debug;Platform=x86;TargetFrameworkVersion=v4.0

個人傾向用第2種~

dotNETcore-build

  • 在Windows Terminal中運行游戲

接下來就是運行游戲了,切換到相應目錄下bin中相關的exe即可~

> D:

> cd D:\Coding\2048\bin\Debug

> ConsoleApplication.exe

玩法:用↑ ↓ ← → 4個方向鍵來玩。

效果圖如下:

2048play


笑到噴的直升機

ROFL: Rolling On the Floor Laughing的意寫,可譯為笑到嘔吐,笑到噴~

ROFLCOPTER: Rolling On the Floor Laughing Can‘t OPerate Till Eyes Refocus的縮寫,意為笑到滿地打滾,直到眼神重聚.

  • ROFLCOPTER - 一種嘲笑他人的隱晦做法,經常被聯想為大笑不止或笑得停不下來。

    據說該術語據稱是由魔獸世界III論壇的版主在2003年創造的,而相應的網站www.roflcopter.com於2004年推出。

  • 同時,ROFLCOPTER 也經常被看成是ASCII字符畫成的以ROFL和LOL為螺旋槳的直升機, 它的螺旋槳由ROFL和LOL「 laughing out loud 」制成,看起來像是在旋轉。

相應的代碼我已經上傳到:

https://github.com/yanglr/GamesInWinTerminal

只需從Windows Terminal的PowerShell類Tab打開,執行如下命令~

> cd D:\Coding
> git clone git@github.com:yanglr/GamesInWinTerminal.git
> cd .\GamesInWinTerminal\charArt

> dotnet build
> dotnet run 

最后運行的效果如下:

ROFL


~~gay~~github上還有其他挺有意思的游戲:

Topic: terminal-game

https://github.com/topics/terminal-game

Topic: console-game

https://github.com/topics/console-game


參考:

roflcopter | Memes by Dictionary.com
https://www.dictionary.com/e/memes/roflcopter/

What is ROFL (Rolling On The Floor Laughing)?
https://www.computerhope.com/jargon/r/rofl.htm

superusercode/roflcopter.md
https://gist.github.com/superusercode/28f6d352c01b247f1747ef54b02fc8ec


作者簡介:Bravo Yeung,計算機碩士,知乎干貨答主(獲81K 贊同, 38K 感謝, 235K 收藏)。曾在國內 Top3互聯網視頻直播公司工作過,后加入一家外企做軟件開發至今。


如需轉載,請加微信 iMath7 申請開白!


歡迎在留言區留下你的觀點,一起討論提高。如果今天的文章讓你有新的啟發,學習能力的提升上有新的認識,歡迎轉發分享給更多人。


歡迎各位讀者加入 .NET技術交流群,在公眾號后台回復“加群”或者“學習”即可。


大白技術控 公眾號名片

文末彩蛋

微信后台回復“asp”,給你:一份全網最強的ASP.NET學習路線圖。


回復“cs”,給你:一整套 C# 和 WPF 學習資源!


回復“core”,給你:2019年dotConf大會上發布的.NET core 3.0學習視頻!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM