介绍
背景
使用代码
1)载入类别和单词:
class WordEntity{ public string Category { get; set; } public string Word { get; set; }}
private string PRESET_WORDS ="COUNTRIES|BANGLADESH|GAMBIA|AUSTRALIA|ENGLAND|NEPAL|INDIA|PAKISTAN|TANZANIA|SRILANKA|CHINA|CANADA|JAPAN|BRAZIL|ARGENTINA|" +"MUSIC|PINKFLOYD|METALLICA|IRONMAIDEN|NOVA|ARTCELL|FEEDBACK|ORTHOHIN|DEFLEPPARD|BEATLES|ADAMS|JACKSON|PARTON|HOUSTON|SHAKIRA|" +...
if (File.Exists(FILE_NAME_FOR_STORING_WORDS)) // If words file exists, then read it. ReadFromFile();else{ // Otherwise create the file and populate from there. string EncryptedWords = StringCipher.Encrypt(PRESET_WORDS, ENCRYPTION_PASSWORD); using (StreamWriter OutputFile = new StreamWriter(FILE_NAME_FOR_STORING_WORDS)) OutputFile.Write(EncryptedWords); ReadFromFile();}
string Str = File.ReadAllText(FILE_NAME_FOR_STORING_WORDS);string[] DecryptedWords = StringCipher.Decrypt(Str, ENCRYPTION_PASSWORD).Split('|');if (DecryptedWords[0].Equals("")) // This means the file was tampered.{ MessageBox.Show("The words file was tampered. Any Categories/Words saved by the player will be lost."); File.Delete(FILE_NAME_FOR_STORING_WORDS); PopulateCategoriesAndWords(); // Circular reference. return;}string Category = "";for (int i = 0; i <= DecryptedWords.GetUpperBound(0); i++){ if (i % (MAX_WORDS + 1) == 0) // Every 15th word is the category name. { Category = DecryptedWords; Categories.Add(Category); } else { WordEntity Word = new WordEntity(); Word.Category = Category; Word.Word = DecryptedWords; WordsList.Add(Word); }}

这篇博客介绍了如何使用C#.NET编写一个完整的字谜游戏,包括载入类别和单词、游戏逻辑以及作弊码功能。代码示例展示了读取和加密单词文件、在网格上放置单词、计分机制以及处理用户输入的过程。此外,还涵盖了检查用户输入的有效性和游戏画布的更新。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



