二维阵列在网格中间向前方向打印字母

发布于 2024-12-17 07:16:52 字数 1474 浏览 0 评论 0原文

public void fill(ArrayList<String> a1) {
    int i = 0;
    while (i < a1.size()) {
        if (i == 0) {
            for (int j = 0; j < a1.get(i).length(); j++)
                crossword[ROWS / 2][(COLUMNS / 4) + j] = a1.get(i)
                        .charAt(j);
            i++;
        }
        if (i == 1) {
            outerloop: for (int t = 0; t < ROWS; t++)
                for (int s = 0; s < COLUMNS; s++)
                    for (int j = 0; j < a1.get(i).length(); j++)
                        if (crossword[t][s] == a1.get(i).charAt(j)) {
                            for (int z = 0; z < j; z++)
                                crossword[t - z - 1][s] = a1.get(i).charAt(
                                        z);
                            for (int h = j + 1; h < a1.get(i).length(); h++)
                                crossword[t + h - j][s] = a1.get(i).charAt(
                                        h);
                            crossword[t][s] = a1.get(i).charAt(j);
                            break outerloop;
                        }
            i++;
        }
    }
}

以上是我在填字游戏板上使单词列表的前两个单词相互交叉的方法。我的问题是针对该部分的:

 for (int z = 0; z < j; z++)
 crossword[t - z - 1][s] = a1.get(i).charAt(z);

它获取交点前面的字母并将它们向后打印在交点行上方。我的大脑现在已经被不同的东西超载了,我似乎不明白如何让字母按正确的顺序排列。我无法附加图像来显示我的问题,但例如,垂直单词“投掷”与字母“o”处的水平单词“clowning”相交,在o之前打印出“rht”(当它应该打印出“ thr”)。有人可以帮忙吗?将不胜感激!

public void fill(ArrayList<String> a1) {
    int i = 0;
    while (i < a1.size()) {
        if (i == 0) {
            for (int j = 0; j < a1.get(i).length(); j++)
                crossword[ROWS / 2][(COLUMNS / 4) + j] = a1.get(i)
                        .charAt(j);
            i++;
        }
        if (i == 1) {
            outerloop: for (int t = 0; t < ROWS; t++)
                for (int s = 0; s < COLUMNS; s++)
                    for (int j = 0; j < a1.get(i).length(); j++)
                        if (crossword[t][s] == a1.get(i).charAt(j)) {
                            for (int z = 0; z < j; z++)
                                crossword[t - z - 1][s] = a1.get(i).charAt(
                                        z);
                            for (int h = j + 1; h < a1.get(i).length(); h++)
                                crossword[t + h - j][s] = a1.get(i).charAt(
                                        h);
                            crossword[t][s] = a1.get(i).charAt(j);
                            break outerloop;
                        }
            i++;
        }
    }
}

The above is my method to make the first two words of a list of words intersect each other on a crossword puzzle board. My question is for the part:

 for (int z = 0; z < j; z++)
 crossword[t - z - 1][s] = a1.get(i).charAt(z);

It takes the letters in front of the intersection point and prints them backwards above the intersection row. My brain is overloaded with different things right now and I can't seem to understand how to make the letters go in the right order. I can't attach an image to display my problem but for example the vertical word "throwing" which intersects with horizontal word "clowning" at the letter "o" prints out "rht" before the o (when it should be printing out "thr"). Could someone help? Would be much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丢了幸福的猪 2024-12-24 07:16:52

这就能解决问题:
for (int z = 0; z < j; z++)
crossword[t - j + z][s] = a1.get(i).charAt(z);

PS 该问题尚未结束(即使您确实回答了问题)。您应该将此答案(或者,如果您不想给我分数,则将您输入的答案)标记为正确,这样问题就不会留在未回答的部分!

This will do the trick:
for (int z = 0; z < j; z++)
crossword[t - j + z][s] = a1.get(i).charAt(z);

P.S. This question hasn't been closed yet (even though you did respond to your question). You should flag this answer (or, if you don't feel like giving me points, an answer that you put in) as correct, so that the question doesn't remain in the unanswered section!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文