• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PacVim: PacVim 是教你学习 vim 命令的游戏

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

PacVim

开源软件地址:

https://gitee.com/mirrors/PacVim

开源软件介绍:

PacVim

PacVim is a game that teaches you vim commands.You must move pacman (the green cursor) to highlight each word on the gameboard while avoiding the ghosts (in red).

my image

Building and running

Vim is a great tool to write and edit code, but manypeople, including me, struggled with the steep learning curve.I did not find a fun, free way to learn about the vim commandsin-depth, and thus, PacVim was born. Inspired by the classic,PacMan, PacVim is a game that'll give anyone plenty ofpractice with the vim commands while being a ton of fun to play.

Download and build the game with:

Mac OS X

brew install pacvim

Linux (and Mac OS X alternative)

  1. Download and install Curses (graphics library)
    -> For Ubuntu (in terminal): sudo apt-get install libncurses5-dev

    -> OR This tutorial may help (have not confirmed)

    -> OR build from source: Curses source files

    -> Mac OS X should come with Curses installed, so skip this step.

2. git clone https://github.com/jmoon018/PacVim.git3. cd PacVim4. [sudo] make install

Using Docker

If you have docker installed already, you can just:

docker run -it freedomben/pacvim [LEVEL_NUMBER] [MODE]

Building the docker image from source

From the project root, build the image:

docker build -t freedomben/pacvim .

Push to docker hub:

docker push freedomben/pacvim

To play, run (from anywhere):

$ pacvim [LEVEL_NUMBER] [MODE]

You may specify the starting level and mode (n and h for normal/hard). Default mode is hard:

$ pacvim 8 n

To Uninstall, navigate to the folder where you cloned this repo, and type make uninstall
Note: this game may not install/compile properly without gcc version 4.8.X or higher

How To Play

The objective of PacVim is very similar to PacMan.You must run over all the characters on the screen while avoiding the ghosts (red G).PacVim has two special obstacles:

  1. You cannot move into the walls (yellow color). You must use vim motions to jump over them.

  2. If you step on a tilde character (cyan ~), you lose!

You are given three lives. You gain a life each time you beatlevel 0, 3, 6, 9, etc. There are 10 levels, 0 through 9. Afterbeating the 9th level, the game is reset to the 0th level, butthe ghosts move faster.

Winning conditions: Use vim commands to move the cursorover the letters and highlight them. After all letters arehighlighted, you win and proceed to the next level.

Losing conditions: If you touch a ghost (indicatedby a red G) or a tilde character, you lose a life. If youhave less than 0 lives, you lose the entire game.

List of Implemented Commands

keywhat it does
qquit the game
hmove left
jmove down
kmove up
lmove right
wmove forward to next word beginning
Wmove forward to next WORD beginning
emove forward to next word ending
Emove forward to next WORD ending
bmove backward to next word beginning
Bmove backward to next WORD beginning
$move to the end of the line
0move to the beginning of the line
gg/1Gmove to the beginning of the first line
numberGmove to the beginning of the line given by number
Gmove to the beginning of the last line
^move to the first word at the current line
&1337 cheatz (beat current level)

Create Your Own Map!

The maps for PacVim are loaded from text files fromthe /usr/local/share/pacvim-maps folder. After installing, you may, instead, use the maps folder (where you installedthe game) by calling make MAPDIR=maps.

The name of each text file must bein a format such as: map#.txt, where # represents a number like0, 1, 9, 14, etc. The numbers must be consecutive (can't have map0.txt,map1.txt, and then map3.txt). MAKE SURE YOU CHANGE THE NUM_OF_LEVELSIN GLOBALS.CPP OR ELSE YOUR NEW MAPS WON'T LOAD. It should be equalto the highest map number.

In the map text file, the walls are denoted by ampersands #, and thetildes come just from the tilde key. Maps must be bounded and closed,so the player is trapped within 4 walls. Make sure walls block the topand left of the terminal (or else the player goes offscreen). Anyshape, height, and width, within these constraints, should work

Creating Ghosts and Players
At the bottom of each map text file, parameters about the Ghost(s)and Players are specified

Ghost:
/# X Y ... EG: /0.5 1 1
The forward slash denotes that this information describes a Ghost (instead of player).
The # denotes the time, in seconds, it takes for the Ghost to move. (#=0.5 means 2 moves/sec)
X and Y denote the starting x- and y-position of the Ghost

Player:
pX Y ... EG: p15 7The 'p' denotes that this information describes a Player (instead of Ghost).
The X and Y denote the starting x- and y-position of the Player.
This is optional, the player spawns in the middle of the map otherwise
This should be the last line of the file

Code Overview

avatar.cpp

Contains the `avatar` class, which contains information aboutthe player, such as his/her x position, y position, etc. Italso contains methods that allow the player to move and correspondto the keystrokes. For example, the `avatar` class contains the methodcalled `parseWordForward(bool)` which implements the functionalityfor the "w" (or "W" if true) vim command.

ghost1.cpp

Contains the Ghost1 class, derived from the `avatar` class. It isjust like the avatar class, but it requires an extra paremeterupon initialization, called `sleepTime`, a double value thatdetermines how quickly a ghost moves. It refers to the time, inseconds, the ghost must wait to move. A `sleepTime` of 0.5 meansthe ghost moves 2 times a second. `sleepTime` = 0.33 is 3 moves per second, etc.
The `Ghost1` class also contains a method called `spawnGhost` whichcreates the ghost at the location based on its initialization parameters.The ghost will appear when `READY` (global bool) is true (this means the playeris ready), and it will call `ghost.think()` one second afterwards.
`think` is a recursive method that simply moves the ghost. It uses a basic greedy algorithm based on the distance of the ghost's potentialmoves (up, down, right, left) and the player.

Each ghost contains its own thread. A global mutex, called mtx, isused (in think) to ensure that resources are shared properly.

helperFns.cppContains methods that allow easy changes of the screen. A few of them:

  • chtype charAt(int x, int y) returns the chtype at the (x,y) location
  • bool writeAt(int x, int y, chtype letter) writes the 'letter' at location (x,y). Returns false if location is invalid.
  • void printAtBottom(string msg) writes a message one line below the last line

game.cpp

This contains the main() method among many other important ones

main - contains a loop that breaks when LIVES < 0. In the loop,the proper map name is determined and loaded. Data is reset (such as as the pointers,the ghost AI, etc). The level is incremented.
init(const char*) - called by main. Calls drawScreen(str map), creates andspawns player and ghosts threads. Then calls playGame. After playGameends, all the ghost threads are deleted, and then we go back to the main method.
drawScreen(char* map) - called by init. Reads from text file givenby parameter. Loads everything onto the screen with the proper color and getsinformation from the ghost and player so that they spawn in the proper place in init.
playGame(time_t, avatar player) - called by init. This contains two loops,one that consumes everything in the input buffer (which is then deleted), the secondloop allows the player to continuously input keystrokes. When a keystroke is input,onKeystroke is called

To-dos / Bugs

  • More testing on `#G` and `G` commands
  • G can go out of bounds on Map 8 with the boxes. #G (between boxes)
  • G won't move to proper line, it can hit the last wall rather than the last word (map2)
  • Refactor code, more comments

LICENSE

PacVim is free software: you can redistribute it and/or modifyit under the terms of the GNU Lesser General Public License (LGPL) as published bythe Free Software Foundation, either version 3 of the License, or(at your option) any later version.

PacVim is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public Licensealong with this program. If not, see http://www.gnu.org/licenses/.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap