Beruflich Dokumente
Kultur Dokumente
Araatuba, SP 2015
LISTA DE FIGURAS
SUMRIO
CAPTULO 1 - INTRODUO.................................................................................... 5
1.1 Objetivos ............................................................................................................... 5
1.2 Introduo ............................................................................................................. 5
CAPTULO 6 - PROGRAMA..................................................................................... 70
1.1 Objetivos
1.2 Introduo
2.1 Peas
2.2 Captura
Roque
En passant ou Ao passar
uma forma especial de captura que o peo faz quando esse est na 5
fila (em relao ao jogador) e um peo adversrio avana duas casas
passando do seu lado.
Na posio do desenho o peo branco est na 5 fila e o peo preto avana
duas casas passando ao seu lado.
Para capturar o peo preto, o peo branco deve ocupar a casa por onde
passou o peo preto.
2.5 Xeque
Quando o Rei est a ser atacado por uma pea inimiga diz-se que este
est em xeque.
No final da jogada o Rei no pode ficar em cheque, se o jogador se
enganar e deixar o Rei nessa situao este ter de refazer o lance, neste caso
a regra piece tuche piece joue se possvel tem de ser respeitada.
Caso no seja possvel deixar o Rei sem estar em xeque a posio
passa a ser de mate e o jogo termina com derrota para o lado que se move.
2-11 Posio em que o Rei est a ser
atacado por uma pea.
2.6 Mate
O jogador que est em xeque no pode evitar que o seu Rei deixe de est-lo
no final do seu lance. Esta situao designada mate e implica a derrota para
o lado do Rei que est em xeque vitria para o outro.
2.7 Empate
Quando o lado a mover no tem nenhuma jogada legal que possa realizar e
no est em xeque o jogo termina com empate.
3.1 Escopo
Estrutura Organizacional
Funes e Responsabilidades
Recursos Utilizados
Anlise de Riscos
4.1 Criao
Para a criao do jogo sero necessrias diversas classes, cada uma com a
sua respectiva funo.
4.2 Classes
GameMain
ChessBoard
ChessPiece
Essa classe funciona como uma genrica de pea onde ficam definido os
atributos e mtodos compartilhados por todas as peas. As classes Pawn, Queen,
Rook, Bishop, King e Knight, so classes que herdam os atributos e mtodos da
classe ChessPiece, cada classe faz a sobrescrita dos mtodos da classe
ChessPiece dependendo da necessidade de cada pea.
4-5 Classe responsvel pelos atributos e mtodos de cada pea.
GameConnection
GameMain.java
package aegis;
import java.awt.Dimension;
/**
*
* @author JV Master
*/
public class GameMain extends javax.swing.JFrame {
/**
* Creates new form GameMain
*/
public GameMain() {
initComponents();
this.setResizable(false);
this.pack();
this.setPreferredSize(new Dimension(400, 400));
}
/**
* This method is called from within the constructor to initialize the
form. WARNING: Do NOT modify this code. The content of this method is always
regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Chess Game");
setResizable(false);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
chessBoard1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
chessBoard1Layout.setVerticalGroup(
chessBoard1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(chessBoard1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(chessBoard1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting
code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the
default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(GameMain.class.getName()).log(java.util.logging.Lev
el.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(GameMain.class.getName()).log(java.util.logging.Lev
el.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(GameMain.class.getName()).log(java.util.logging.Lev
el.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(GameMain.class.getName()).log(java.util.logging.Lev
el.SEVERE, null, ex);
}
//</editor-fold>
GameStart.java
package aegis;
/**
*
* @author JV Master
*/
public class GameStart extends javax.swing.JFrame {
/**
* Creates new form GameStart
*/
public GameStart() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the
form. WARNING: Do NOT modify this code. The content of this method is always
regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Chess Game");
setResizable(false);
jRadioButton1.setSelected(true);
jRadioButton1.setText("Network");
jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton1ActionPerformed(evt);
}
});
jRadioButton2.setText("Janela nica");
jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton2ActionPerformed(evt);
}
});
jButton1.setText("Iniciar Jogo");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel1.setLabelFor(jTextField1);
jLabel1.setText("Host:");
jTextField1.setText("localhost");
jLabel2.setLabelFor(jTextField2);
jLabel2.setText("Usurio:");
jTextField2.setText("root");
jLabel3.setLabelFor(jTextField3);
jLabel3.setText("Senha:");
jCheckBox1.setSelected(true);
jCheckBox1.setText("Sempre Alinhar Abaixo");
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSeparator1)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(35, 35, 35)
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(jLabel3))
.addComponent(jLabel2,
javax.swing.GroupLayout.Alignment.TRAILING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField3)
.addComponent(jTextField1)
.addComponent(jTextField2)))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioButton1)
.addComponent(jRadioButton2))
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(0, 173, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jButton1,
javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jCheckBox1))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jRadioButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextField1,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jTextField2,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jTextField3,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11,
Short.MAX_VALUE)
.addComponent(jCheckBox1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jSeparator1,
javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jRadioButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)
.addContainerGap())
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>
private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jRadioButton2.setSelected(false);
changeNetworkChecked(true);
}
if (jRadioButton1.isSelected()) {
GameConnection conn = new GameConnection();
conn.start(jTextField1.getText(), jTextField2.getText(),
jTextField3.getText());
frame.getBoard().setConnection(conn);
}
if (jCheckBox1.isSelected())
frame.getBoard().setInvertSecondPlayer(true);
frame.setVisible(true);
this.setVisible(false);
this.dispose();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting
code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the
default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(GameStart.class.getName()).log(java.util.logging.Le
vel.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(GameStart.class.getName()).log(java.util.logging.Le
vel.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(GameStart.class.getName()).log(java.util.logging.Le
vel.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(GameStart.class.getName()).log(java.util.logging.Le
vel.SEVERE, null, ex);
}
//</editor-fold>
ChessBoard.java
package aegis;
import aegis.pieces.*;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import javax.swing.JPanel;
import javax.swing.Timer;
/**
* Chess Board
* @author JV Master
*/
public class ChessBoard extends JPanel implements MouseListener {
// -----------------
protected boolean networking = false;
protected GameConnection conn = null;
protected int status = 0; // 0: waiting second player
protected Timer timer;
public ChessBoard() {
// Inicia o listener do mouse
this.addMouseListener(this);
// Inicia o jogo
this.start();
}
// Inicia o jogo
public void start() {
// Inicia os jogadores
this.setPlayers(new ChessPlayer[2]);
players[0] = new ChessPlayer(1);
players[1] = new ChessPlayer(0);
this.setCurrent(0);
this.setPieceIndex(-1);
}
// ---------------------------------------------------------------
// DRAWING
// ---------------------------------------------------------------
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// Desenha o tabuleiro
for (int x = 0; x < 8; x++)
for (int y = 0; y < 8; y++) {
g2d.setColor(((x + y) % 2 == 0) ? Color.LIGHT_GRAY :
Color.GRAY);
g2d.fillRect(x * 50, y * 50, 50, 50);
}
// Desenha as marcaes
if (this.getPieceIndex() != -1) {
ChessPiece piece = this.getPlayerPiece(this.getPieceIndex());
// alpha
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
g2d.setColor(Color.MAGENTA);
g2d.fillRect(xy(piece.getX()) * 50, xy(piece.getY()) * 50, 50, 50);
g2d.setColor(Color.CYAN);
for (Point move : this.getPieceMoves())
g2d.fillRect(xy((int)move.getX()) * 50, xy((int)move.getY()) *
50, 50, 50);
g2d.setColor(Color.RED);
for (Point eat : this.getPieceEats())
g2d.fillRect(xy((int)eat.getX()) * 50, xy((int)eat.getY()) *
50, 50, 50);
// reset alpha
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f));
}
// Desenha as peas
for (int i = 0; i < 2; i++)
this.getPlayer(i).draw(g, (xy(0) == 7));
if (this.current != this.getConnection().getPlayerIndex())
drawMessage(g2d, "VEZ DO OPONENTE");
}
}
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
0.8f));
g2d.setColor(Color.BLACK);
g2d.fillRect(0, 0, 400, 400);
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
1f));
g2d.setColor(Color.WHITE);
g2d.drawString(text, (this.getWidth() - fm.stringWidth(text)) / 2,
this.getHeight() / 2);
}
// ---------------------------------------------------------------
// INPUT
// ---------------------------------------------------------------
@Override
public void mouseClicked(MouseEvent e) {
// Calcula a clula do tabuleiro relativa a posio do mouse
int x = xy(e.getX() / 50);
int y = xy(e.getY() / 50);
if (this.getPieceIndex() == -1 || (this.getPieceMoves().isEmpty()
&& this.getPieceEats().isEmpty())) {
// -- Faz a seleo da pea que ser movida
this.setPieceIndex(this.indexOfPiece(this.getPlayerPieces(), x,
y));
if (this.getPieceIndex() != -1) {
// Calcula a lista de movimentos possveis da pea
selecionada
this.setPieceMoves(this.getCurrentPiece().getMoves(this));
this.setPieceEats(this.getCurrentPiece().getEats(this));
// Atualiza o desenho
this.repaint();
}
} else {
// -- Move a pea selecionada
// Atualiza o desenho
this.repaint();
// Executa a ao da pea
Point p = this.getPieceEats().get(eat);
eat(this.getCurrentPiece(), (int)p.getX(), (int)p.getY());
// Atualiza o desenho
this.repaint();
}
}
}
}
// Move a pea e remove a pea inimiga "comida", enviando uma mensagem caso
esteja utilizando networking
protected void eat(ChessPiece piece, int x, int y) {
eat(piece, x, y, "eat");
}
// Desabilita o inimigo
enemy.setEnabled(false);
// Move a pea
piece.setX(x);
piece.setY(y);
// Verifica a promoo
checkPromotion(piece);
// Networking
if (isNetworking() && !action.equals("")) {
this.getConnection().send(action, "" + oX + oY + piece.getX() +
piece.getY());
}
}
// ---------------------------------------------------------------
@Override
public void mousePressed(MouseEvent e) { }
@Override
public void mouseReleased(MouseEvent e) { }
@Override
public void mouseEntered(MouseEvent e) { }
@Override
public void mouseExited(MouseEvent e) { }
// ---------------------------------------------------------------
// CUSTOM GETTERS & SETTERS
// ---------------------------------------------------------------
return -1;
}
return -1;
}
// ---------------------------------------------------------------
// GETTERS & SETTERS
// ---------------------------------------------------------------
// ---------------------------------------------------------------
// NETWORKING
// ---------------------------------------------------------------
this.setNetworking(true);
this.getConnection().getPlayerIndex();
this.getConnection().send("start", "" +
this.getConnection().getPlayerIndex());
this.getConnection().setLastIndex(Integer.parseInt(this.getConnection().receive()[0]))
;
this.getTimer().start();
if (this.getConnection().getPlayerIndex() == 1)
this.setStatus(1);
}
// Para o networking
public void stopConnection() {
if (isNetworking()) {
this.getTimer().stop();
this.getConnection().send("stop", "" +
this.getConnection().getPlayerIndex());
this.getConnection().stop();
this.setNetworking(false);
}
}
ChessPiece piece;
switch(data[1]) {
case "start":
// Caso seja o jogador 1 e receba a mensagem que um jogador
entrou
if (this.getConnection().getPlayerIndex() == 0) {
this.setStatus(1);
// Atualiza o desenho
this.repaint();
}
break;
case "move":
// Seleciona a pea movida
piece =
this.getPlayerPiece(this.indexOfPiece(this.getPlayerPieces(), getIntAt(data[2], 0),
getIntAt(data[2], 1)));
// Executa a ao da pea
move(piece, getIntAt(data[2], 2), getIntAt(data[2], 3),
"");
// Atualiza o desenho
this.repaint();
break;
case "eat":
// Seleciona a pea movida
piece =
this.getPlayerPiece(this.indexOfPiece(this.getPlayerPieces(), getIntAt(data[2], 0),
getIntAt(data[2], 1)));
// Executa a ao da pea
eat(piece, getIntAt(data[2], 2), getIntAt(data[2], 3), "");
// Atualiza o desenho
this.repaint();
break;
case "stop":
// Fecha o jogo caso o outro cliente tenha sido finalizado
stopConnection();
System.exit(0);
break;
default:
break;
}
}
}
return value;
}
ChessPiece.java
package aegis;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.util.ArrayList;
import javax.swing.ImageIcon;
/**
* Chess Piece
* @author JV Master
*/
public class ChessPiece {
protected int x;
protected int y;
protected int side;
public ChessPiece() {
this(0, 0, 0);
}
// -------------------------------------------------
// move mapping
// 0: continue search
// 1: stop search
public int addCellEmpty(ArrayList<Point> list, ChessBoard board, int x, int y)
{
x += this.getX(); y+= this.getY();
if (this.isCell(x, y) &&
board.indexOfPiece(board.getPlayerPieces(), x, y) == -1 &&
board.indexOfPiece(board.getEnemyPieces(), x, y) == -1) {
list.add(new Point(x, y));
return 0;
}
return 1;
}
return 1;
}
// -------------------------------------------------
ChessPlayer.java
package aegis;
import aegis.pieces.*;
import java.awt.Graphics;
import java.util.ArrayList;
/**
* Chess Player
* @author JV Master
*/
public class ChessPlayer {
this.start();
}
public void start() {
int offset = side * 7;
GameConnection.java
package aegis;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Game Connection
* @author JV Master
*/
public class GameConnection {
try {
Class.forName("com.mysql.jdbc.Driver");
createGameTable();
ResultSet rs = conn.getMetaData().getCatalogs();
boolean found = false;
while (rs.next()) {
String databaseName = rs.getString(1);
if(databaseName.equals(dbName))
found = true;
}
rs.close();
// -----------
if (!found) {
Statement st = conn.createStatement();
st.executeUpdate("CREATE DATABASE " + dbName);
st.close();
}
conn.close();
}
if (rs.next()) {
if (rs.getString("players").equals("2") ||
rs.getInt("stopped") > 0) {
this.gameIndex = rs.getInt("gid") + 1;
this.playerIndex = 0;
} else {
this.gameIndex = rs.getInt("gid");
this.playerIndex = 1;
}
} else {
this.gameIndex = 0;
this.playerIndex = 0;
}
st.close();
} catch (SQLException ex) {
Logger.getLogger(GameConnection.class.getName()).log(Level.SEVERE, null, ex);
}
return this.playerIndex;
} else {
return this.playerIndex;
}
}
return null;
}
ResultSet rs = st.getGeneratedKeys();
if (rs.next())
this.setLastIndex(rs.getInt(1));
st.close();
} catch (SQLException ex) {
Logger.getLogger(GameConnection.class.getName()).log(Level.SEVERE,
null, ex);
}
}
Bishop.java
package aegis.pieces;
import aegis.ChessBoard;
import aegis.ChessPiece;
import java.awt.Point;
import java.util.ArrayList;
/**
* Chess Bishop
* @author JV Master
*/
public class Bishop extends ChessPiece {
public Bishop() {
super();
}
this.setImage(this.loadPieceImage("bishop"));
}
@Override
public ArrayList<Point> getMoves(ChessBoard board) {
ArrayList<Point> list = new ArrayList<>();
return list;
}
@Override
public ArrayList<Point> getEats(ChessBoard board) {
ArrayList<Point> list = new ArrayList<>();
return list;
}
}
King.java
package aegis.pieces;
import aegis.ChessBoard;
import aegis.ChessPiece;
import java.awt.Point;
import java.util.ArrayList;
/**
* Chess King
* @author JV Master
*/
public class King extends ChessPiece {
public King() {
super();
}
this.setImage(this.loadPieceImage("king"));
}
@Override
public ArrayList<Point> getMoves(ChessBoard board) {
ArrayList<Point> list = new ArrayList<>();
return list;
}
@Override
public ArrayList<Point> getEats(ChessBoard board) {
ArrayList<Point> list = new ArrayList<>();
this.addCellEnemy(list, board, 1, 0);
this.addCellEnemy(list, board, -1, 0);
this.addCellEnemy(list, board, 0, 1);
this.addCellEnemy(list, board, 0, -1);
this.addCellEnemy(list, board, 1, 1);
this.addCellEnemy(list, board, -1, -1);
this.addCellEnemy(list, board, 1, -1);
this.addCellEnemy(list, board, -1, 1);
return list;
}
}
Knight.java
package aegis.pieces;
import aegis.ChessBoard;
import aegis.ChessPiece;
import java.awt.Point;
import java.util.ArrayList;
/**
* Chess Knight
* @author JV Master
*/
public class Knight extends ChessPiece {
public Knight() {
super();
}
this.setImage(this.loadPieceImage("knight"));
}
@Override
public ArrayList<Point> getMoves(ChessBoard board) {
ArrayList<Point> list = new ArrayList<>();
return list;
}
@Override
public ArrayList<Point> getEats(ChessBoard board) {
ArrayList<Point> list = new ArrayList<>();
return list;
}
}
Pawn.java
package aegis.pieces;
import aegis.ChessBoard;
import aegis.ChessPiece;
import java.awt.Point;
import java.util.ArrayList;
/**
* Chess Pawn
* @author JV Master
*/
public class Pawn extends ChessPiece {
public Pawn() {
super();
}
this.setImage(this.loadPieceImage("pawn"));
}
@Override
public ArrayList<Point> getMoves(ChessBoard board) {
ArrayList<Point> list = new ArrayList<>();
if (this.getSide() == 0) {
this.addCellEmpty(list, board, 0, 1);
if (this.getY() == 1) this.addCellEmpty(list, board, 0, 2);
} else {
this.addCellEmpty(list, board, 0, -1);
if (this.getY() == 6) this.addCellEmpty(list, board, 0, -2);
}
return list;
}
@Override
public ArrayList<Point> getEats(ChessBoard board) {
ArrayList<Point> list = new ArrayList<>();
if (this.getSide() == 0) {
this.addCellEnemy(list, board, -1, 1);
this.addCellEnemy(list, board, 1, 1);
} else {
this.addCellEnemy(list, board, -1, -1);
this.addCellEnemy(list, board, 1, -1);
}
return list;
}
}
Queen.java
package aegis.pieces;
import aegis.ChessBoard;
import aegis.ChessPiece;
import java.awt.Point;
import java.util.ArrayList;
/**
* Chess Queen
* @author JV Master
*/
public class Queen extends ChessPiece {
public Queen() {
super();
}
this.setImage(this.loadPieceImage("queen"));
}
@Override
public ArrayList<Point> getMoves(ChessBoard board) {
ArrayList<Point> list = new ArrayList<>();
return list;
}
@Override
public ArrayList<Point> getEats(ChessBoard board) {
ArrayList<Point> list = new ArrayList<>();
return list;
}
}
Rook.java
package aegis.pieces;
import aegis.ChessBoard;
import aegis.ChessPiece;
import java.awt.Point;
import java.util.ArrayList;
/**
* Chess Rook
* @author JV Master
*/
public class Rook extends ChessPiece {
public Rook() {
super();
}
public Rook(int x, int y, int side) {
super(x, y, side);
this.setImage(this.loadPieceImage("rook"));
}
@Override
public ArrayList<Point> getMoves(ChessBoard board) {
ArrayList<Point> list = new ArrayList<>();
return list;
}
@Override
public ArrayList<Point> getEats(ChessBoard board) {
ArrayList<Point> list = new ArrayList<>();
return list;
}
}
Captulo 6
CAPTULO 6 - PROGRAMA
Menu
Ao escolher a opo Janela nica e depois clicar em Iniciar Jogo, ser gerado
uma janela com o tabuleiro.
6-2 Tabuleiro
Multiplayer
Depois da insero dos dados e clicar em Iniciar Jogo aparecer uma janela
com o tabuleiro para o jogador que inciou o jogo.
Peo
Rei
6-7 Rei
Torre
A torre se movimenta para frente e para trs, para a direita e para a esquerda,
quantas casas quiser, mas no pode pular nenhuma outra pea.
6-8 Torre
Cavalo
O cavalo a nica pea do xadrez que pode pular outras peas. Ele tem um
movimento especial que parece a letra L, movendo-se 2 casas para frente ou para trs
e em seguida 1 casa para a direita ou para a esquerda ou vice-versa.
6-9 Cavalo
Bispo
6-10 Bispo
Rainha
a pea mais poderosa do xadrez, ela pode ir para frente ou para trs, para
direita ou para a esquerda, ou na diagonal, quantas casas quiser, mas no pode pular
nenhuma outra pea.
6-11 Rainha
Promoo do Peo
Xeque Mate
Quando o Rei est a ser atacado por uma pea inimiga diz-se que este est
em xeque. Esta situao implica a derrota para o lado do Rei que est em xeque
vitria para o outro.
Na figura abaixo, podemos ver que ocorrer um xeque-mate, assim que o
fizer, o jogo termina e reinicializado.
6-13 Xeque-Mate
CAPTULO 7 - BIBLIOGRAFIA
SIERRA, Kathy; BATES, Bert Use a Cabea Java Editora Alta Books, Rio
de Janeiro, 2010.