- Diagonal lines are no longer removed.
This commit is contained in:
@@ -17,16 +17,6 @@ public class Board {
|
||||
// a Ply is a play by 1 side. Increments each time setTile() is called.
|
||||
private int numPlies = 0;
|
||||
|
||||
public Board(Board that) {
|
||||
board = new TileColor[NUM_ROWS][NUM_COLS];
|
||||
|
||||
for (int r = 0; r < NUM_ROWS; r++) {
|
||||
for (int c = 0; c < NUM_COLS; c++) {
|
||||
this.board[r][c] = that.board[r][c];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Board() {
|
||||
board = new TileColor[NUM_ROWS][NUM_COLS];
|
||||
for (int r = 0; r < NUM_ROWS; r++) {
|
||||
@@ -36,12 +26,14 @@ public class Board {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + Arrays.hashCode(board);
|
||||
return result;
|
||||
public Board(Board that) {
|
||||
board = new TileColor[NUM_ROWS][NUM_COLS];
|
||||
|
||||
for (int r = 0; r < NUM_ROWS; r++) {
|
||||
for (int c = 0; c < NUM_COLS; c++) {
|
||||
this.board[r][c] = that.board[r][c];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,6 +65,14 @@ public class Board {
|
||||
return numPlies / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + Arrays.hashCode(board);
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isPlayerTurn() {
|
||||
return numPlies % 2 == 0;
|
||||
}
|
||||
@@ -151,76 +151,79 @@ public class Board {
|
||||
remove.addAll(hold);
|
||||
}
|
||||
|
||||
// We decided to get rid of diagonals. If we ever decide to bring
|
||||
// them back, all we have to do is un-comment this code.
|
||||
|
||||
// Check descending diagonal.
|
||||
count = 0;
|
||||
hold = new ArrayList<CellPointer>();
|
||||
int row = cp.r;
|
||||
int col = cp.c;
|
||||
loop: while (row >= 0 && col >= 0) {
|
||||
if (board[row][col] == tile) {
|
||||
hold.add(new CellPointer(row, col));
|
||||
count++;
|
||||
} else {
|
||||
break loop;
|
||||
}
|
||||
|
||||
row--;
|
||||
col--;
|
||||
}
|
||||
|
||||
row = cp.r + 1;
|
||||
col = cp.c + 1;
|
||||
loop: while (row < NUM_ROWS && col < NUM_COLS) {
|
||||
if (board[row][col] == tile) {
|
||||
hold.add(new CellPointer(row, col));
|
||||
count++;
|
||||
} else {
|
||||
break loop;
|
||||
}
|
||||
|
||||
row++;
|
||||
col++;
|
||||
}
|
||||
|
||||
if (count >= ROW_REMOVAL_SIZE) {
|
||||
remove.addAll(hold);
|
||||
}
|
||||
|
||||
// Check ascending diagonal.
|
||||
count = 0;
|
||||
hold = new ArrayList<CellPointer>();
|
||||
|
||||
row = cp.r;
|
||||
col = cp.c;
|
||||
loop: while (row < NUM_ROWS && col >= 0) {
|
||||
if (board[row][col] == tile) {
|
||||
hold.add(new CellPointer(row, col));
|
||||
count++;
|
||||
} else {
|
||||
break loop;
|
||||
}
|
||||
|
||||
row++;
|
||||
col--;
|
||||
}
|
||||
|
||||
row = cp.r - 1;
|
||||
col = cp.c + 1;
|
||||
loop: while (row >= 0 && col < NUM_COLS) {
|
||||
if (board[row][col] == tile) {
|
||||
hold.add(new CellPointer(row, col));
|
||||
count++;
|
||||
} else {
|
||||
break loop;
|
||||
}
|
||||
|
||||
row--;
|
||||
col++;
|
||||
}
|
||||
|
||||
if (count >= ROW_REMOVAL_SIZE) {
|
||||
remove.addAll(hold);
|
||||
}
|
||||
// count = 0;
|
||||
// hold = new ArrayList<CellPointer>();
|
||||
// int row = cp.r;
|
||||
// int col = cp.c;
|
||||
// loop: while (row >= 0 && col >= 0) {
|
||||
// if (board[row][col] == tile) {
|
||||
// hold.add(new CellPointer(row, col));
|
||||
// count++;
|
||||
// } else {
|
||||
// break loop;
|
||||
// }
|
||||
//
|
||||
// row--;
|
||||
// col--;
|
||||
// }
|
||||
//
|
||||
// row = cp.r + 1;
|
||||
// col = cp.c + 1;
|
||||
// loop: while (row < NUM_ROWS && col < NUM_COLS) {
|
||||
// if (board[row][col] == tile) {
|
||||
// hold.add(new CellPointer(row, col));
|
||||
// count++;
|
||||
// } else {
|
||||
// break loop;
|
||||
// }
|
||||
//
|
||||
// row++;
|
||||
// col++;
|
||||
// }
|
||||
//
|
||||
// if (count >= ROW_REMOVAL_SIZE) {
|
||||
// remove.addAll(hold);
|
||||
// }
|
||||
//
|
||||
// // Check ascending diagonal.
|
||||
// count = 0;
|
||||
// hold = new ArrayList<CellPointer>();
|
||||
//
|
||||
// row = cp.r;
|
||||
// col = cp.c;
|
||||
// loop: while (row < NUM_ROWS && col >= 0) {
|
||||
// if (board[row][col] == tile) {
|
||||
// hold.add(new CellPointer(row, col));
|
||||
// count++;
|
||||
// } else {
|
||||
// break loop;
|
||||
// }
|
||||
//
|
||||
// row++;
|
||||
// col--;
|
||||
// }
|
||||
//
|
||||
// row = cp.r - 1;
|
||||
// col = cp.c + 1;
|
||||
// loop: while (row >= 0 && col < NUM_COLS) {
|
||||
// if (board[row][col] == tile) {
|
||||
// hold.add(new CellPointer(row, col));
|
||||
// count++;
|
||||
// } else {
|
||||
// break loop;
|
||||
// }
|
||||
//
|
||||
// row--;
|
||||
// col++;
|
||||
// }
|
||||
//
|
||||
// if (count >= ROW_REMOVAL_SIZE) {
|
||||
// remove.addAll(hold);
|
||||
// }
|
||||
|
||||
for (CellPointer cell : remove) {
|
||||
board[cell.r][cell.c] = TileColor.NONE;
|
||||
|
||||
@@ -3,7 +3,6 @@ package view;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@@ -29,10 +28,10 @@ public class UserChooserFrame extends JFrame {
|
||||
"Here should go some rules text. Lorem ipsum dolor sit amet, consectetur adipiscing elit...");
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Player comPlayer;
|
||||
private final JButton playButton = new JButton("Play!");
|
||||
private final JComboBox<String> userNameBox = new JComboBox<String>();
|
||||
private ArrayList<String> users;
|
||||
private final Player comPlayer;
|
||||
|
||||
public UserChooserFrame(ParsedArgs parsedArgs) {
|
||||
this.comPlayer = parsedArgs.getComPlayer();
|
||||
@@ -85,29 +84,6 @@ public class UserChooserFrame extends JFrame {
|
||||
playButton.addActionListener(psActionListener);
|
||||
}
|
||||
|
||||
void launchSelectedPlayer() {
|
||||
String name = ((String) userNameBox.getSelectedItem());
|
||||
name = name == null ? name : name.trim().toLowerCase();
|
||||
|
||||
if (name != null && name.compareTo("") != 0) {
|
||||
UserChooserFrame.this.setVisible(false);
|
||||
|
||||
boolean found = false;
|
||||
for (int i = 0; !found && i < users.size(); i++) {
|
||||
if (name.compareTo(users.get(i)) == 0) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
users.add(name);
|
||||
}
|
||||
|
||||
saveUserList();
|
||||
new MainFrame(name, comPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
private void initLayout() {
|
||||
GridBagLayout gbl = new GridBagLayout();
|
||||
|
||||
@@ -165,4 +141,27 @@ public class UserChooserFrame extends JFrame {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
void launchSelectedPlayer() {
|
||||
String name = ((String) userNameBox.getSelectedItem());
|
||||
name = name == null ? name : name.trim().toLowerCase();
|
||||
|
||||
if (name != null && name.compareTo("") != 0) {
|
||||
UserChooserFrame.this.setVisible(false);
|
||||
|
||||
boolean found = false;
|
||||
for (int i = 0; !found && i < users.size(); i++) {
|
||||
if (name.compareTo(users.get(i)) == 0) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
users.add(name);
|
||||
}
|
||||
|
||||
saveUserList();
|
||||
new MainFrame(name, comPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user