GameLogic,X连续游戏 [英] GameLogic, x in a row game

查看:164
本文介绍了GameLogic,X连续游戏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个游戏,我需要做哪些检查,如果指定的单元格是包含相同字符细胞水平的连续序列的一部分的方法。细胞的序列必须是长度l的。如果该细胞是长度的水平序列至少微升一部分,它是真假,否则

I'm making a game and I need to make a method which checks if the specified cell is part of a horizontal consecutive sequence of cells containing the same character. The sequence of cells needs to be of length l. It is true if the cell is part of a horizontal sequence of length at least l, and false otherwise.

到目前为止我认为它检测是否有至少连续5个细胞用相同的字符中指定的字符的行中的任何地方。谁能帮助?

So far I have it that it detects if there are at least 5 consecutive cells with the same character anywhere in the row of the character specified. Can anyone help?

推荐答案

您可以简单地搜索边用两个回路(每边一个)两种,检查是否连续的单元格的总和确实。沿着线的东西:

You can simply search for both sides using two loops (one per side) and check if the sum of consecutive cells is indeed l. Something along the lines of:

public static boolean checkPositionRow(char[][] a, int row, int col, int l) {
    int counter = 1; //starting from 1, because for a[row][col] itself
    char charAtPosition = a[row][col];
   //expand to the right as much as possible
    for (int i = col+1; i < a[row].length && a[row][i] == charAtPosition; i++) counter++;
   //expand to the left as much as possible
    for (int i = col-1; i >= 0 && a[row][i] == charAtPosition; i--) counter++;
    return counter >= l;
}

这篇关于GameLogic,X连续游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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