gpt4 book ai didi

java - 如何检查完整的列?

转载 作者:行者123 更新时间:2023-12-01 13:29:28 25 4
gpt4 key购买 nike

我正在构建一个四子棋游戏,这是我的检查器:

 static final int ROWS = 6;

public void checkIfFull(int colu)
{
/*deleted*/
}

当用户单击按钮时调用此函数:

if (e.getSource () == b1)
{
checkIfFull (0);


}

这是我将代币定位在最低开放水平的方法:

    public void setPos(int column)
{
if (demise) return; //this is for when the game is already over and the user
still attempts to click on a button

int row;
for (row = 0; row < ROWS; ++row)
{
if (slots[row][column] > 0)
break;
}

if (row > 0)
{
//save current player
slots[--row][column] = active;
//change turns
/*if (active == GREEN)
{
active = RED;
activeMe ();
}
else if (active == RED)
{
active = GREEN;
activeMe();
} I moved this to setCircle method*/

setCircle(active, row, column); //gui method used to fill up the empty circle
}


}

当我填写一栏时,Joptionpane 没有弹出,但它应该会弹出。

有什么线索吗?

我仍在不断研究我的逻辑,所以如果您发现其他缺陷,请指出。 :)

最佳答案

您应该检查 counter 是否等于 6,因为您已声明:

static final int ROWS = 6;

所以你必须检查一下:

if (counter == ROWS) // not 5

请注意,您正在与 ROWS 进行比较,而不是直接与 6 进行比较,以避免 "magic numbers" .

另外,在使用计数器之前不要忘记声明并初始化它:

int counter = 0;

关于java - 如何检查完整的列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21654479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com