Skip to content

Commit

Permalink
save game parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
asalamon74 committed Dec 8, 2003
1 parent 7bab3b6 commit 3e7e085
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bin/jtReversi.jad
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIDlet-1: jtReversi, /icons/reversi.png, reversi.jtReversi
MIDlet-Description: Reversi game
MIDlet-Jar-Size: 23570
MIDlet-Jar-Size: 23736
MIDlet-Jar-URL: jtReversi.jar
MIDlet-Name: jtReversi
MIDlet-Vendor: Jataka
Expand Down
Binary file modified bin/jtReversi.jar
Binary file not shown.
44 changes: 39 additions & 5 deletions src/reversi/jtReversi.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,9 @@ record = new byte[1];
System.out.println("load["+i+"]:"+tableArray[i]);
}
System.out.println("saved game");
actPlayer = tableArray[0];
table = new ReversiTable(tableArray,1);
// actPlayer = tableArray[0];
loadGameParameters(tableArray, 0);
table = new ReversiTable(tableArray,3);
gameLoaded = true;
System.out.println("table:"+table);
} else {
Expand Down Expand Up @@ -448,9 +449,10 @@ public void saveRecordStore() {
rs.setRecord(1, record, 0, 1);

System.out.println("save table:\n"+table);
byte []tableByteArray = new byte[18];
table.toByteArray(tableByteArray,1);
tableByteArray[0] = actPlayer;
byte []tableByteArray = new byte[20];
saveGameParameters(tableByteArray, 0);
table.toByteArray(tableByteArray,3);
// tableByteArray[0] = actPlayer;
for( int i=0; i<tableByteArray.length; ++i ) {
System.out.println("save["+i+"]:"+tableByteArray[i]);
}
Expand All @@ -463,6 +465,38 @@ public void saveRecordStore() {
}
}

public void saveGameParameters(byte []byteArray, int offset) {
int index = offset;
//isHuman
byteArray[index] = 0;
if( isHuman[0] ) {
byteArray[index] |= 1;
}
if( isHuman[1] ) {
byteArray[index] |= 2;
}
++index;
//actPlayer
byteArray[index++] = actPlayer;
//turnNum
byteArray[index++] = (byte)turnNum;
}

public void loadGameParameters(byte []byteArray, int offset) {
int index = offset;
isHuman[0] = isHuman[1] = false;
if( (byteArray[index] & 1) > 0 ) {
isHuman[0] = true;
}
if( (byteArray[index] & 2) > 0 ) {
isHuman[1] = true;
}
twoplayer = isHuman[0] && isHuman[1];
++index;
actPlayer = byteArray[index++];
turnNum = byteArray[index++];
}

public class SplashScreen extends Canvas {
private Display display;
private Displayable next;
Expand Down

0 comments on commit 3e7e085

Please sign in to comment.