Fix get() method in GomokuBoard and save() method in GomokuGame
This commit is contained in:
@@ -129,6 +129,8 @@ public class GomokuBoard{
|
|||||||
* @return GomokuCell in the position.
|
* @return GomokuCell in the position.
|
||||||
*/
|
*/
|
||||||
public GomokuCell get(int x, int y){
|
public GomokuCell get(int x, int y){
|
||||||
|
if (x < 0 || x >= this.boardWidth) return null;
|
||||||
|
if (y < 0 || y >= this.boardHeight) return null;
|
||||||
int i = 0, j = 0;
|
int i = 0, j = 0;
|
||||||
GomokuCell act = this.firstCell;
|
GomokuCell act = this.firstCell;
|
||||||
while (i != x || j != y){
|
while (i != x || j != y){
|
||||||
|
|||||||
@@ -147,13 +147,13 @@ public class GomokuGame {
|
|||||||
// Write the board
|
// Write the board
|
||||||
for (int i = 0; i < this.getBoard().getHeight(); ++i) {
|
for (int i = 0; i < this.getBoard().getHeight(); ++i) {
|
||||||
for (int j = 0; j < this.getBoard().getWidth(); ++j) {
|
for (int j = 0; j < this.getBoard().getWidth(); ++j) {
|
||||||
char c = ' ';
|
char c;
|
||||||
switch (board.get(i, j).getState()) {
|
switch (board.get(i, j).getState()) {
|
||||||
case BLACK:
|
case BLACK:
|
||||||
c = 'X';
|
c = 'X';
|
||||||
break;
|
break;
|
||||||
case WHITE:
|
case WHITE:
|
||||||
|
c = 'O';
|
||||||
break;
|
break;
|
||||||
case NIL:
|
case NIL:
|
||||||
c = '.';
|
c = '.';
|
||||||
|
|||||||
Reference in New Issue
Block a user