package checkers;
import jess.*;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.StringTokenizer;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* This class is the entry point of the program (main () method) and stands for the game class. The class constructs the main dialogs and handle the user choice and the displays some feedback information inside a message box.
*/
public class Checker
extends JDialog {
static Rete r = new Rete();
boolean isOver = false;
private FootPanel footPanel;
boolean turn;
static Player player[] = new Player[2];
static private Checker checker = new Checker();
/**
* This method is calling the methods in the other class to initilize the game and it runs the main module of Jess.
*/
public Checker() {
super();
try {
System.
err.
println("Warning: UnsupportedLookAndFeel: " + laf
);
System.
err.
println("Error loading " + laf
+ ": " + exc
);
}
}
});
setResizable(false);
setTitle(title);
titleLabel.
setFont(new Font("MS Sans Serif",
1,
18));
titleLabel.setText(title);
footPanel = new FootPanel();
getContentPane
().
add(Grid.
getInstance(),
BorderLayout.
CENTER);
pack();
try {
r.executeCommand("(batch main.clp)");
} catch (JessException e
) {System.
err.
println(e
);}
}
/**
* This method is used get the instance of the Checker's object.
* @return the information about the checker.
*/
static public Checker getInstance() {
return checker;
}
/**
* This is the Main Method used to start and initilize the game
* It ask for the game options to be played (Human vs Human, Jess vs Jess...
* @param argv not used
*/
static public void main
(String[] argv
) {
{Grid grid;}
Object[] possibleValues
= { "Human vs Human",
"Human vs Jess",
"Jess vs Jess" };
"Choose a mode", "Input",
possibleValues, possibleValues[0]);
if (selectedValue == null)
if (selectedValue.equals("Human vs Human")) {
player[0] = new Human ("Human", Piece.WHITE);
player[1] = new Human("Human", Piece.BLACK);
}
else if (selectedValue.equals("Human vs Jess")) {
player[0] = new Human ("Human", Piece.WHITE);
player[1] = new Jess("Jess", Piece.BLACK);
}
else if (selectedValue.equals("Jess vs Jess")) {
player[0] = new Jess ("Jess", Piece.WHITE);
player[1] = new Jess("Jess", Piece.BLACK);
}
else {alert ("Please, choose a mode");}
player[0].setNext(player[1]);
player[1].setNext(player[0]);
checker.show();
checker.init();
player[0].hasTurn();
}
/**
* This method is to print out the exception if any error should happen in the program.
* Prints out the error.
* @param exception The exception containing the message to be printed
*/
static public void alert
(Exception exception
) {
exception.printStackTrace();
}
/**
* This method is used to print out the information about the error
* Prints out the information about the error.
* @param info Informasion to be printed out
*/
static public void alert
(String info
) {
}
/**
* This Method is used print out a message in the textbox of graphical user interface.
* @param msg message to be append to the textArea
*/
public void displayMessage
(String msg
) {
footPanel.resultTextArea.append(msg + "\n");
}
/**
* This method get information about the board and initilize a new board with this information
*/
public void init() {
Board board = Board.getInstance();
board.init();
}
/**
* This method is invoked when a player win the game.
* @param color The color of the winer
*/
public void win(boolean color) {
if (player[0].color == color)
alert(player[0] + " win the game.");
else
alert(player[1] + " win the game.");
isOver = true;
}
/**
* This method is used to find out if the game is over
* @return true if the game is over;
*/
public boolean isOver() {
return isOver;
}
/**
* This method is used to tell who's turn it is.
* @return true if it is white else false if it is black
*/
public boolean getTurn(){
return turn;
}
/**
* This Class is extendsion of JPanel which is used for the graphial part
* This class setup the graphical user interface.
*/
private class FootPanel
extends JPanel {
/** Creates new form footPanel */
public FootPanel() {
actionLabel.setText("Movement");
add(actionLabel);
resultTextArea.setEditable(false);
jScrollPane1.setViewportView(resultTextArea);
add(jScrollPane1);
playBtn.setText("Play");
if (turn)
player[1].hasTurn();
else
player[0].hasTurn();
}
});
add(playBtn);
movBtn.setText("Move");
SelectDialog selectDialog = new SelectDialog();
selectDialog.show();
}
});
add(movBtn);
}
/**
* Causes this container to lay out its components.
*/
public void doLayout() {
actionLabel.setBounds(30, 10, 80, 20);
jScrollPane1.setBounds(20, 40, 250, 90);
playBtn.setBounds(60, 140, 80, 30);
movBtn.setBounds(150, 140, 80, 30);
}
/**
* @return an instance of Dimension that represents the minimum size of this container.
*/
}
/**
* @return an instance of Dimension that represents the preferred size of this container.
*/
}
}
}