Android サーバー ゲームに問題があります。1 人のプレーヤーが移動した後、たとえば 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;
}
}
neighbours() と score() は、ボードに色を付けてから、現在のスコアを計算する必要があります。しかし、そうではありません。ただし、ボード (塗りつぶされた) を表す配列は、callGameAddMove(session, Filled) でサーバーに送信されるときに適切に更新されます。
それはどうしてですか?サーバーとの間でリクエストを送受信するために ksoap2 を使用しています。