简体   繁体   中英

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. Obviously you'd need to handle (or ignore) the exception which is thrown if the same letter was used again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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