少于128行代码的Jawbreaker游戏的克隆(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/a-clone-of-the-jawbreaker-game-in-less-than-128-li-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 3 分钟阅读 - 1495 个词 阅读量 0少于128行代码的Jawbreaker游戏的克隆(译文)
原文地址:https://www.codeproject.com/Articles/19722/A-Clone-of-the-Jawbreaker-Game-in-Less-than-128-Li
原文作者:Ronounours
译文由本站 robot-v1.0 翻译
前言
Small game programming tutorial using the CImg Library
使用CImg库的小型游戏编程教程
介绍(Introduction)
在这里,我提出了Jawbreaker游戏的C ++版本,适合少于128行C ++代码.由于使用了(Here, I propose a C++ version of the Jawbreaker game that fits in less than 128 lines of C++ code. This is possible thanks to the use of the) CImg图书馆(CImg Library) ,这是一个小型且非常有用的C ++库,专用于图像处理操作.(, a small and very useful C++ library dedicated to image processing operations.)
在我们的案例中,我们只使用了(In our case, we just use some functions of the) CImg
该库用于处理图像,在窗口中显示动画图形以及检索用户事件(鼠标和键盘).(Library to handle images, display animated graphics in a window, and retrieve user events (mouse and keyboard).)
注意(Note that) CImg
是跨平台的,因此拟议的破坏代码可以在Linux,BSD或MacOSX计算机上编译.(is multi-platform, so that the proposed jawbreaker code will compile on Linux, BSD or MacOSX computers.)
Jawbreaker游戏是一款简单且非常有趣的游戏,具有彩球.单击一组(至少两个)彩色球将其删除.设置越大,得分将越大.这是在基于Windows Mobile的PDA中发现的经典游戏.(The Jawbreaker game is a simple and very funny game featuring colored balls. Clicking on a set of (at least two) colored balls remove them. The bigger the set is, the bigger the score will be. This is a classical game found in Windows Mobile based PDA.)
背景(Background)
本文紧跟前两篇文章,它们解释了如何使用来编写小型游戏(This article follows these two previous articles explaining how to code small games using the) CImg
图书馆:(Library:)
- 俄罗斯方块不到128行代码(Tetris in less than 128 lines of code)
- 少于64行的C ++ Breakout游戏克隆(A C++ Breakout game clone in less than 64 lines)
这些不是必需的,但是三篇文章一起很好地说明了如何进行(These are not necessary, but the three articles together give a good view of how to proceed with)
CImg
创建一些小游戏.(to create some small games.)
使用代码(Using the Code)
源代码很小.文件(The source code is quite small. The file)**颚破(jawbreaker.cpp)**有156行,但是第一条代码行在注释后的第37行开始,因此代码本身包含在120行中.当然,编码风格非常紧凑,但并非不可读:有注释,没有代码混淆.(has 156 lines, but the first code line starts at line 37, after the comments, so the code itself is contained in 120 lines. Of course, the coding style is quite compact, but not unreadable: There are comments and no code obfuscation.) 它是如何工作的 ?首先,我们从头开始创建游戏图形,这意味着不需要额外的图形数据.基本上,对于这个游戏,我们需要创建彩色的球精灵和背景.(How does it work ? First we start by creating game graphics from scratch, which means that no extra graphical data is needed. Basically for this game, we need to create colored balls sprites and a background.) 然后,代码进入主事件循环,该循环使用之前创建的球显示游戏板,并处理用户事件(鼠标和键盘).(Then, the code enters the main event loop that displays the game board using the balls created before, and handles user events (mouse and keyboard).) 主要的困难来自彩球的选择,以及在必要时计算修改后的游戏板.但是,您可能会注意到,这根本不是一个巨大的步骤.(The main difficulty comes from the selection of colored balls, and the computation of a modified game board if necessary. But as you may notice, this is not such a huge step at all.)
怎么玩?(How to Play?)
要控制游戏,只需使用鼠标:左键单击以选择一组相连的球,左键单击以确认其抑制.使用键" BACKSPACE"进入撤消模式,并使用" ESC"结束游戏.(To control the game, just use the mouse: left click to select a set of connected balls, left click to confirm its suppression. Use key ‘BACKSPACE’ for an UNDO mode, and ‘ESC’ to end the game.)
历史(History)
- 2007/07/24:初始版本(2007/07/24 : Initial version)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ Windows Visual-Studio Dev 新闻 翻译