/* * Othello2.java * * Created on 21. Oktober 2004, 22:20 */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import java.lang.*; import java.util.*; public class BACKUP_Othello2 extends JFrame implements ActionListener { /** Creates new form Othello2 */ public BACKUP_Othello2() { wClock = new Stopwatch(); bClock = new Stopwatch(); initComponents(); picture.setIcon(createBoard()); whiteIcon = createIcon("images/white.gif"); blackIcon = createIcon("images/black.gif"); Matrix(boardSize); possibleMoves(getPlayer()); wClock.start(); repaint(); //Register a listener for the game controls. jButton1.addActionListener(this); jButton2.addActionListener(this); } /** Returns an ImageIcon, or null if the path was invalid. */ private ImageIcon createBoard() { String path = "images/8x8.gif"; java.net.URL imgURL = Othello2.class.getResource(path); if (imgURL != null) { return new ImageIcon(imgURL); } else { System.err.println("Couldn't find file: " + path); return null; } } private ImageIcon createIcon(String path) { java.net.URL imgURL = Othello2.class.getResource(path); if (imgURL != null) { return new ImageIcon(imgURL); } else { System.err.println("Couldn't find file: " + path); return null; } } private Dimension setWindowSize() { int pad_x = 275; int pad_y = 100; Dimension d = new Dimension(DIM + pad_x, DIM + pad_y); return d; } private void setWScore(int wS) {wScore = wS;} private void setBScore(int bS) {bScore = bS;} public void paint(Graphics g) { int addX=0, addY=0; addX = 70; addY = 115;//118; jLabel10.setText(wClock.getTimeString(wClock.getSeconds())); jLabel12.setText(bClock.getTimeString(bClock.getSeconds())); if (whiteIcon != null && blackIcon != null) { double x = (picture.getWidth() - (2 * cutoffX)) / boardSize; double y = (picture.getHeight() - (2 * cutoffY)) / boardSize; for (int i = 0; i < boardSize; ++i) { for (int j = 0; j < boardSize; ++j) { if (boardMatrix[i][j] == WHITE) whiteIcon.paintIcon(picture, g, (int)(x * i) + addX, (int)(y * j) + addY); else if (boardMatrix[i][j] == BLACK) blackIcon.paintIcon(picture, g, (int)(x * i) + addX, (int)(y * j) + addY); } } } } private void Matrix(int bs) { boardMatrix = new int[bs][bs]; for (int i = 0; i != bs; i++) { for (int j = 0; j != bs; j++) { // first part of the number (x) encodes the occupation of the field (0,1,2), second part (= y)the scoring (xyy) // black if (i == bs/2 - 1 && j == bs/2 - 1 || i == (bs/2) && j == (bs/2) ) { boardMatrix [i][j] = BLACK ; // white } else if (i == bs/2 - 1 && j == (bs/2) || i == (bs/2) && j == (bs/2 - 1) ) { boardMatrix [i][j] = WHITE; } else { // not occupied boardMatrix [i][j] = EMPTY; } } } } // checking matrix for possible moves and save them in an array private void possibleMoves(boolean pl) { int m=0, n=0, player = 0, opponent=0, q=0; Vector flipV = new Vector(); Direction dir = new Direction(); if (pl) { player = WHITE; opponent = BLACK; } else { player = BLACK; opponent = WHITE; } // setting the player matrix and the flip matrix to 0 / null for (int i = 0; i != boardSize; i++) { for (int j = 0; j != boardSize; j++) { playerMatrix[i][j] = 0; flipM[i][j] = null; } } for (int i = 0; i != boardSize; i++) { for (int j = 0; j != boardSize; j++) { if (boardMatrix[i][j] == EMPTY){ // column going down if(i < boardSize - 1 && boardMatrix[i+1][j] == opponent) { n = 0; for (m = i+2; m != boardSize; m++) { if(boardMatrix[m][j] == player && n == 0) { n = 1; playerMatrix[i][j] = POSSIBLE; // saving direactions dir.dx = 0; dir.dy = 1; flipV.add(dir); } else if( boardMatrix[m][j]== EMPTY && n == 0) { n = 1; } } } // column going up if(i > 1 && boardMatrix[i-1][j] == opponent) { n = 0; for (m = i-2; m >= 0; m--) { if(boardMatrix[m][j] == player && n == 0) { n = 1;; playerMatrix[i][j] = POSSIBLE; // saving direactions dir.dx = 0; dir.dy = -1; flipV.add(dir); } else if( boardMatrix[m][j]== EMPTY && n == 0) { n = 1; } } } // row going right if(j < boardSize - 1 && boardMatrix[i][j+1] == opponent) { n = 0; for (m = j+2; m != boardSize; m++) { if(boardMatrix[i][m] == player && n == 0) { n = 1; playerMatrix[i][j] = POSSIBLE; // saving direactions dir.dx = 1; dir.dy = 0; flipV.add(dir); } else if( boardMatrix[i][m]== EMPTY && n == 0) { n = 1; } } } // row going left if(j > 1 && boardMatrix[i][j-1] == opponent) { n = 0; for (m = j-2; m >= 0; m--) { if(boardMatrix[i][m] == player && n == 0) { n = 1; playerMatrix[i][j] = POSSIBLE; // saving direactions dir.dx = -1; dir.dy = 0; flipV.add(dir); } else if( boardMatrix[i][m]== EMPTY && n == 0) { n = 1; } } } // diagonal from upper left to lower right if(i < boardSize - 1 && j < boardSize - 1 && boardMatrix[i+1][j+1] == opponent) { n = 0; if(i>j) { q = j+2; for (m = i+2; m != boardSize; m++){ if(boardMatrix[m][q] == player && n == 0 ){ n = 1; playerMatrix[i][q] = POSSIBLE; // saving direactions dir.dx = 1; dir.dy = 1; flipV.add(dir); } else if(boardMatrix[m][q]== EMPTY && n == 0){ n = 1; } q = q + 1; } } else { m = i + 2; for (q = j+2; q != boardSize; q++) { if(boardMatrix[m][q] == player && n ==0) { n = 1; playerMatrix[i][j] = POSSIBLE; // saving direactions dir.dx = 1; dir.dy = 1; flipV.add(dir); } else if(boardMatrix[m][q] == EMPTY && n == 0) { n = 1; } m++; } } } // diagonal from lower left to upper right if(i > 1 && j < boardSize - 1 && boardMatrix[i-1][j+1] == opponent) { n = 0; if(i+j >= 7) { m = i-2; for (q = j+2; q != boardSize; q++){ if(boardMatrix[m][q] == player && n == 0 ){ n = 1; playerMatrix[i][j] = POSSIBLE; // saving direactions dir.dx = 1; dir.dy = -1; flipV.add(dir); } else if(boardMatrix[m][q]== EMPTY && n == 0){ n = 1; } m = m - 1; } } else { q = j + 2; for (m = i-2; m >= 0; m--) { if(boardMatrix[m][q] == player && n == 0) { n = 1; playerMatrix[i][j] = POSSIBLE; // saving direactions dir.dx = 1; dir.dy = -1; flipV.add(dir); } else if(boardMatrix[m][q] == EMPTY && n == 0) { n = 1; } q = q + 1; } } } // diagonal from lower right to upper left if(i > 1 && j > 1 && boardMatrix[i-1][j-1] == opponent) { n = 0; if(i>=j) { m = i-2; for (q = j-2; q >= 0; q--){ if(boardMatrix[m][q] == player && n == 0 ){ n = 1; playerMatrix[i][j] = POSSIBLE; // saving direactions dir.dx = -1; dir.dy = -1; flipV.add(dir); } else if(boardMatrix[m][q]== EMPTY && n == 0){ n = 1; } m = m - 1; } } else { q = j - 2; for (m = i-2; m >= 0; m--) { if(boardMatrix[m][q] == player && n ==0) { n = 1; playerMatrix[i][j] = POSSIBLE; // saving direactions dir.dx = -1; dir.dy = -1; flipV.add(dir); } else if(boardMatrix[m][q] == EMPTY && n == 0) { n = 1; } q = q - 1; } } } // diagonal from upper right to lower left if(i < boardSize - 1 && j > 1 && boardMatrix[i+1][j-1] == opponent) { n = 0; if(i+j>=7) { q = j-2; for (m = i+2; m != boardSize; m++){ if(boardMatrix[m][q] == player && n == 0 ){ n = 1; playerMatrix[i][j] = POSSIBLE; // saving direactions dir.dx = -1; dir.dy = 1; flipV.add(dir); } else if(boardMatrix[m][q]== EMPTY && n == 0){ n = 1; } q = q - 1; } } else { m = i + 2; for (q = j-2; q >= 0; q--) { if(boardMatrix[m][q] == player && n ==0) { n = 1; playerMatrix[i][j] = POSSIBLE; // saving direactions dir.dx = -1; dir.dy = 1; flipV.add(dir); } else if(boardMatrix[m][q] == EMPTY && n == 0) { n = 1; } m = m + 1; } } } //System.out.println("flipVsave:"+ flipV.size()); flipM[i][j] = flipV; /* if(flipV.size() != 0) { System.out.println("i (x): " + i); System.out.println("j (y): " + j); System.out.println("MATRIX SAVED: " + flipM[i][j]); }*/ flipV = new Vector(); } } } } // x any y hold the position that was clicked public void flip(boolean pl, int X, int Y) { int m=0, n=0, p=0, player = 0, opponent=0, q=0; if (pl) { player = WHITE; opponent = BLACK; System.out.println("Player: " + player); } else { player = BLACK; opponent = WHITE; System.out.println("Player: " + player); } if ( X <= boardSize && X >= 0 && Y <= boardSize && Y >= 0) { // checking and maybe changing horizontally from left to right if (X < boardSize - 1) { if (boardMatrix[X+1][Y] == opponent) { n = 0; p = 0; for (m = X+1; m != boardSize; m++) { if (boardMatrix[m][Y] == opponent && p == 0) { n++; } else if (boardMatrix[m][Y] == player && p == 0) { p = 1; } else if (boardMatrix[m][Y] == EMPTY && p == 0) { p = 2; } } if (p == 1) { for (m = X; m <= X + n; m++) { boardMatrix[m][Y] = player; System.out.println("horizontal: " + m + " " + Y); } boardMatrix[X][Y] = player; } } } // checking and maybe changing horizontally from right to left if (X > 0) { if (boardMatrix[X-1][Y] == opponent && X > 0) { n = 0; p = 0; for (m = X-1; m >= 0; m--) { if (boardMatrix[m][Y] == opponent && p == 0) { n++; } else if (boardMatrix[m][Y] == player && p == 0) { p = 1; } else if (boardMatrix[m][Y] == EMPTY && p == 0) { p = 2; } } if (p == 1) { for (m = X; m >= X - n; m--) { boardMatrix[m][Y] = player; System.out.println("horizontal: " + m + " " + Y); } boardMatrix[X][Y] = player; } } } // checking and maybe changing vertically from top to bottom if (Y < boardSize - 1) { if (boardMatrix[X][Y+1] == opponent) { n = 0; p = 0; for (m = Y+1; m != boardSize; m++) { if (boardMatrix[X][m] == opponent && p == 0) { n++; } else if (boardMatrix[X][m] == player && p == 0) { p = 1; } else if (boardMatrix[X][m] == EMPTY && p == 0) { p = 2; } } if (p == 1) { for (m = Y; m <= Y + n; m++) { boardMatrix[X][m] = player; System.out.println("vertical " + X + " " + m); } boardMatrix[X][Y] = player; } } } // checking and maybe changing vertically from bottom to top if (Y > 0) { if (boardMatrix[X][Y-1] == opponent) { n = 0; p = 0; for (m = Y-1; m >= 0; m--) { if (boardMatrix[X][m] == opponent && p == 0) { n++; } else if (boardMatrix[X][m] == player && p == 0) { p = 1; } else if (boardMatrix[X][m] == EMPTY && p == 0) { p = 2; } } if (p == 1) { for (m = Y; m >= Y - n; m--) { boardMatrix[X][m] = player; System.out.println("vertical " + X + " " + m); } boardMatrix[X][Y] = player; } } } // checking and maybe changing diagonally from upper left to lower right if (X < boardSize - 1 && Y < boardSize - 1) { if (boardMatrix[X+1][Y+1] == opponent) { n = 0; p = 0; if (X >= Y) { q = Y + 1; for (m = X+1; m != boardSize; m++) { if (boardMatrix[m][q] == opponent && p == 0) { n++; } else if (boardMatrix[m][q] == player && p == 0) { p = 1; } else if (boardMatrix[m][q] == EMPTY && p == 0) { p = 2; } q++; } } else { m = Y; for (q = Y; q != boardSize; q++) { if (boardMatrix[m][q] == opponent && p == 0) { n++; } else if (boardMatrix[m][q] == player && p == 0) { p = 1; } else if (boardMatrix[m][q] == EMPTY && p == 0) { p = 2; } m++; } } if (p == 1) { q = X; for (m = Y; m <= Y + n; m++) { boardMatrix[q][m] = player; System.out.println("diagonal_1: " + q + " " + m); q++; } boardMatrix[X][Y] = player; } } } // checking and maybe changing diagonally from lower right to upper left if (X > 0 && Y > 0) { if (boardMatrix[X-1][Y-1] == opponent) { n = 0; p = 0; if (X >= Y) { m = X - 1; for (q = Y - 1; q >= 0; q--) { if (boardMatrix[m][q] == opponent && p == 0) { n++; } else if (boardMatrix[m][q] == player && p == 0) { p = 1; } else if (boardMatrix[m][q] == EMPTY && p == 0) { p = 2; } m--; } } else { q = Y - 1; for (m = X - 1; m >= 0; m--) { if (boardMatrix[m][q] == opponent && p == 0) { n++; } else if (boardMatrix[m][q] == player && p == 0) { p = 1; } else if (boardMatrix[m][q] == EMPTY && p == 0) { p = 2; } q--; } } if (p == 1) { q = X; for (m = Y; m >= Y - n; m--) { boardMatrix[q][m] = player; System.out.println("diagonal_1: " + q + " " + m); q--; } boardMatrix[X][Y] = player; } } } // checking and maybe changing diagonally from lower left to upper right if (X > 0 && Y < boardSize - 1) { if (boardMatrix[X-1][Y+1] == opponent) { n = 0; p = 0; if (X + Y >= 7) { m = X - 1; for (q = Y + 1; q != boardSize; q++) { if (boardMatrix[m][q] == opponent && p == 0) { n++; } else if (boardMatrix[m][q] == player && p == 0) { p = 1; } else if (boardMatrix[m][q] == EMPTY && p == 0) { p = 2; } m--; } } else { q = Y + 1; for (m = X - 1; m >= 0; m--) { if (boardMatrix[m][q] == opponent && p == 0) { n++; } else if (boardMatrix[m][q] == player && p == 0) { p = 1; } else if (boardMatrix[m][q] == EMPTY && p == 0) { p = 2; } q++; } } if (p == 1) { q = X; for (m = Y; m <= Y + n; m++) { boardMatrix[q][m] = player; System.out.println("diagonal_2: " + q + " " + m); q--; } boardMatrix[X][Y] = player; } } } // checking and maybe changing diagonally from upper right to lower left if (X < boardSize -1 && Y > 0) { if (boardMatrix[X+1][Y-1] == opponent) { n = 0; p = 0; if (X + Y >= 7) { q = Y - 1; for (m = X + 1; m != boardSize; m++) { if (boardMatrix[m][q] == opponent && p == 0) { n++; } else if (boardMatrix[m][q] == player && p == 0) { p = 1; } else if (boardMatrix[m][q] == EMPTY && p == 0) { p = 2; } q--; } } else { m = X + 1; for (q = Y - 1; q >= 0; q--) { if (boardMatrix[m][q] == opponent && p == 0) { n++; } else if (boardMatrix[m][q] == player && p == 0) { p = 1; } else if (boardMatrix[m][q] == EMPTY && p == 0) { p = 2; } m++; } } if (p == 1) { q = X; for (m = Y; m >= Y - n; m--) { boardMatrix[q][m] = player; System.out.println("diagonal_2: " + q + " " + m); q++; } boardMatrix[X][Y] = player; } } } } } public void printMatrix(int[][] matrix) { for (int i = 0; i != boardSize; i++) { for (int j = 0; j != boardSize; j++) { if (j < (boardSize - 1)) System.out.print(matrix[i][j]+""); else System.out.println(matrix[i][j]+""); } } System.out.println(""); } // flipping pices public void flip2(boolean pl, int X, int Y) { int player; int opponent; boolean isBreak; if (pl) { player = WHITE; opponent = BLACK; } else { player = BLACK; opponent = WHITE; } System.out.println("X: "+ X); System.out.println("Y: "+ Y); System.out.println("MATRIX: " + flipM[X][Y]); Vector curV = (Vector)flipM[X][Y]; System.out.println("curV.size: " + curV.size()); for (int i = 0; i != curV.size(); i++) { isBreak = false; Direction dir = (Direction)curV.get(i); System.out.println("dx: " + dir.dx); System.out.println("dy: " + dir.dy); for (int j = Y + dir.dy; j != boardSize && j != 0; j += dir.dy) { int k = X + dir.dx; for (; k != boardSize && k != 0; k += dir.dx) { System.out.println("j: " + j); System.out.println("k: " + k); if (player != boardMatrix[k][j]) { boardMatrix[k][j] = player; printMatrix(boardMatrix); } else { isBreak = true; break; } } if (isBreak) break; } } repaint(); } // getting the square of the Click private void pictureMouseClicked(java.awt.event.MouseEvent evt) { // getting the X value mouseX = evt.getX(); // getting the Y value mouseY = evt.getY(); getPosition(mouseX, mouseY, boardSize); } // mouseX, mouseY and bs to get the position of the click private void getPosition(int m_x, int m_y, int bs) { if (m_x > cutoffX && m_x < picture.getWidth() - cutoffX && m_y > cutoffY && m_y < picture.getHeight() - cutoffY) { double x; double y; x = picture.getWidth(); y = picture.getHeight(); x = (x - 2 * (double)cutoffX)/boardSize; y = (y - 2 * (double)cutoffY)/boardSize; curX = (double)(m_x - cutoffX)/x; curX = Math.ceil(curX); curY = (double)(m_y - cutoffY)/y; curY = Math.ceil(curY); if (getPlayer() && boardMatrix[(int)curX-1][(int)curY-1] == EMPTY && playerMatrix[(int)curX-1][(int)curY-1] == POSSIBLE) { //boardMatrix[(int)curX-1][(int)curY-1] = WHITE; System.out.println("Before flipping..."); printMatrix(boardMatrix); int old[][] = boardMatrix; flip(getPlayer(), (int)(curX-1), (int)(curY-1)); System.out.println("After flipping..."); printMatrix(boardMatrix); countScore(old, boardMatrix); wClock.stop(); bClock.start(); changePlayer(); possibleMoves(player); repaint(); } else if (!getPlayer() && boardMatrix[(int)curX-1][(int)curY-1] == EMPTY && playerMatrix[(int)curX-1][(int)curY-1] == POSSIBLE) { //boardMatrix[(int)curX-1][(int)curY-1] = BLACK; System.out.println("Before flipping..."); printMatrix(boardMatrix); int old[][] = boardMatrix; flip(getPlayer(), (int)(curX-1), (int)(curY-1)); System.out.println("After flipping..."); printMatrix(boardMatrix); countScore(old, boardMatrix); bClock.stop(); wClock.start(); changePlayer(); possibleMoves(player); repaint(); } } } private void countScore(int[][] oldMatrix, int[][] newMatrix) { int oldW = 0, oldB = 0, newW = 0, newB = 0, score = 0; for (int i = 0; i != boardSize; i++) { for (int j = 0; j != boardSize; j++) { if (oldMatrix[i][j] == WHITE) oldW++; if (oldMatrix[i][j] == BLACK) oldB++; if (newMatrix[i][j] == WHITE) newW++; if (newMatrix[i][j] == BLACK) newB++; } } diffB = newB - oldB; diffW = newW - oldW; setBScore(newB); setWScore(newW); } private void changePlayer() { player = !player; } private boolean getPlayer() { return player; } public void initComponents() {//GEN-BEGIN:initComponents setTitle("O-Thell-Us"); setBackground(Color.white); setDefaultLookAndFeelDecorated(true); setResizable(false); java.awt.GridBagConstraints gridBagConstraints; jPanel1 = new JPanel(); jPanel1.setPreferredSize(setWindowSize()); jPanel1.setBackground(Color.white); jPanel2 = new JPanel(); jPanel2.setBackground(Color.white); picture = new JLabel(); jLabel6 = new JLabel(); jLabel11 = new JLabel(); jTextField6 = new JTextField(); jTextField8 = new JTextField(); jPanel3 = new JPanel(); jPanel3.setBackground(Color.white); jLabel7 = new JLabel(); jLabel8 = new JLabel(); jLabel10 = new JLabel(wClock.getTimeString(wClock.getSeconds())); jLabel12 = new JLabel(bClock.getTimeString(bClock.getSeconds())); jLabel9 = new JLabel(); java.awt.GridBagConstraints gridBagConstraints2; jPanel11 = new JPanel(); jPanel11.setBackground(Color.white); jPanel11.setBorder(new javax.swing.border.TitledBorder("Game Controls")); jLabel1 = new JLabel(); jLabel1.setBackground(Color.white); jComboBox1 = new JComboBox(); jComboBox1.setBackground(Color.white); jButton1 = new JButton(); jButton2 = new JButton(); picture.addMouseListener( new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { pictureMouseClicked(evt); } }); addWindowListener( new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { exitForm(evt); } }); jPanel1.setLayout(new java.awt.GridBagLayout()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridheight = 4; gridBagConstraints.insets = new Insets(10,10,10,10); gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; jPanel1.add(picture, gridBagConstraints); // adding the game's logo jLabel9.setIcon(createIcon("images/logo2.gif")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; jPanel1.add(jLabel9, gridBagConstraints); jPanel2.setLayout(new java.awt.GridBagLayout()); jPanel2.setBorder(new javax.swing.border.TitledBorder("White")); jLabel6.setText("Elapsed Time"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.insets = new Insets(0,10,0,0); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; jPanel2.add(jLabel6, gridBagConstraints); jLabel11.setText("Score"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.insets = new Insets(0,10,0,0); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; jPanel2.add(jLabel11, gridBagConstraints); jLabel10.setBackground(Color.white); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.insets = new Insets(10,10,10,10); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.ipadx = 1; jPanel2.add(jLabel10, gridBagConstraints); jTextField6.setText(wScore+""); jTextField6.setEditable(false); jTextField6.setBackground(Color.white); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; gridBagConstraints.insets = new Insets(10,10,10,10); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.ipadx = 2; jPanel2.add(jTextField6, gridBagConstraints); // adding white's statistics gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; jPanel1.add(jPanel2, gridBagConstraints); jPanel3.setLayout(new java.awt.GridBagLayout()); jPanel3.setBorder(new javax.swing.border.TitledBorder("Black")); jLabel7.setText("Elapsed Time"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.insets = new Insets(0,10,0,0); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; jPanel3.add(jLabel7, gridBagConstraints); jLabel8.setText("Score"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.insets = new Insets(0,10,0,0); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; jPanel3.add(jLabel8, gridBagConstraints); jLabel12.setBackground(Color.white); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.insets = new Insets(10,10,10,10); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; jPanel3.add(jLabel12, gridBagConstraints); jTextField8.setText(bScore+""); jTextField8.setEditable(false); jTextField8.setBackground(Color.white); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.insets = new Insets(10,10,10,10); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; jPanel3.add(jTextField8, gridBagConstraints); // adding black's statistics gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; jPanel1.add(jPanel3, gridBagConstraints); // start oth1 jPanel11.setLayout(new java.awt.GridBagLayout()); jComboBox1.setModel(new DefaultComboBoxModel(new String[] { "Human vs. Computer", "Human vs. Human", "Computer vs. Human" })); gridBagConstraints2 = new java.awt.GridBagConstraints(); gridBagConstraints2.gridx = 2; gridBagConstraints2.gridy = 0; gridBagConstraints2.insets = new Insets(0,0,10,0); jPanel11.add(jComboBox1, gridBagConstraints2); jButton1.setText("Start New Game"); gridBagConstraints2 = new java.awt.GridBagConstraints(); gridBagConstraints2.gridx = 2; gridBagConstraints2.gridy = 8; gridBagConstraints2.ipadx = 25; gridBagConstraints2.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints2.insets = new Insets(20, 4, 0, 0); jPanel11.add(jButton1, gridBagConstraints2); jButton2.setText("Quit"); gridBagConstraints2 = new java.awt.GridBagConstraints(); gridBagConstraints2.gridx = 2; gridBagConstraints2.gridy = 9; gridBagConstraints2.ipadx = 25; gridBagConstraints2.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints2.insets = new Insets(20, 4, 10, 0); jPanel11.add(jButton2, gridBagConstraints2); // add game controls gridBagConstraints2 = new java.awt.GridBagConstraints(); gridBagConstraints2.gridx = 1; gridBagConstraints2.gridy = 3; jPanel1.add(jPanel11, gridBagConstraints2); getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER); pack(); setVisible(true); }//GEN-END:initComponents /** Exit the Application */ private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm System.exit(0); }//GEN-LAST:event_exitForm /** * @param args the command line arguments */ public static void main(String args[]) { new Othello2().show(); } public void actionPerformed(ActionEvent e) { if(e.getSource() == jButton1) { playerMode = jComboBox1.getSelectedIndex(); if (playerMode == -1) System.err.println("Error in combobox!"); } if(e.getSource() == jButton2) { System.exit(0); } } // Variables declaration private JLabel jLabel6; private JLabel jLabel7; private JLabel jLabel8; private JLabel jLabel9; private JLabel jLabel10; // white clock private JLabel jLabel11; private JLabel jLabel12; // black clock private JPanel jPanel1; private JPanel jPanel2; private JPanel jPanel3; private JTextField jTextField6; //score private JTextField jTextField8; private JLabel picture; private JButton jButton1; private JButton jButton2; private JComboBox jComboBox1; private JLabel jLabel1; private JPanel jPanel11; private int mouseX; private int mouseY; private double scaleX; private double scaleY; private double cutoffX = 32; // 8: 33, 32; 12: 32, 34; 16: 34, 34 private double cutoffY = 32; // 8: 32, 32; 12: 32, 32; 16: 32, 33 private double curX = 0; private double curY = 0; private int boardSize = 8; private int playerMode; private int boardMatrix[][]; private boolean player = true; //white = true private int playerMatrix[][] = new int[boardSize][boardSize]; private Vector flipM[][] = new Vector[boardSize][boardSize]; private static final int BLACK = 0; private static final int WHITE = 1; private static final int EMPTY = 2; private static final int POSSIBLE = 3; private static final int DIM = 465; private int wScore = 2; private int bScore = 2; private int diffB = 0; private int diffW = 0; private ImageIcon whiteIcon; private ImageIcon blackIcon; private Stopwatch wClock; private Stopwatch bClock; // End of variables declaration } class Direction { short dx; short dy; }