简体   繁体   English

在hangman游戏(通过文本框输入)中只接受一封信VB.NET

[英]Only accepting a letter once during a hangman game (entered through a textbox) VB.NET

I have to make a hangman game for a school project and one of the requirements is to only accept a letter once during gameplay. 我必须为一个学校项目制作一个子手游戏,其中一项要求是在玩游戏时只接受一次字母。 I have allowed a user to guess the word by entering letters into a textbox and so I was just wondering if anyone knew how I could validate this? 我已经允许用户通过在文本框中输入字母来猜测单词,所以我只是想知道是否有人知道我可以对此进行验证?

You could store all the letters that the user has already entered into some data structure like hash table(faster) / array(have to iterate through whole array). 您可以将用户已经输入的所有字母存储到某种数据结构中,例如哈希表(更快)/数组(必须遍历整个数组)。 Then when the user enters the next letter in the letterbox , just check against the previously entered characters stored to find if it has been entered before or not. 然后,当用户在信箱中输入下一个字母时,只需对照先前输入的字符进行检查,以查找是否之前输入过。

You could in theory use any collection type, but it would be better to use one that has a built in key eg sortedlist or dictionary which would stop any duplicate letter being added. 从理论上讲,您可以使用任何集合类型,但是最好使用具有内置键的类型,例如sortedlist或Dictionary,这样可以阻止添加任何重复的字母。 Obviously you'd need to handle (or ignore) the exception which is thrown if the same letter was used again. 显然,您需要处理(或忽略)如果再次使用相同的字母会引发的异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM