/** Játék mentése */
public void saveGame(Session session) throws TableException {
_gui.debug("Saving...");
String id = session.getUser().getID();
ITable table = session.getTable();
long timespent = session.getTimeSpent();
String content = "";
int x = table.getColumnCount();
int y = table.getRowCount();
for (int j = 0; j < y; j++) {
for (int i = 0; i < x; i++) {
Position pos = new Position(i, j);
switch (table.getType(pos)) {
case ITable.BLACK_NONE:
{
content = content + "-|-";
break;
}
case ITable.BLACK_VERTICAL:
{
int vsum = table.getSum(pos, ITable.SUM_VERTICAL);
content = content + integerToString(vsum,2) + "/-";
break;
}
case ITable.BLACK_HORIZONTAL:
{
int hsum = table.getSum(pos, ITable.SUM_HORIZONTAL);
content = content + "-/" + integerToString(hsum,2);
break;
}
case ITable.BLACK_BOTH:
{
int vsum = table.getSum(pos, ITable.SUM_VERTICAL);
int hsum = table.getSum(pos, ITable.SUM_HORIZONTAL);
content = content + integerToString(vsum,2) + "/" + integerToString(hsum,2);
break;
}
case ITable.WHITE:
{
int normalValue = table.readCell(pos, ITable.VALUE_NORMAL);
int trueValue = table.readCell(pos, ITable.VALUE_TRUE);
content = content + integerToString(normalValue,1) + "=" + integerToString(trueValue,1);
break;
}
}
if((j == y-1) && (i == x-1))
content = content + ';';
else
content = content + ',';
}
}
try{
stmt.executeUpdate("delete from game where game.UserID='"+session.getUser().getID()+"' and TableID='"+integerToString(table.getSkeletonId(), 8)+"'");
query = "INSERT INTO game VALUES(?,?,?,?)";
PreparedStatement ps = (PreparedStatement) con.prepareStatement(query);
ps.setString(1, id);
ps.setString(2, integerToString(session.getTable().getSkeletonId(), 8));
ps.setString(3, ""+timespent);