如何在命运之轮中检查正确答案

本文关键字:检查 答案 命运 | 更新日期: 2023-09-27 18:19:51

我有这个命运之轮应用程序。轮子是一个整体。当车轮停止旋转时,我能够旋转并检测角度。这是它的代码:

private void SpinBtn_Click(object sender, RoutedEventArgs e)
        {
            var ease = new PowerEase { EasingMode = EasingMode.EaseOut };
            Random rng = new Random(Guid.NewGuid().GetHashCode());
            //DoubleAnimation(FromValue. ToValue, Duration)
            double degree = rng.Next(360, 720);
            DoubleAnimation myanimation = new DoubleAnimation
                    (0, degree, new Duration(TimeSpan.FromSeconds(3)));
            double resultAngle = degree - 360;
            double num = resultAngle % 45;
            double quadrant = num + 1;

            data.Content = resultAngle;
            //Adding Power ease to the animation
            myanimation.EasingFunction = ease;
            RotateTransform rotate = new RotateTransform();
            img.RenderTransform = rotate;
            img.RenderTransformOrigin = new Point(0.5, 0.5);
            rotate.BeginAnimation(RotateTransform.AngleProperty, myanimation);

        }

但是,我如何检查用户将单词拖到文本框中是否与指针指向的图像相符?我的讲师要求我将单词(我从数据库中得到的)存储到一个数组中,并将对象编号存储到数组中,但我不知道如何做到这一点。例如,1号物体将处于0-45的角度范围,2号物体处于46-90的角度范围等等。我该如何进行检查?

如何在命运之轮中检查正确答案

我不太确定我是否完全理解了这里的问题!但是,您可以简单地使用Dictionary来保存每个45度切片的字符串值,并根据用户拖动的单词进行检查。

Dictionary<int, string> dict = new Dictionary<int, string>();
dict.Add(1, "Eraser");
dict.Add(2, "Glue");
dict.Add(3, "Pen");
dict.Add(4, "Scissors");
dict.Add(5, "Stapler");
dict.Add(6, "Sharpener");
dict.Add(7, "Ruler");
dict.Add(8, "Pencil");

并将您的代码更改为:

double degree = rng.Next(360, 720);
double resultAngle = degree - 360;
int num = (int)Math.Ceiling(resultAngle / 45);

然后,指针当前指向的元素的名称将是:

string currentElem = dict[num];