1 Star 0 Fork 0

julian / pacvim

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
LGPL-3.0

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 many people, including me, struggled with the steep learning curve. I did not find a fun, free way to learn about the vim commands in-depth, and thus, PacVim was born. Inspired by the classic, PacMan, PacVim is a game that'll give anyone plenty of practice 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.git
3. cd PacVim
4. [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 beat level 0, 3, 6, 9, etc. There are 10 levels, 0 through 9. After beating the 9th level, the game is reset to the 0th level, but the ghosts move faster.

Winning conditions: Use vim commands to move the cursor over the letters and highlight them. After all letters are highlighted, you win and proceed to the next level.

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

List of Implemented Commands

key what it does
q quit the game
h move left
j move down
k move up
l move right
w move forward to next word beginning
W move forward to next WORD beginning
e move forward to next word ending
E move forward to next WORD ending
b move backward to next word beginning
B move backward to next WORD beginning
$ move to the end of the line
0 move to the beginning of the line
gg/1G move to the beginning of the first line
numberG move to the beginning of the line given by number
G move 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 from the /usr/local/share/pacvim-maps folder. After installing, you may, instead, use the maps folder (where you installed the game) by calling make MAPDIR=maps.

The name of each text file must be in a format such as: map#.txt, where # represents a number like 0, 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_LEVELS IN GLOBALS.CPP OR ELSE YOUR NEW MAPS WON'T LOAD. It should be equal to the highest map number.

In the map text file, the walls are denoted by ampersands #, and the tildes 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 top and left of the terminal (or else the player goes offscreen). Any shape, 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 7 The '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 about the player, such as his/her x position, y position, etc. It also contains methods that allow the player to move and correspond to the keystrokes. For example, the `avatar` class contains the method called `parseWordForward(bool)` which implements the functionality for the "w" (or "W" if true) vim command.

ghost1.cpp

Contains the Ghost1 class, derived from the `avatar` class. It is just like the avatar class, but it requires an extra paremeter upon initialization, called `sleepTime`, a double value that determines how quickly a ghost moves. It refers to the time, in seconds, the ghost must wait to move. A `sleepTime` of 0.5 means the ghost moves 2 times a second. `sleepTime` = 0.33 is 3 moves per second, etc.
The `Ghost1` class also contains a method called `spawnGhost` which creates the ghost at the location based on its initialization parameters. The ghost will appear when `READY` (global bool) is true (this means the player is 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 potential moves (up, down, right, left) and the player.

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

helperFns.cpp Contains 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 and spawns player and ghosts threads. Then calls playGame. After playGame ends, 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 given by parameter. Loads everything onto the screen with the proper color and gets information 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 second loop 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 modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the 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 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

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

GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.

简介

暂无描述 展开 收起
LGPL-3.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/tox/pacvim.git
git@gitee.com:tox/pacvim.git
tox
pacvim
pacvim
master

搜索帮助