我应该如何为游戏“ Lingo”等字母着色

时间:2019-12-21 10:07:30

标签: c#

我正在创建相同的Lingo(See video on YouTube)仅单词游戏。我的问题是黄色块(用词表示,但不正确)没有正确显示。所有字母均显示为黄色,但位置不正确。出现黄色字母的数字代表乱序的代表会发生什么情况。我要说的是什么?

        Label[,] labels = new Label[6, 5]{    {l01, l02, l03, l04, l05} ,
                                              {l06, l07, l08, l09, l10} ,
                                              {l11, l12, l13, l14, l15} ,
                                              {l16, l17, l18, l19, l20} ,
                                              {l21, l22, l23, l24, l25} ,
                                              {l26, l27, l28, l29, l30} ,
        };

        TableLayoutPanel[,] blocks = new TableLayoutPanel[6, 5]{    {v1, v2, v3, v4, v5} ,
                                                                    {v6, v7, v8, v9, v10} ,
                                                                    {v11, v12, v13, v14, v15} ,
                                                                    {v16, v17, v18, v19, v20} ,
                                                                    {v21, v22, v23, v24, v25} ,
                                                                    {v26, v27, v28, v29, v30} ,
        };

        Label[,] l = labels;
        TableLayoutPanel[,] v = blocks;

        public static string first_word File.ReadLines(@"link to text file").Skip(word_number - 1)
        public string[] mistery_word = first_word.Select(c => c.ToString()).ToArray();
        public string[] compair_letters = { " ", " ", " ", " ", " "};
        public string[] correct_letters = { " ", " ", " ", " ", " "};

按键盘上的字母时,正方形中的标签会更改。按下Enter键将检查:

    int a = 0;
    int b = 0;
    int c = 0;

    for (a = 0; a < 5; a++)
    {
        if (l[current_line, a].Text == mistery_word[a]) // So the same = correct
        {
             compair_letters[a] = "0";
             correct_letters[a] = l[current_line, a].Text;
        }
    }

    for (a = 0; a < 5; a++)
   {
      if (mistery_word.Contains(l[current_line, a].Text))
      {
          compair_letters[a] = "1";
      }
     } 

for (c = 0; c < 5; c++)
                    {
                        switch (compair_letters[c])
                        {
                            case "0":
                                Correct here
                            case "1":
                                Half here;
                            case "2":
                                Wrong here
                            default:
                                Wrong
                        }
                    }     

Result untill now

我还要循环播放3倍(3rth正在着色)。有没有更聪明的方法?

1 个答案:

答案 0 :(得分:0)

第二个循环类似(未经测试!):

for (a = 0; a < 5; a++)
{
    String current_letter = l[current_line, a].Text;
    String correctLetters = ""
    for (b=0; b<5; b++) { if (b!=a) { correctLetters += correct_letters[b]; }}
    if (mistery_word.Contains(current_letter) && !correctLetters.Contains(current_letter) )
    {
        compair_letters[a] = "1";
    }
}

进一步思考之后,我创建了下一件事:

public static string[] check_word_for_lingo(string guess, string secret_word)
{
    String[] checks = new string[5];
    char[] remainingLettersToCheck = secret_word.ToCharArray();
    char[] secretWordLetters = secret_word.ToCharArray();

    for (int a=0; a<5; a++)
    {
        if (guess[a]==secret_word[a])
        {
            checks[a] = "0"; remainingLettersToCheck[a] = ' ';
        } else {
            checks[a] = " ";
        }
    }
    secret_word = new string(remainingLettersToCheck);

    for (int a = 0; a < 5; a++)
    {
        if (remainingLettersToCheck[a] != ' ')
        {
            if (guess[a] != ' ' && secret_word.Contains(guess[a]))
            {
                checks[a] = "1"; remainingLettersToCheck[a] = ' ';
            }
            else
            {
                checks[a] = "2";
            }
        }
    }

    return checks;
}

它的用法如下:

String[] checks = new string[5];

string guess = "SOEEE";
string secret_word = "SMORE";
checks = check_word_for_lingo(guess, secret_word);

Console.WriteLine(guess);
Console.WriteLine(secret_word);
int i = 0;
foreach (var item in checks)
{
    Console.Write(item);
    i++;
}

将输出: 国电 更多 01220

使用单词“ SOEOE”进行测试仍然会返回错误的答案(01210)