DroidFish: Moved game status strings to strings.xml.

This commit is contained in:
Peter Osterlund 2011-12-17 01:33:22 +00:00
parent cf312a2b20
commit 045cb8a700
5 changed files with 96 additions and 52 deletions

View File

@ -337,4 +337,18 @@ you are not actively using the program.\
<string name="comment_before">Before:</string>
<string name="comment_move">Move:</string>
<string name="comment_after">After:</string>
<string name="whites_move">White\'s move</string>
<string name="blacks_move">Black\'s move</string>
<string name="ponder">ponder</string>
<string name="thinking">thinking</string>
<string name="analyzing">analyzing</string>
<string name="white_mate">Game over, white mates!</string>
<string name="black_mate">Game over, black mates!</string>
<string name="stalemate">Game over, draw by stalemate!</string>
<string name="draw_rep">Game over, draw by repetition!</string>
<string name="draw_50">Game over, draw by 50 move rule!</string>
<string name="draw_no_mate">Game over, draw by impossibility of mate!</string>
<string name="draw_agree">Game over, draw by agreement!</string>
<string name="resign_white">Game over, white resigns!</string>
<string name="resign_black">Game over, black resigns!</string>
</resources>

View File

@ -112,7 +112,6 @@ public class DroidFish extends Activity implements GUIInterface {
// FIXME!!! Online play on FICS
// FIXME!!! Add chess960 support
// FIXME!!! Make program translatable
// FIXME!!! Implement "hint" feature
// FIXME!!! Don't send "stop" command when engine is already stopped
@ -800,7 +799,60 @@ public class DroidFish extends Activity implements GUIInterface {
}
@Override
public void setStatusString(String str) {
public void setStatus(GameStatus s) {
String str;
switch (s.state) {
case ALIVE:
str = Integer.valueOf(s.moveNr).toString();
if (s.white)
str += ". " + getString(R.string.whites_move);
else
str += "... " + getString(R.string.blacks_move);
if (s.ponder) str += " (" + getString(R.string.ponder) + ")";
if (s.thinking) str += " (" + getString(R.string.thinking) + ")";
if (s.analyzing) str += " (" + getString(R.string.analyzing) + ")";
break;
case WHITE_MATE:
str = getString(R.string.white_mate);
break;
case BLACK_MATE:
str = getString(R.string.black_mate);
break;
case WHITE_STALEMATE:
case BLACK_STALEMATE:
str = getString(R.string.stalemate);
break;
case DRAW_REP: {
str = getString(R.string.draw_rep);
if (s.drawInfo.length() > 0)
str = str + " [" + s.drawInfo + "]";
break;
}
case DRAW_50: {
str = getString(R.string.draw_50);
if (s.drawInfo.length() > 0)
str = str + " [" + s.drawInfo + "]";
break;
}
case DRAW_NO_MATE:
str = getString(R.string.draw_no_mate);
break;
case DRAW_AGREE:
str = getString(R.string.draw_agree);
break;
case RESIGN_WHITE:
str = getString(R.string.resign_white);
break;
case RESIGN_BLACK:
str = getString(R.string.resign_black);
break;
default:
throw new RuntimeException();
}
setStatusString(str);
}
private final void setStatusString(String str) {
status.setText(str);
}

View File

@ -21,10 +21,10 @@ package org.petero.droidfish;
import java.util.ArrayList;
import java.util.List;
import org.petero.droidfish.gamelogic.Game;
import org.petero.droidfish.gamelogic.Move;
import org.petero.droidfish.gamelogic.Position;
/** Interface between the GUI and the ChessController. */
public interface GUIInterface {
@ -34,8 +34,18 @@ public interface GUIInterface {
/** Mark square i as selected. Set to -1 to clear selection. */
public void setSelection(int sq);
final static class GameStatus {
public Game.GameState state = Game.GameState.ALIVE;
public int moveNr = 0;
public String drawInfo = ""; // Move required to claim draw, or empty string
public boolean white = false;
public boolean ponder = false;
public boolean thinking = false;
public boolean analyzing = false;
}
/** Set the status text. */
public void setStatusString(String str);
public void setStatus(GameStatus status);
/** Update the list of moves. */
public void moveListUpdated();

View File

@ -614,17 +614,23 @@ public class DroidChessController {
}
final private void updateGUI() {
String str;
if (game.getGameState() == Game.GameState.ALIVE) {
str = Integer.valueOf(game.currPos().fullMoveCounter).toString();
str += game.currPos().whiteMove ? ". White's move" : "... Black's move";
GUIInterface.GameStatus s = new GUIInterface.GameStatus();
s.state = game.getGameState();
if (s.state == Game.GameState.ALIVE) {
s.moveNr = game.currPos().fullMoveCounter;
s.white = game.currPos().whiteMove;
if (computerThread != null)
str += humansTurn() ? " (ponder)" : " (thinking)";
if (analysisThread != null) str += " (analyzing)";
if (humansTurn())
s.ponder = true;
else
s.thinking = true;
if (analysisThread != null)
s.analyzing = true;
} else {
str = game.getGameStateString();
if ((s.state == GameState.DRAW_REP) || (s.state == GameState.DRAW_50))
s.drawInfo = game.getDrawInfo();
}
gui.setStatusString(str);
gui.setStatus(s);
updateMoveList();
StringBuilder sb = new StringBuilder();

View File

@ -200,46 +200,8 @@ public class Game {
}
}
public final String getGameStateString() {
switch (getGameState()) {
case ALIVE:
return "";
case WHITE_MATE:
return "Game over, white mates!";
case BLACK_MATE:
return "Game over, black mates!";
case WHITE_STALEMATE:
case BLACK_STALEMATE:
return "Game over, draw by stalemate!";
case DRAW_REP:
{
String ret = "Game over, draw by repetition!";
String drawInfo = tree.getGameStateInfo();
if (drawInfo.length() > 0) {
ret = ret + " [" + drawInfo+ "]";
}
return ret;
}
case DRAW_50:
{
String ret = "Game over, draw by 50 move rule!";
String drawInfo = tree.getGameStateInfo();
if (drawInfo.length() > 0) {
ret = ret + " [" + drawInfo + "]";
}
return ret;
}
case DRAW_NO_MATE:
return "Game over, draw by impossibility of mate!";
case DRAW_AGREE:
return "Game over, draw by agreement!";
case RESIGN_WHITE:
return "Game over, white resigns!";
case RESIGN_BLACK:
return "Game over, black resigns!";
default:
throw new RuntimeException();
}
public final String getDrawInfo() {
return tree.getGameStateInfo();
}
/**