WURDZ,一个令人上瘾的文字游戏-用随机字母制作单词!(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/wurdz-an-addictive-word-game-make-words-from-rando-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 10 分钟阅读 - 4785 个词 阅读量 0WURDZ,一个令人上瘾的文字游戏-用随机字母制作单词!(译文)
原文地址:https://www.codeproject.com/Articles/12617/WURDZ-An-Addictive-Word-Game-Make-Words-from-Rando
原文作者:Koushik Biswas
译文由本站 robot-v1.0 翻译
前言
Written using pure C# WinForms, WURDZ is a completely new idea in the world of word games! This will be one game which will be as much fun to play as it will be to study its code, if not more. You make meaningful words from a random stream of letters, and score points.
使用纯C#WinForms编写的WURDZ在文字游戏领域是一个全新的想法!这将是一款游戏,即使没有更多的乐趣,它也会像研究代码一样有趣.您可以从随机字母流和得分中获得有意义的单词.
- 下载源代码465.3 KB(Download source code - 465.3 KB)
- 仅下载游戏文件(用于播放)-353.5 KB(Download only game files (for playing) - 353.5 KB)
介绍(Introduction)
玩了拼字游戏后,我一直想成为(After playing scrabble, I always wanted to be the)发明者(inventor)一个新的文字游戏(好吧,你可以笑).(of a new word game (okay, you can laugh).)新(New),表示以前未曾想到的想法.那里有成千上万的文字游戏,但很少有人提供像拼字游戏这样的无限永不重复的场景.没有两个拼字游戏是相同的.我梦想着发明类似的东西.(, meaning an idea not thought of before. There are a zillion word games out there, but not many offer literally infinite never-repeating scenarios like scrabble. No two scrabble games are the same. I dreamt of inventing something like that.) WURDZ是我的尝试.我真的不相信这样的崇高抱负可以一开始就能真正实现.所以伙计们-如果您之前已经看过类似的东西,或者有一些想法和建议可以使这款游戏与众不同,请给我大喊大叫.(WURDZ is my feeble attempt at it. I seriously don’t believe that such a noble ambition can be truly fulfilled at first try. So guys out there - please give me a shout if you have already seen something like this before, or with ideas and suggestions that will make this game unique.) 这个想法很简单-会有无休止的字母随机流.玩家将使用随机字母创建单词.为了使游戏更具挑战性,它必须同时包含多个单词-这样玩家就需要在玩杂耍并权衡下一个随机字母的放置位置.一旦构建了有意义的单词-玩家将获得积分奖励.游戏也将与TETRIS相似-意思是,您放置的字母越多,对空间的限制就越大-仅当您输入正确的单词时,您才能重新获得空间.因此,双字造词奖励-点数和空格!(The idea is simple - there will be a random stream of never ending letters. The player will use the random letters to create words. To make the game challenging, it has to be multiple words at the same time - so that a player needs to juggle and weigh where to put the next random letter. Once a meaningful word has been constructed - the player will be rewarded with points. The game will also have a resemblance with TETRIS - meaning, the more letters you place, the more restricted for space you will become - and only if you make a correct word, you will regain the space back. So, double reward for making a word - points and space!) 当我第一次点击"(That was my vague idea when I first clicked on “)新项目…(New Project…)在Visual Studio 7.0中…(” in Visual Studio 7.0…)
怎么玩(How to Play)
我不会将本文用作游戏的帮助手册.为此,我花了一个小时在游戏中编写游戏规则(I will not use this article as a help manual for the game. For that, I have spent an hour writing the rules of the game in the)*帮助文件(HELP.TXT)*游戏附带的相反,我将根据CodeProject的文章来使用本文来突出显示代码的有趣方面.(that comes with the game. Rather, I will use this article to highlight the interesting aspects of the code, befitting a CodeProject article.)
有关守则的要点(Points About the Code)
任何文字游戏作者有时都会遇到下面描述的大多数此类问题.(Any word game writer faces most of these issues described below at some time or the other.)
随机字母(Random Letters)
我的字母不仅是随机的(在计算机算法允许的范围内达到伪随机的程度),而且我还面临着提供(Not only are my letters random (to the extent of pseudo-randomness that computer algorithms allow), but I faced the problem of providing a)***公平(fair)***元音和高频字母的混合.例如,如果" Q"在10次中出现4次,那将没有太大帮助.获得" P"," G"和" T"之后,您可能会拼命寻找元音.如果游戏无法及时为您提供元音,您很快就会感到沮丧.如何解决这个问题呢?很简单-看一下拼字游戏的麻袋.你看到了什么? 9’A'-s,X’B'-s,依此类推.在麻袋里放一个字母的次数的比例决定了一个特定字母出现的频率.我从那个比例开始.然后我发现对于WURDZ来说,这是一个很好的起点,但还不够.由于WURDZ具有比拼字游戏更多的同时打开内容,因此,例如,我需要的’Z’比仅1多.因此,我将一些低频数字乘以4或5,将某些高频数字乘以1.5或2.(mix of vowels and high frequency alphabets. For example, if a ‘Q’ turns up 4 out of 10 times, that will not be much helpful. After you get a ‘P’, ‘G’ and ‘T’, you are probably desperately looking for a vowel. If the game cannot provide you with a timely vowel, you will soon get frustrated. How to solve this problem? Simple - look at the scrabble’s sack of tiles. What do you see? 9 ‘A’-s, X ‘B’-s, and so on. The ratio of the number of times you place an alphabet in your sack determines on how frequently a particular letter will appear. I began with that proportion. Then I found out that for WURDZ, that was a good starting point, but not enough. As WURDZ has more simultaneous openings than scrabble, I need, for example, more ‘Z’-s than only 1. So I multiplied some low frequency numbers by 4 or 5 and some high frequency numbers by 1.5 or 2.) 实现很简单-声明一个字符数组,其中包含正确数量的所有字母,如上所述.然后运行"加扰"循环数千次,以使原始阵列(以后将在此处选择)完全加扰.然后,当您需要一个随机字母时,生成一个随机数并在该索引处返回该字母.(The implementation is simple - declare an array of characters containing all the letters in the right quantities as explained above. Then run a “scramble” loop thousands of times to make your original array (where you will pick from later) totally scrambled. Then, when you need a random letter, generate a random number and return the letter at that index.)
字典和加密(Dictionary and Encryption)
古老的问题-是吗?如何感知正确的英语单词?您需要一本字典.我是从在线拼字游戏NETWORDZ那里获得的,它为您提供了一个巨大的文本文件,每行一个单词.我需要所有长度为3到8(即WURDZ支持的长度范围)的有意义的单词.因此,我编写了将列表分成多个相同长度的子列表的程序-现在有6个列表,每个列表包含3到8个相同长度的单词.然后,特别是出于WURDZ的目的,(Age old problem - huh? How to sense a correct English word? You need a dictionary. I took it from NETWORDZ, the online scrabble game, which provides you with a giant text file, one word per line. I needed all meaningful words of length 3 through 8 (that is the length range supported by WURDZ). So I wrote programs to break the list into individual sub lists of same length - 6 lists now, each containing words of the same length, 3 through 8. Then, specifically for the purpose of WURDZ, I do)***不(not)*在第8个字母列表中需要CATAPULT,因为它以CAT开头,并且一旦玩家构建CAT,就将获得积分.因此,我编写了另一个程序,通过消除以短单词开头的单词来缩短每个词典文件.现在,我已经准备好字典文件-6个文件.我将简单地使用(need CATAPULT in the 8 letter list, because it starts with CAT, and as soon as the player constructs CAT, he will be awarded points. So I wrote another program to shorten each dictionary file by eliminating words that share the beginning with some shorter word. Now, I have my dictionary files ready - 6 files. I will simply use an) ArrayList
加载它们.至于检查一个单词的存在,(to load them. As for checking the existence of a word,) ArrayList.Contains()
很有效率.如果我需要检查" SUGT"是否存在,请致电(is quite efficient. If I need to check if “SUGT” exists, I call) Contains()
在(on the) ArrayList
仅包含长度为4的单词-因此搜索时间得以最小化.(containing words of length 4 only - so the search time is minimized.)
那么,加密问题从何而来?您需要将这些词典文件与游戏一起提供,并且为了保持某些开发人员的外观,您可能不希望用户浏览到游戏文件夹,打开包含单词的TXT文件,添加他或她自己喜欢的单词,然后傻瓜游戏.我使用了.NET加密-解密机制.看这个(So, where does the question of encryption come? You need to ship these dictionary files with the game, and to maintain some developer’s clothing, you will probably not want the user to browse to the game folder, open the TXT files containing the words, add his or her own fancy words, and fool the game. I used the .NET encryption - decryption mechanism. Look at this) 文章(article) .我使用此方法加密了6个文件中的每个文件.我使用了不同的键,并用键命名了文件.在WURDZ代码中,我编写了解密例程-使用文件名(而不是扩展名)作为密钥.我使用扩展名让游戏找出此文件中包含多少长度的单词.因此,名称为")_(=!^ {.F5@O0+"的文件意味着它包含长度为6(扩展名的长度)的单词,可以使用密钥")_(=!^
解密". {".用户将看到无意义的二进制文件,他/她无法查看或编辑.(. I encrypted each of the 6 files using this method. I used different keys, and named the files with the keys. In the WURDZ code, I wrote the decryption routine - using the file name (not the extension) as the key. I used the extension to let the game find out words of what length are contained in this file. So a file with name “)_(=!^{.F5@O0+" means that it contains words of length 6 (the length of its extension) and it can be decrypted using the key ")_(=!^
{”. The user will see meaninglessly named binary files which he/she cannot view or edit.)
动态创建后在WinForm上拖放控件(Drag Drop of Controls on a WinForm After Dynamic Creation)
该游戏的基本要求是用户需要将字母拼贴拖动到四个垂直插槽之一中.随着游戏计时器每秒产生一个新字母,保持拖动状态从来都不是一件容易的事.如果您看到我动态创建的充当字母图块的按钮的鼠标向下,鼠标移动和鼠标向上处理程序,您将了解该技术.专注于依赖于(The basic requirement of this game is that the user needs to drag a letter tile to one of the four vertical slots. With the game timer producing one new letter every second, maintaining drag state was never going to be easy. If you see the mouse-down, mouse-move, and mouse-up handlers for the buttons that I create dynamically to behave as letter tiles, you will know the technique. Focus on the blocks of code that are dependent on the) bDragging
变量-其余与拖动无关,但与游戏功能有关.(variable - the rest are not related to dragging but to game functionality.)
我遇到了一个问题-仅使用我刚才提到的代码,就发生了拖动,但是在拖动过程中,如果您猛地(或非常快)移动了鼠标,则拖动的按钮不会跟随光标.突然,您丢失了按钮.缓慢拖动就可以了.我大致解决了这个问题-这次我处理了表单的mouse-move事件(与按钮的mouse-move事件相对).如果(I faced a problem - with just the pieces of code I just mentioned, dragging was happening, but while dragging, if you moved the mouse with a jerk (or very fast), the dragged button was not following the cursor. Suddenly, you lost the button. Slow dragging was OK. I solved this problem in a round about way - I handled the form’s mouse-move event this time (as opposed to the button’s mouse-move event). If) bDragging
是(is) true
,我只是在新的鼠标位置上重新绘制了拖动的按钮-现在,即使您使用超音速喷气飞机来回移动鼠标,拖动的按钮也会挂在您身上!(, I just repainted the dragged button at the new mouse location - and now, even if you move the mouse around using a supersonic jet plane, the dragged button will hang on to you!)
计时器(Timers)
我需要(I needed)**许多(many)**计时器!的(timers! The) Threading.Timers
上课令人失望.不知何故,它最终导致禁用其他计时器.我只用过(class was a disappointment. Somehow, it ends up in disabling other timers. I have used only) Timers.Timer
.闪烁效果(创建正确的单词后)使用计时器.放置字母拼块后,游戏将最多提供四秒钟的时间将其删除.在这四秒钟内,它在字母周围绘制了黄色边界,以视觉传达"您可以在我为时已晚之前删除我".该实现使用计时器.底部有一个有用的注释文本-它继续传达发生的情况.但是在显示的信息失去上下文后,它必须还原为一些有意义的文本.为此使用了计时器.除了所有这些,游戏还由主计时器控制.(. The blinking effect (after a correct word is created) uses a timer. Once you place a letter tile, the game gives you up to four seconds to remove it. In those four seconds, it draws yellow boundaries around the letter, to visually convey that “you can remove me now before it is too late”. That implementation uses a timer. There is a helpful comment text at the bottom - it keeps on relaying what happened. But it must revert back to some meaningful text after the displayed information loses context. A timer has been used for that purpose. In addition to all these, the game is controlled by a master timer.)
其他有趣的地方(Other Interesting Points)
该代码将显示:(The code will show:)
- 如何在不拉伸或歪斜的情况下将图片放入图片框(我通过Googling学习了此技术)-在(How to fit a picture in a picture box without stretching or skewing it (I learnt this technique by Googling) - in the)关于(About)对话框.(dialog box.)
- 如何维护二进制高分数据文件.(How to maintain a binary high scores data file.)
- 如何根据屏幕尺寸动态放置按钮/控件.(How to dynamically place buttons/ controls based on screen size.)
- 如何在运行时创建控件并控制其行为.(How to create controls at runtime and control their behavior.)
谢谢(Thanks)
我从那里借了字母图标(I borrowed the letter icons from) www.iconbazaar.com(www.iconbazaar.com) .(.) 我的妻子通过测试游戏和提出好主意来帮助我!(My wife helped me by testing the game and suggesting great ideas!)
未来(Future)
请给我反馈和建议,以便我可以改善这个游戏.(Please send me feedback and suggestions so that I can improve this game.)
历史(History)
- 5(5)日(th)2006年1月:初始版本(January, 2006: Initial version)
执照(License)
本文没有附带任何明确的许可,但可能在文章文本或下载文件本身中包含使用条款.如有疑问,请通过下面的讨论区与作者联系.可以找到作者可能使用的许可证列表(This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below. A list of licenses authors might use can be found) 这里(here) .(.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ C# VC7.0 .NET Windows Visual-Studio VS.NET2003 Dev 新闻 翻译