Lingo-C#中的简单文字游戏(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/lingo-a-simple-word-game-in-c-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 10 分钟阅读 - 4941 个词 阅读量 0Lingo-C#中的简单文字游戏(译文)
原文地址:https://www.codeproject.com/Articles/20077/Lingo-A-Simple-Word-Game-in-C
原文作者:Benzi K. Ahamed
译文由本站 robot-v1.0 翻译
前言
Lingo is a simple five-letter word game in C#. It is based on the popular TV game show of the same name. The idea of the game is simple: you are given five chances to guess a five letter word, given two letters in the word initially.
Lingo是C#中一个简单的五字母文字游戏.它基于同名的流行电视游戏节目.游戏的想法很简单:您有5次机会猜一个5个字母的单词,而单词中最初有2个字母.
- 下载Lingo游戏-117.26 KB(Download the Lingo game - 117.26 KB)
- 下载完整的源文件-835.13 KB(Download the complete source files - 835.13 KB)
- 下载(Download)Lingo-版黑(Lingo - Edition Black)版本-157.79 KB(version - 157.79 KB) –(-)
NEW!
介绍(Introduction)
ingo是一个简单的文字游戏,基于(ingo is a simple word game that is based on the) 热门电视游戏节目(popular TV game show) 相同名称的格式.游戏的想法是给玩家五次猜测一个五个字母的单词的机会,最初给该单词两个字母.在此过程中,对于每一个猜测,如果猜测中的字母与原始单词在同一位置,或者如果原始单词中存在字母,但猜测单词中的字母不在同一位置,则玩家将被告知.(format of the same name. The idea of the game is to give a player five chances to guess a five letter word, given two letters in the word initially. Along the way, for every guess made, if a letter in the guess falls in the same place as that in the original word, or if a letter is present in the original word but not in the same position in the guess word, the player will be apprised.)
游戏玩法(Gameplay)
Lingo具有以下游戏元素:(Lingo has the following gameplay elements:)
- 五次猜一个五个字母的单词的机会(Five chances to guess a five letter word)
- 最初将标记两个字母(Two letters will be marked initially)
- 正确的字母和原始单词中存在但位置不正确的字母将突出显示(Correct letters and letters present in the original word but not in the correct position will be highlighted)
- 检查玩家是否提供了有效的单词(如果单词无效,则玩家失去机会)(Checks if the player provides a valid word (if the word is not valid, the player loses a chance))
- 得分是基于猜测一个单词所需的机会.第一次猜对可得5分,最后一次尝试可得1分(Scoring is based on how many chances are required to guess a word. 5 points awarded for guessing it right the first time, 1 point for guessing it at the last attempt)
- 提供一种选择游戏难度级别的机制.存在三个级别(容易,中等和困难).每个级别都有自己专有的单词集,并且五个字母单词的字典组合起来超过12,000个单词.大多数单词确实很晦涩,但是仍然是一个不错的列表.(Provides a mechanism to select the difficulty level of the game. Three levels are present (easy, medium and hard). Each level has its own exclusive set of words, and combined, the dictionary of five letter words is over 12,000 words strong. Most of the words are really obscure, but it’s a good list nonetheless.)
- 提供一种机制,使您需要5分钟的休息时间,而任何需要5分钟的休息时间都可以. :)(Provides a mechanism to have a much needed 5-minute break from anything that requires you to have a 5-minute break. :))
这是启动Lingo时的屏幕外观:(Here’s how the screen will look like on starting up Lingo:)
的(The)版黑(Edition Black)版本如下所示.(version looks like below.)
您将获得五个字母中的两个字母(蓝色),您必须在五个或更少的猜测中找出答案.对于您所做的每一个猜测,如果字母落在正确的位置,或者单词中出现字母但位置不正确,则会通知您.如果程序感觉您在使用单词时遇到困难,它将给您一个比原始单词还要多的奖励字母(在第一个屏幕顶部以橙色标记).(You are provided with two letters (in blue) of a five letter that you have to figure out in five or less guesses. For every guess you make, if a letter falls in the exact position, or if a letter is present in the word but not in the correct position, you will be notified. If the program feels you are having difficulty with a word, it would give you one more bonus letter from the original word (marked in orange at the top, first screen).) 游戏过程示例如下:(A sample course of play would look like:)
首先,游戏提供两个字母" n"和" o".我们最多只能尝试五次.我们的第一个尝试是"音符",用红色突出显示的" n"," o"和" t"表示位置不正确,用绿色突出显示的" s"表示位置正确.如果输入了无效的单词(" sugam"),您实际上会错失良机,并且不会处理字母.(To start with, the game provides two letters ‘n’ and ‘o’. We have to figure out the word in at most five attempts. Our first attempt was ‘notes’, and ‘n’, ‘o’ and ’t' highlighted in red indicates they are not in the right position, and ’s' in green indicates it’s in the correct position. If an invalid word (‘sugam’) is entered, you effectively miss a chance, and the letters will not be processed.) 游戏允许您控制难度级别.右键单击该表格,您可以选择将难度级别设置为"简单",“中等"或"困难”.选择难度级别时,您在游戏中必须猜到的单词将属于该难度级别.(The game allows you to control the difficulty level. Right-clicking on the form gives you the option to set your difficulty level as either Easy, Medium or Difficult. On choosing a difficulty level, words you have to guess in the game will be of that difficulty level.)
游戏使用超过12,000个单词的单词列表.我无法验证列表中的所有单词,因为我在一段时间内从各种来源收集了这些单词,并将它们全部组合在一起. (谷歌搜索对我有很大帮助!).(The game uses a word list of over 12,000 words. I have not been able to verify all the words in the list, as I have collected it from various sources over a span of time and just combined them all. (Googling a lot helped me a lot!).) 玩家说完一个字后,在表格底部附近会出现一个链接,单击该链接即可将您转到(After the player is finished off with a word, a link appears near the bottom of the form, which on clicking should take you to the) 词网(WordNet) 网站,并使用其在线应用程序获取该词的定义.并非所有单词都可以得到定义,因为Lingo中使用的单词列表文件非常大(大多数单词太晦涩).(site, and use their online application to get a definition for the word. Not all words may get a definition, as the word list file used in Lingo is very large (most of the words are too obscure).) 那么,为什么不继续下载源代码和可执行文件,并尝试这一小段代码呢?(So why not go ahead and download the source and the executable, and try this little piece?) 您可以单独下载可执行文件.有基本版本和Edition Black版本.(You can download the executables separately. There is a basic version, and the Edition Black version.)
使用代码(Using the Code)
整个解决方案和源代码文件都位于zip文件中.解决方案文件是在Visual Studio 2008 Orcas Beta 2中创建的.如果无法打开该文件,则可能必须在Visual Studio版本中创建一个新项目,并将所有文件添加到该文件下.(*The entire solution and source code files are present in the zip file. The solution file was created in Visual Studio 2008 Orcas Beta 2. If you are not able to open the same, you may have to create a new project in your Visual Studio version and add all the files under the*)**林戈(*Lingo*)**文件夹.图标和单词列表文件((*folder to it. The icons and the word list file (*)**Lingo \ Words \ Lingo.txt(*Lingo\Words\Lingo.txt*)**)需要设置为嵌入到程序集中作为资源.它是用.NET 2.0编译的.(*) need to be set as embedded as resources into the assembly. It was compiled with .NET 2.0.*)
在这里,我将不提供任何代码描述或片段;它已经得到了充分的文档记录,应该易于遵循. [(I am not going to give any description or snippets of the code here; it has been fairly documented and should be easy to follow. )毕竟,这只是一个简单的游戏. :)(After all, it’s just a simple game. :))
**更新:(UPDATE:)**我在游戏中添加了一些淡入淡出的效果.我在表单上使用了很多标签,并扩展了(I have added some fading effects to the game. I use labels on the form quite a lot, and extended the) Label
类创建(class to create the) FadeLabel
类.这个新标签可以转换其前后颜色.看看这个.(class. This new label is capable of transitioning its fore and back colors. Check it out.)
更新(UPDATE)(2007年8月22日):我已经提出了((22 AUG 2007): I have put up the)版黑(Edition Black)可供下载的游戏版本.目前尚无可用资源,因为它仍在进行中.我一完成就把它放起来.在技术方面,我为此版本广泛使用了图像(屏幕截图中的那些彩色字母),并且整体上采用了黑色主题.它仍然需要对UI进行一些改进,但是游戏应该可以任意播放.(version of the game for download. No source is available at the moment, as it’s still a work in progress. I’ll put it up as soon as I complete it. On the technical front, I used images extensively for this version (those colorful letters in the screenshot), and overall sports a black theme. It still needs a bit of polishing UI wise, but the game should be playable at any rate.)
兴趣点(Points of Interest)
在编写此游戏时,我唯一真正需要思考的就是符合我提出的以下要求:(The only bit of real thinking I had to do in writing this game was conforming to the following requirement I made:) 假设猜测的单词是"(Assume the word to guess is “)行话(lingo)".并假设”(". And assume “)面条(oodle)“是您建议的单词.(” is a word you suggested.) 在处理您的猜测时,应输出以下内容(On processing your guess, the following should be output)
- 正确的字母:(Correct Letters:)没有(none)
- 错误的职位信:(Wrong Position Letters:)‘o’(‘o’)在第一位置(at first position,)‘我’(‘l’)在第四位置(at fourth position) 请注意,第二个'(Note that the second ‘)Ø(o)“不应以错误的位置作为字母提及,因为我们已经报告了”(’ should not be mentioned as a letter in the wrong position, as we already have reported an ‘)Ø(o)在此之前.因此,如果您输入”(’ prior to that. So if you enter ‘)oo(ooooo)',只有最后一个字母才能突出显示,因为它位于正确的位置,并且如果您输入’(', only the last letter should be highlighted as it is in the correct position, and if you enter ‘)oo(ooooz)',仅应突出显示第一个字母,而不能突出显示其他’(', only the first letter should be highlighted, and not the other ‘)Ø(o)的.希望你明白.(’s. Hope you get the idea.) 乍一看,这似乎很容易实现(最终实现).但我确实建议您在查看代码以了解如何解决该问题之前,请尝试自行提出一种算法(如果您愿意的话,几乎不会花费几分钟的时间,如果您喜欢这种东西,那将会很有趣.当您准备就绪时,请与我已实施的解决方案进行比较.如果您的简单一些,也请让我知道.(At first glance, this seems straightforward to achieve (and eventually it is). But I do suggest that before you take a look at the code to see how I solved it, please try to come up with an algorithm on your own (it’ll take hardly a few minutes of your time if you care to do so, and if you like this sort of thing it’ll be interesting). When you have one ready, compare with the solution I have implemented. If yours is simpler, let me know too.)
历史和更新(History and Updates)
-
2007年8月17日:初始版本(17 AUG 2007: Initial release)
-
2007年8月18日:进行了一些小的增强和新增功能(18 AUG 2007: Minor enhancements and new features added)
- [+]如果程序检测到您在单词上遇到困难,它将再给您一个奖励字母,以便您可以解决单词([+] If the program detects you are having difficulty with a word, it will give you one more bonus letter so that you can solve the word)
- [+]包括一个奖励分数计数器,当您说出一个单词时,它就会添加到您的基本分数中.这个想法是您猜单词的速度越快,您的分数就越高([+] Includes a bonus score counter, which gets added to your base score when you get a word. The idea being the faster you guess a word, the better your score)
- [〜] UI进行了一些调整,以使其外观更好([~] The UI has undergone a bit of tweaking to make it better looking)
- [〜]修改了选择开头两个随机字母的方式([~] Modified the way the initial two random letters are chosen)
-
2007年8月19日:新功能(19 AUG 2007: New features)
- [+]添加了淡入淡出标签.请参阅([+] Added fading labels. Refer to the)
FadeLabel
源文件中的类以获取更多详细信息(class in the source file for more details) - [+]创建了游戏的主要Lingo图标([+] Created the main Lingo icon for the game)
- [+]添加了淡入淡出标签.请参阅([+] Added fading labels. Refer to the)
-
2007年8月22日:发布黑色版(22 AUG 2007: Edition Black is released)
- [+]游戏的新版本.增强了用户界面.此版本带有黑色主题,字母的彩色按钮([+] A new version of the game. Enhanced the UI quite a bit. This version sports a black theme, and colorful buttons for the letters)
- [+]为游戏创建了许多新图标,主要用于Edition Black中([+] Created a lot of new icons for the game, mostly used in Edition Black)
学分(Credits)
应用程序中的图标来自(*The icons in the application are from the*) 丝绸图标集(Silk Icon Set) [()^( ) ^免费提供(*available for free from*) FamFamFam.com(FamFamFam.com) [()^( ) ^.该图标集包含1000个16x16图标.该网站上还有其他图标集.看看吧(. The icon set contains 1000 16x16 icons. There are other icon sets available on that site. Do have a look.) 我使用Inkscape,Paint.NET和GIMP的组合制作了上述来源中未使用的图标.(Icons not used from the above source were made by me using a combination of Inkscape, Paint.NET and GIMP.)
有最后的话(Having The Last Word)
为此.现有的应用程序可以进行许多增强,从一些代码重构开始,以增强UI,添加计时器,音乐,图形和效果,多人游戏? (hmmm)…随时将您的想法付诸实践.(So much for that. There are many enhancements that can be made to the existing application, starting with a bit of code refactoring to enhancing the UI, adding timers, music, graphics and effects, multiplayer? (hmmm)… Feel free to put your ideas into it.) 最后,如果您喜欢文字游戏,我希望Lingo能够在5分钟内吸引您的注意力.(In the end, if you are into word games, I do hope Lingo gets your attention for a fun 5 minutes.) 请享用.(Enjoy.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C#3.0 C# C#2.0 WinXP Vista .NET2.0 VS2008 Visual-Studio VS2005 Dev 新闻 翻译