我的Android Server游戏存在问题。在一个玩家进行移动之后,每次发送一个请求到服务器的时间为3秒,以检查另一个玩家是否进行了移动,以便第一个玩家可以再次移动。现在我不知道为什么,但无论我怎么做(使用Thread.sleep()或下面的方法),就像其余代码不存在一样。
if (this.filled[field_id] != 0) // The field was already marked
return;
neighbours(field_id); // Colouring neccesary fields
// Sending updated board to the server:
if (move>0) {
filled[field_id] = current;
GameAndroidUtil.callGameAddMove(session, filled);
switchColourToOpposite(current); // Switching colour to the opposite as our opponent will now take action
}
score(); // Updating the score after our move
if (isBoardFull()){ // Checking if the board is empty
if(white_score>black_score)
Toast.makeText(this, "White won!", Toast.LENGTH_SHORT).show();
else if(white_score<black_score)
Toast.makeText(this, "Black won!", Toast.LENGTH_SHORT).show();
else
Toast.makeText(this, "No winner!", Toast.LENGTH_SHORT).show();
}
// Waiting for the opponent to make his move
boolean different = false;
while (!different) {
long startTime = System.currentTimeMillis();
long endTime = System.currentTimeMillis();
while(endTime!=startTime+3000)
endTime = System.currentTimeMillis();
if (checkChange()) {
different = true;
}
}
neighbors()和score()应该为棋盘着色,然后计算当前分数。但他们没有。但是,代表板(已填充)的数组在callGameAddMove(会话,已填充)中发送到服务器时会正确更新。
怎么会这样?我使用ksoap2向/从服务器发送和接收请求。