拼字游戏的问题 [英] Problems with a scrabble game

查看:103
本文介绍了拼字游戏的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我正在制作类似于拼字游戏的游戏。我的程序有没有办法确保用户输入的单词是一个单词?如果有人能回答这个问题,那将非常有帮助。



更新



我已经找到在线词典但是我如何将这些结合到我的代码中呢?

Okay, so I am making a game similar to scrabble. Is there a way my program can make sure the word that the user inputs is a word? If anybody can answer this it would be very helpful.

Update

I have already found online dictionaries but how would I incorporate these into my code?

推荐答案





看看这里:

http://stackoverflow.com/a/9864021 [ ^ ]

Hi,

Have a look here:
http://stackoverflow.com/a/9864021[^]

确切的拼字游戏用语位于 source-forge (只是原始的单词所以它就是你所追求的)。它位于文件sowpods.txt.gz中的scrabbledict-vvv-win.zip中。 sowpods 是单词列表的名称。

The exact scrabble diction is hosted on source-forge (just raw words so it's what you're after). It's in the scrabbledict-vvv-win.zip in the file "sowpods.txt.gz". sowpods is the name of the word list.

Softpedia有一个免费的英国英语版本。

我会使用Wordnet。你也可以在这里获得unix字典。

I'd go with Wordnet. You can also get the unix dictionary here.

1 英文字典为txt或xml文件,支持同义词 dictionary-as-txt-or-xml-file -with-support-of-synonyms

1: English dictionary as txt or xml file with support of synonyms dictionary-as-txt-or-xml-file-with-support-of-synonyms





首先,阅读文本文件:http://msdn.microsoft.com/en-us/library/vstudio/ezwyzy7b.aspx [ ^ ]

你应该将所有行加载到数组中。并尝试检查给定的单词是否是真正的单词:



First, read the text file: http://msdn.microsoft.com/en-us/library/vstudio/ezwyzy7b.aspx[^]
You should load all lines into the array. And try this to check whether a given word is a real word:

public bool IsRealWord(string word) 
{ 
       return Array.IndexOf(wordArray, word) != -1; 
}

将'wordArray'更改为加载所有单词的数组名称。





不要使用数组,使用 HashSet< string> 。对于 HashSet 数组中的查找单词数为 O(n) >它是 O(1)

Change 'wordArray' into the name of the array in which all words are loaded.


Don't use an Array, use a HashSet<string>. Lookup in the Array is O(n) in the number of words, for the HashSet it is O(1):

  private HashSet<string> RealWords;

// when initializing (needs better error handling):
  RealWords = new HashSet<string>(System.IO.File.ReadAllLines(@"{path to words file}"));
// Then:
public bool IsRealWord(string word) 
{ 
  return RealWords.Contains(word); 
}

[完编辑:Matt T Heffron]

[End Matt T Heffron]


这篇关于拼字游戏的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆