Documentos de Académico
Documentos de Profesional
Documentos de Cultura
package jgomoku;
public class GomokuGame extends BoardData{
private char winner;
private boolean newGame=true;
private GomokuGameHistory gameHistory;
private boolean isGameOver;
public GomokuGame(){
super();
gameHistory=new GomokuGameHistory();
winner='o';
isGameOver=false;
}
public GomokuGame(int size){
super(size);
gameHistory=new GomokuGameHistory();
winner='o';
isGameOver=false;
}
public GomokuGame(GomokuGameHistory ggh){
gameHistory=ggh;
isGameOver=true;
}
public GomokuGame(char[][] board){
super(15);
this.board=board;
}
@Override
public boolean moveWhite(int row , int column){
if(isGameOver){
return false;
}
boolean result=super.moveWhite(row , column);
if(result){
newGame=false;
gameHistory.addMove(row , column);
gameHistory.getNextMove();
checkWinner('w');
}
}
@Override
public boolean moveBlack(int row , int column){
if(isGameOver){
return false;
}
boolean result=super.moveBlack(row, column);
if(result){
newGame=false;
gameHistory.addMove(row , column);
gameHistory.getNextMove();
checkWinner('b');
}
return result;
}
public Move previousMove(){
return gameHistory.getPreviousMove();
}
public Move nextMove(){
return gameHistory.getNextMove();
}
public boolean saveGame(String file){
return gameHistory.saveGame(file);
}
public boolean checkWinner(char side){
boolean isOver=false;
if(side != 'w'){
if(checkHorizontalWinner('b')){
isOver=true;
}
if(!isOver && checkVerticalWinner('b')){
isOver=true;
}
if(!isOver && checkMainDiagonalWinner('b')){
isOver=true;
}
if(!isOver && checkSecondaryDiagonalWinner('b')){
isOver=true;
}
if(isOver){
winner='b';
isGameOver=true;
return true;
}
}
if(side != 'b'){
if(checkHorizontalWinner('w')){
isOver=true;
}
if(!isOver && checkVerticalWinner('w')){
isOver=true;
}
if(!isOver && checkMainDiagonalWinner('w')){
isOver=true;
}
if(!isOver && checkSecondaryDiagonalWinner('w')){
isOver=true;
}
if(isOver){
winner='w';
isGameOver=true;
return true;
}
}
return false;
}
length=0;
}
return false;
}
private boolean checkVerticalWinner(char side){
int row , column;
int length=0;
for(column=0 ; column<size ; column++){
for(row=0 ; row<size ; row++){
if(board[row][column] == side){
length++;
}
else{
length=0;
}
if(length == 5){
return true;
}
}
length=0;
}
return false;
}
if(length == 5){
return true;
}
length=0;
}
if(length == 5){
return true;
}
}
length=0;
}
length=0;
}
}
//diagonals below and parallel to the main board
matrice diagonal
for(aux=0 ; aux<size-1 ; aux++){
for(row=size-1-aux , column=0 ; row<=size-1 ;
row++ , column++){
if(board[row][column] == side){
length++;
}
else{
length=0;
}
if(length == 5){
return true;
}
}
length=0;
}
return false;
}
return false;
}
package jgomoku;
return m;
}
import java.io.*;
import java.util.*;
if(! gameFinished){
return null;
}
if(currentMove==0){
return null;
}
currentMove--;
m= (Move) moves.get(currentMove);
if(currentMove%2 == 0){
m.isBlack=true;
}
else{
m.isBlack=false;
}
GomokuGameHistory(){
moves=new ArrayList();
gameFinished=false;
currentMove=0;
}
public void addMove(int row , int column){
Move m=new Move(row , column);
moves.add(m);
currentMove++;
}
return m;
public void setGameFinished(){
gameFinished=true;
}
public Move getNextMove(){
Move m;
if(! gameFinished){
return null;
}
if(currentMove == moves.size()){
return null;
}
m= (Move) moves.get(currentMove);
if(currentMove%2 == 0){
m.isBlack=true;
}
else{
m.isBlack=false;
}
currentMove++;
}
public boolean loadGame(String filename){
try {
BufferedReader bfR = new BufferedReader(new
FileReader(filename));
while(true){
try {
String line =bfR.readLine();
if(line == null){
if(moves.size() > 0){
currentMove=0;
gameFinished=true;
return true;
}
return false;
}
int spaceIndex=line.indexOf(" ");
int n1=Integer.parseInt(line.subSequence(0 ,
spaceIndex).toString());
int
n2=Integer.parseInt(line.substring(spaceIndex+1).toString(
));
Move m=new Move(n1 , n2);
moves.add(m);
}
catch (IOException ex) {
ex.printStackTrace();
return false;
}
}
package jgomoku;
public class Move {
public int row;
public int column;
public boolean isBlack;
Move(){
}
Move(int row , int column){
this.row=row;
this.column=column;
}
}
catch (FileNotFoundException ex) {
ex.printStackTrace();
}
return false;
}
public boolean saveGame(String file){
try {
BufferedWriter bfW = new BufferedWriter(new
FileWriter(file));
Iterator<Move> it=moves.iterator();
Move m=null;
while(it.hasNext()){
m=it.next();
bfW.write(m.row + " " + m.column + "\n");
}
bfW.flush();
bfW.close();
return true;
}
catch (IOException ex) {
ex.printStackTrace();
return false;
}
}
}
/*
*Copyright 2008 Cristian Achim
*
* Licensed under the Apache License, Version 2.0 (the
"License");
* you may not use this file except in compliance with the
License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in
writing,
* software distributed under the License is distributed on
an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied.
* See the License for the specific language governing
permissions and
* limitations under the License.
*
*/
package jgomoku;
import java.util.*;
public class GameController/* extends TimerTask*/{
private GomokuGame gomokuGame;
private UserInterface humanUserInterface;
private boolean blackHuman , whiteHuman;
private GomokuGameHistory gameHistory;
private boolean waitMove;
private boolean waitBlack;
private boolean doingReplay;
private Thread t;
GameController(){
humanUserInterface=new
GraphicalInterfaceController(15 , 15);
humanUserInterface.setCallback(this);
waitMove=false;
doingReplay=false;
}
GameController(boolean graphical){
if(graphical == true){
humanUserInterface=new
GraphicalInterfaceController(15 , 15);
}
else{
humanUserInterface=new TextInterface();
}
humanUserInterface.setCallback(this);
waitMove=false;
doingReplay=false;
}
public void newGame(boolean blackHuman , boolean
whiteHuman){
gomokuGame=new GomokuGame(15);
if(blackHuman){
humanUserInterface.printText("waiting for black
move");
}
else{
humanUserInterface.printText("waiting for ai
move");
}
if(t != null){
if(t.isAlive()){
t.interrupt();
}
}
this.blackHuman=blackHuman;
this.whiteHuman=whiteHuman;
this.waitMove=true;
this.waitBlack=true;
if(! blackHuman){
t=new Thread(new
GomokuAi(gomokuGame.exportPositionToAi() , true , this
, 2));
t.start();
}
}
public boolean removeOldGame(){
if(this.waitMove || this.doingReplay){
this.waitMove=false;
this.doingReplay=false;
return true;
}
return false;
}
private void saveGame(String fileName){
if(this.gomokuGame.saveGame(fileName)){
this.humanUserInterface.printText("game saved");
}
else{
this.humanUserInterface.printText("game saving
failed");
}
}
private void loadGame(String fileName){
GomokuGameHistory ggh;
ggh=new GomokuGameHistory();
if(ggh.loadGame(fileName)){
gameHistory=ggh;
gomokuGame=new GomokuGame(gameHistory);
doingReplay=true;
humanUserInterface.setReplayMode();
}
else{
humanUserInterface.printText("game file loading
failed");
}
}
private void makeMove(int row , int column){
if(! this.waitMove){
System.out.println("error not waiting move");
return;
}
if(waitBlack && blackHuman){
if(gomokuGame.moveBlack(row, column)){
if(gomokuGame.isGameOver()){
column);
doingReplay=true;
waitMove=false;
waitBlack=false;
}
else if(whiteHuman){
humanUserInterface.printText("waiting for
white move");
humanUserInterface.getWhiteMove(row ,
column);
waitBlack=false;
}
else{
humanUserInterface.printText("waiting for ai
move");
humanUserInterface.waitAiMove(true , row ,
column);
t=new Thread(new
GomokuAi(gomokuGame.exportPositionToAi() , false , this
, 2));
waitBlack=false;
t.start();
}
//waitBlack=false;-moved into to if elses
}
else{
humanUserInterface.printText("illegal move");
}
}
else if(! waitBlack && whiteHuman){
if(gomokuGame.moveWhite(row, column)){
if(gomokuGame.isGameOver()){
humanUserInterface.printText("white won the
game");
humanUserInterface.gameFinished(false , row ,
column);
doingReplay=true;
waitMove=false;
waitBlack=true;
}
else if(blackHuman){
humanUserInterface.printText("waiting for
black move");
humanUserInterface.getBlackMove(row ,
column);
waitBlack=true;
}
else{
humanUserInterface.printText("waiting for ai
move");
humanUserInterface.waitAiMove(false , row ,
column);
t=new Thread(new
GomokuAi(gomokuGame.exportPositionToAi() , false , this
, 2));
waitBlack=true;
t.start();
}
//waitBlack=true;-moved into the if elses
}
else{
humanUserInterface.printText("illegal move");
}
}
else if(waitBlack && ! blackHuman){
if(gomokuGame.moveBlack(row, column)){
if(gomokuGame.isGameOver()){
humanUserInterface.printText("black won the
game");
humanUserInterface.gameFinished(true , row ,
column);
doingReplay=true;
waitMove=false;
waitBlack=false;
}
else if(whiteHuman){
humanUserInterface.printText("waiting for
white move");
humanUserInterface.getWhiteMove(row,
column);
waitBlack=false;
}
else{
humanUserInterface.printText("waiting for ai
move");
t=new Thread(new
GomokuAi(gomokuGame.exportPositionToAi() , false , this
, 2));
humanUserInterface.waitAiMove(true, row,
column);
waitBlack=false;
t.start();
}
//waitBlack=false;-moved into the if elses
}
else{
humanUserInterface.printText("illegal ai move");
}
}
else if(! waitBlack && ! whiteHuman){
if(gomokuGame.moveWhite(row, column)){
if(gomokuGame.isGameOver()){
humanUserInterface.printText("white won the
game");
humanUserInterface.gameFinished(false, row,
column);
doingReplay=true;
waitMove=false;
waitBlack=true;
}
else if(blackHuman){
humanUserInterface.printText("waiting for
black move");
humanUserInterface.getBlackMove(row,
column);
waitBlack=true;
}
else{
humanUserInterface.printText("waiting for ai
move");
t=new Thread(new
GomokuAi(gomokuGame.exportPositionToAi() , true , this
, 2));
humanUserInterface.waitAiMove(false, row,
column);
waitBlack=true;
t.start();
}
//waitBlack=true;-moved to the if elses
}
else{
humanUserInterface.printText("illegal ai move");
}
}
else{
humanUserInterface.printText("weird boolean
error");
}
}
private void previousMove(){
if(doingReplay){
Move m=gomokuGame.previousMove();
if(m == null){
humanUserInterface.printText("reached first
move");
}
else{
if(m.isBlack){
humanUserInterface.removeBlack(m.row,
m.column);
}
else{
humanUserInterface.removeWhite(m.row,
m.column);
}
}
}
else{
humanUserInterface.printText("error no game
replay");
}
}
private void nextMove(){
if(doingReplay){
Move m=gomokuGame.nextMove();
if(m == null){
humanUserInterface.printText("reached last
move");
}
else{
if(m.isBlack){
humanUserInterface.moveBlack(m.row,
m.column);
}
else{
humanUserInterface.moveWhite(m.row,
m.column);
}
}
}
else{
humanUserInterface.printText("error no game
replay");
}
}
//the callback function from gomokuai ,
graphicalinterface or textinterface
public void sendPlayerInput(String input){
String token;
StringTokenizer st=new StringTokenizer(input);
int value1 , value2;
boolean blackHuman , whiteHuman;
/*
* all posible input commands:
*
* move row column
* previous
* next
* new blackplayer whiteplayer ;
whiteplayer,blackplayer=human | computer
* load filelocationandnamestring
* save filelocationandnamestring
*/
if(! st.hasMoreTokens()){
return;
}
token=st.nextToken();
if(token.equals("move")){
if(! st.hasMoreTokens()){
return;
}
token=st.nextToken();
if(! st.hasMoreTokens()){
return;
}
token=st.nextToken();
try{
value1=Integer.parseInt(token);
}
catch(Exception e){
e.printStackTrace();
return;
}
if(! st.hasMoreTokens()){
return;
}
token=st.nextToken();
if(token.equals("human")){
whiteHuman=true;
}
else if(token.equals("computer")){
whiteHuman=false;
}
else{
return;
}
try{
value2=Integer.parseInt(token);
}
catch(Exception e){
e.printStackTrace();
return;
}
newGame(blackHuman , whiteHuman);
}
else if(token.equals("load")){
if(! st.hasMoreTokens()){
return;
}
token=st.nextToken();
makeMove(value1 , value2);
}
else if(token.equals("previous")){
previousMove();
}
else if(token.equals("next")){
nextMove();
}
else if(token.equals("new")){
if(! st.hasMoreTokens()){
return;
}
token=st.nextToken();
loadGame(token);
}
else if(token.equals("save")){
if(! st.hasMoreTokens()){
return;
}
token=st.nextToken();
saveGame(token);
}
}
}
if(token.equals("human")){
blackHuman=true;
}
else if(token.equals("computer")){
blackHuman=false;
}
else{
return;
}
package jgomoku;
import java.awt.image.*;
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.RenderingHints;
import javax.swing.JFileChooser;
public class GraphicalInterface extends javax.swing.JPanel
{
imageReader=this.getClass().getResourceAsStream("/artw
ork/whitestone.png");
whiteStone=ImageIO.read(imageReader);
imageReader.close();
imageReader=this.getClass().getResourceAsStream("/artw
ork/middlenode.png");
middleNode=ImageIO.read(imageReader);
imageReader.close();
imageReader=this.getClass().getResourceAsStream("/artw
ork/northnode.png");
northNode=ImageIO.read(imageReader);
imageReader.close();
imageReader=this.getClass().getResourceAsStream("/artw
ork/eastnode.png");
eastNode=ImageIO.read(imageReader);
imageReader.close();
imageReader=this.getClass().getResourceAsStream("/artw
ork/northeastnode.png");
northEastNode=ImageIO.read(imageReader);
imageReader.close();
imageReader=this.getClass().getResourceAsStream("/artw
ork/southeastnode.png");
southEastNode=ImageIO.read(imageReader);
imageReader.close();
imageReader=this.getClass().getResourceAsStream("/artw
ork/southnode.png");
southNode=ImageIO.read(imageReader);
imageReader.close();
imageReader=this.getClass().getResourceAsStream("/artw
ork/southwestnode.png");
southWestNode=ImageIO.read(imageReader);
imageReader.close();
imageReader=this.getClass().getResourceAsStream("/artw
ork/westnode.png");
westNode=ImageIO.read(imageReader);
imageReader.close();
imageReader=this.getClass().getResourceAsStream("/artw
ork/northwestnode.png");
northWestNode=ImageIO.read(imageReader);
imageReader.close();
}
catch(Exception e){
e.printStackTrace();
}
}
/** Creates new form GInterface */
public GraphicalInterface(GraphicalInterfaceController
gic , int maxrow , int maxcolumn) {
this.gic=gic;
MAXROW=maxrow;
MAXCOLUMN=maxcolumn;
imageInitialisation();
initComponents();
newGameButton.setEnabled(false);
saveGameButton.setEnabled(false);
boardCanvas.setSize(450, 450);
boardImage=new BufferedImage(450 , 450 ,
BufferedImage.TYPE_INT_ARGB);
drawAllBackgroundCells();
}
}
else{
img=middleNode;
}
drawBackImage(img , row , column);
}
public void drawBlackStone(int row , int column){
BufferedImage img=blackStone;
drawBackImage(img , row+1 , column+1);
flipBackImage();
}
public void drawWhiteStone(int row , int column){
BufferedImage img=whiteStone;
drawBackImage(img , row+1 , column+1);
flipBackImage();
}
if(result == JFileChooser.APPROVE_OPTION){
targetFile=fc.getSelectedFile();
}
if(targetFile != null){
return targetFile.getAbsolutePath();
}
return null;
height=boardCanvas.getHeight();
width=boardCanvas.getWidth();
}
cellWidth=width/MAXCOLUMN;
cellHeight=height/MAXROW;
imageWidth=img.getWidth(this);
imageHeight=img.getHeight(this);
g=(Graphics2D) boardImage.getGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION ,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(img , cellWidth * (column - 1) ,
cellHeight * (row - 1) , cellWidth , cellHeight , this);
jLabel1.setText("black player");
nextMoveButton.setText("Next move");
nextMoveButton.addMouseListener(new
java.awt.event.MouseAdapter() {
public void
mouseClicked(java.awt.event.MouseEvent evt) {
nextMoveButtonMouseClicked(evt);
}
});
whitePlayerComboBox.setModel(new
javax.swing.DefaultComboBoxModel(new String[] {
"Human", "Computer" }));
startGameButton.setText("Start game");
startGameButton.addMouseListener(new
java.awt.event.MouseAdapter() {
public void
mouseClicked(java.awt.event.MouseEvent evt) {
startGameButtonMouseClicked(evt);
}
});
blackPlayerComboBox.setModel(new
javax.swing.DefaultComboBoxModel(new String[] {
"Human", "Computer" }));
newGameButton.setText("New game");
newGameButton.addMouseListener(new
java.awt.event.MouseAdapter() {
public void
mouseClicked(java.awt.event.MouseEvent evt) {
newGameButtonMouseClicked(evt);
}
});
saveGameButton.setText("Save game");
saveGameButton.addMouseListener(new
java.awt.event.MouseAdapter() {
public void
mouseClicked(java.awt.event.MouseEvent evt) {
saveGameButtonMouseClicked(evt);
}
});
loadGameButton.setText("Load game");
loadGameButton.addMouseListener(new
java.awt.event.MouseAdapter() {
public void
mouseClicked(java.awt.event.MouseEvent evt) {
loadGameButtonMouseClicked(evt);
}
});
jLabel2.setText("white player");
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(boardCanvas,
javax.swing.GroupLayout.PREFERRED_SIZE, 450,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupL
ayout.Alignment.TRAILING)
.addComponent(previousMoveButton,
javax.swing.GroupLayout.DEFAULT_SIZE, 121,
Short.MAX_VALUE)
.addComponent(jLabel1,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.PREFERRED_SIZE, 103,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(nextMoveButton,
javax.swing.GroupLayout.DEFAULT_SIZE, 121,
Short.MAX_VALUE)
.addComponent(whitePlayerComboBox,
javax.swing.GroupLayout.Alignment.LEADING, 0, 121,
Short.MAX_VALUE)
.addComponent(startGameButton,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, 121,
Short.MAX_VALUE)
.addComponent(blackPlayerComboBox, 0, 121,
Short.MAX_VALUE)
.addComponent(newGameButton,
javax.swing.GroupLayout.DEFAULT_SIZE, 121,
Short.MAX_VALUE)
.addComponent(saveGameButton,
javax.swing.GroupLayout.DEFAULT_SIZE, 121,
Short.MAX_VALUE)
.addComponent(loadGameButton,
javax.swing.GroupLayout.DEFAULT_SIZE, 121,
Short.MAX_VALUE)
.addComponent(jLabel2,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.PREFERRED_SIZE, 95,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(boardCanvas,
javax.swing.GroupLayout.PREFERRED_SIZE, 450,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGap(30, 30, 30)
.addComponent(newGameButton)
.addGap(8, 8, 8)
.addComponent(saveGameButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPla
cement.UNRELATED)
.addComponent(loadGameButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPla
cement.RELATED, 46, Short.MAX_VALUE)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPla
cement.RELATED)
.addComponent(blackPlayerComboBox,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(8, 8, 8)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPla
cement.RELATED)
.addComponent(whitePlayerComboBox,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(startGameButton)
.addGap(44, 44, 44)
.addComponent(previousMoveButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPla
cement.RELATED)
.addComponent(nextMoveButton)
.addGap(40, 40, 40))
);
}// </editor-fold>//GEN-END:initComponents
private void
newGameButtonMouseClicked(java.awt.event.MouseEve
nt evt) {//GENFIRST:event_newGameButtonMouseClicked
// TODO add your handling code here:
if(! newGameButton.isEnabled()){
return;
}
gic.newGameButtonClicked();
}//GEN-LAST:event_newGameButtonMouseClicked
private void
saveGameButtonMouseClicked(java.awt.event.MouseEve
nt evt) {//GENFIRST:event_saveGameButtonMouseClicked
// TODO add your handling code here:
if(! saveGameButton.isEnabled()){
return;
}
String f=getFileOnDisk(false);
if(f != null){
gic.saveFile(f);
}
}//GEN-LAST:event_saveGameButtonMouseClicked
private void
loadGameButtonMouseClicked(java.awt.event.MouseEve
nt evt) {//GENFIRST:event_loadGameButtonMouseClicked
// TODO add your handling code here:
if(! loadGameButton.isEnabled()){
return;
}
String f=getFileOnDisk(true);
if(f != null){
gic.loadFile(f);
}
}//GEN-LAST:event_loadGameButtonMouseClicked
private void
startGameButtonMouseClicked(java.awt.event.MouseEve
nt evt) {//GENFIRST:event_startGameButtonMouseClicked
// TODO add your handling code here:
if(! startGameButton.isEnabled()){
return;
}
boolean blackHuman , whiteHuman;
if(blackPlayerComboBox.getSelectedIndex() == 0){
blackHuman=true;
}
else{
blackHuman=false;
}
if(whitePlayerComboBox.getSelectedIndex() == 0){
whiteHuman=true;
}
else{
whiteHuman=false;
}
gic.startGame(blackHuman , whiteHuman);
}//GEN-LAST:event_startGameButtonMouseClicked
private void
previousMoveButtonMouseClicked(java.awt.event.Mouse
Event evt) {//GENFIRST:event_previousMoveButtonMouseClicked
// TODO add your handling code here:
if(! previousMoveButton.isEnabled()){
return;
}
gic.getPreviousMove();
}//GEN-LAST:event_previousMoveButtonMouseClicked
private void
nextMoveButtonMouseClicked(java.awt.event.MouseEve
nt evt) {//GENFIRST:event_nextMoveButtonMouseClicked
// TODO add your handling code here:
if(! nextMoveButton.isEnabled()){
return;
}
gic.getNextMove();
}//GEN-LAST:event_nextMoveButtonMouseClicked
private void
boardCanvasMouseMoved(java.awt.event.MouseEvent
evt) {//GEN-FIRST:event_boardCanvasMouseMoved
// TODO add your handling code here:
int xPress , yPress;
int canvasWidth , canvasHeight;
int cellWidth , cellHeight;
int row , column;
xPress=evt.getX();
yPress=evt.getY();
canvasWidth=boardCanvas.getWidth();
canvasHeight=boardCanvas.getHeight();
cellWidth=(int)((float)canvasWidth /
(float)MAXROW);
cellHeight=(int)((float)canvasHeight /
(float)MAXCOLUMN);
row=(int) ((float)yPress / (float) cellHeight);
column=(int)((float)xPress / (float)cellWidth);
gic.mouseMoved(row, column);
}//GEN-LAST:event_boardCanvasMouseMoved
private void
boardCanvasMouseClicked(java.awt.event.MouseEvent
evt) {//GEN-FIRST:event_boardCanvasMouseClicked
// TODO add your handling code here:
int xPress , yPress;
int canvasWidth , canvasHeight;
int cellWidth , cellHeight;
int row , column;
xPress=evt.getX();
yPress=evt.getY();
canvasWidth=boardCanvas.getWidth();
canvasHeight=boardCanvas.getHeight();
cellWidth=(int)((float)canvasWidth /
(float)MAXROW);
cellHeight=(int)((float)canvasHeight /
(float)MAXCOLUMN);
row=(int) ((float)yPress / (float) cellHeight);
column=(int)((float)xPress / (float)cellWidth);
gic.mouseClicked(row, column);
}//GEN-LAST:event_boardCanvasMouseClicked
private void
boardCanvasMouseExited(java.awt.event.MouseEvent
evt) {//GEN-FIRST:event_boardCanvasMouseExited
// TODO add your handling code here:
gic.mouseMoved(-1 , -1);
}//GEN-LAST:event_boardCanvasMouseExited