如何消除C#中aarray边界内的重复用户输入? [英] How to eliminate duplicate user input within the boundries of anarray in C#?

查看:44
本文介绍了如何消除C#中aarray边界内的重复用户输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows 2015 UWP C#中制作游戏,用户在时间限制内输入他们可以想到的以Ac开头的所有单词,并且每个单词的分数变量都会递增。我的C#UWP应用程序中有一个字符串数组,其中包含字典中的所有Ac字样。游戏运行良好,唯一的事情是用户可以根据需要多次输入相同的单词,分数仍然会增加。有没有办法处理重复的用户输入?这是我的代码(不包括数组中大约450多个单词,不包括DispatcherTimer):



I'm making a game in Windows 2015 UWP C# where the user enters in all the words they can think of beginning with 'Ac' within a time limit and a score variable increments with each word. I have a String Array in my C# UWP application containing all of the 'Ac' words in the dictionary. The game works fine, the only thing is that the user can enter in the same word as many times as they want and the score will still increment. Is there any way to deal with duplicate User Input? This is my Code (excluding about 450+ of the words in the array to be brief and excluding the DispatcherTimer):

private void btnEnter_Click(object sender, RoutedEventArgs e)
        {
            imgCorrectSign.Visibility = Visibility.Collapsed;
            imgX.Visibility = Visibility.Collapsed;
            string[] WordsWithAc = new string[] {"e","t","ed","es","he","hy","id"};

            txtUserInput.Text.Distinct();
            if (Array.IndexOf(WordsWithAc, txtUserInput.Text) > -1)
            {
                score += 10;
                txtScore.Text = score.ToString();
                imgCorrectSign.Visibility = Visibility.Visible;
            }
            else
            {
                imgX.Visibility = Visibility.Visible;
            }





wordserror - Postimage .org [ ^ ]



我尝试了什么:



尝试了许多合乎逻辑的解决方法,但是很有新的工作方式数组详细。



wordserror — Postimage.org[^]

What I have tried:

Lots of logical workarounds were tried but kind of new to working with arrays in detail.

推荐答案

你可以使用 Dictionary ,参见: [ ^ ]

还有:藏品 - 具有唯一键和值的C#字典类型 - Stack Overflow [ ^ ]
You can use Dictionary for this, see: [^]
And also: collections - C# dictionary type with unique keys and values - Stack Overflow[^]


这篇关于如何消除C#中aarray边界内的重复用户输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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