Code:
CODE
import java.awt.*;
public class Test extends java.applet.Applet
{
Button nextButton;
Image board, bp, wp, bn, wn, br, wr, bb, wb, bk, wk, bq, wq;
Board currentBoard = new Board();
public void init() {
board = getImage(getCodeBase(), "../images/board.jpg");
bp = getImage(getCodeBase(), "../images/bp.gif");
wp = getImage(getCodeBase(), "../images/wp.gif");
bn = getImage(getCodeBase(), "../images/bn.gif");
wn = getImage(getCodeBase(), "../images/wn.gif");
br = getImage(getCodeBase(), "../images/br.gif");
wr = getImage(getCodeBase(), "../images/wr.gif");
bb = getImage(getCodeBase(), "../images/bb.gif");
wb = getImage(getCodeBase(), "../images/wb.gif");
bk = getImage(getCodeBase(), "../images/bk.gif");
wk = getImage(getCodeBase(), "../images/wk.gif");
bq = getImage(getCodeBase(), "../images/bq.gif");
wq = getImage(getCodeBase(), "../images/wq.gif");
nextButton = new Button("Next");
add(nextButton);
}
public boolean action(Event evt, Object arg) {
if (evt.target instanceof Button) {
getMove((Button) evt.target);
return true;
} else {
return false;
}
}
void getMove(Button b) {
changeBoard();
repaint();
}
public void paint(Graphics screen) {
// Draw Board
screen.drawImage(board, 0, 50, 900, 930, this);
String hi = "hi";
for(int y = 1; y < 9; y++)
{
char tempX = 'a';
for(int x = 1; x < 9; x++)
{
if(currentBoard.colorOn(tempX, y) != 'n')
{
if(currentBoard.colorOn(tempX, y) == 'b')
{
if (currentBoard.typeOn(tempX, y) == "Pawn")
{
screen.drawImage(bp, convertX(tempX), convertY(y), 100, 100, this);
}
if (currentBoard.typeOn(tempX, y) == "Rook")
{
screen.drawImage(br, convertX(tempX), convertY(y), 100, 100, this);
}
if (currentBoard.typeOn(tempX, y) == "Knight")
{
screen.drawImage(bn, convertX(tempX), convertY(y), 100, 100, this);
}
if (currentBoard.typeOn(tempX, y) == "Bishop")
{
screen.drawImage(bb, convertX(tempX), convertY(y), 100, 100, this);
}
if (currentBoard.typeOn(tempX, y) == "King")
{
screen.drawImage(bk, convertX(tempX), convertY(y), 100, 100, this);
}
if (currentBoard.typeOn(tempX, y) == "Queen")
{
screen.drawImage(bq, convertX(tempX), convertY(y), 100, 100, this);
}
}
if(currentBoard.colorOn(tempX, y) == 'w')
{
if (currentBoard.typeOn(tempX, y) == "Pawn")
{
screen.drawImage(wp, convertX(tempX), convertY(y), 100, 100, this);
}
if (currentBoard.typeOn(tempX, y) == "Rook")
{
screen.drawImage(wr, convertX(tempX), convertY(y), 100, 100, this);
}
if (currentBoard.typeOn(tempX, y) == "Knight")
{
screen.drawImage(wn, convertX(tempX), convertY(y), 100, 100, this);
}
if (currentBoard.typeOn(tempX, y) == "Bishop")
{
screen.drawImage(wb, convertX(tempX), convertY(y), 100, 100, this);
}
if (currentBoard.typeOn(tempX, y) == "King")
{
screen.drawImage(wk, convertX(tempX), convertY(y), 100, 100, this);
}
if (currentBoard.typeOn(tempX, y) == "Queen")
{
screen.drawImage(wq, convertX(tempX), convertY(y), 100, 100, this);
}
}
}
tempX++;
}
}
}
public int convertX(char a) {
return ((a-97)*(100)) + 90;
}
public int convertY(int a) {
return ((a-1)*(100)) + 90;
}
public void changeBoard(){
currentBoard.move('b',2,'b',3);
currentBoard.move('b',7,'b',5);
}
}
public class Test extends java.applet.Applet
{
Button nextButton;
Image board, bp, wp, bn, wn, br, wr, bb, wb, bk, wk, bq, wq;
Board currentBoard = new Board();
public void init() {
board = getImage(getCodeBase(), "../images/board.jpg");
bp = getImage(getCodeBase(), "../images/bp.gif");
wp = getImage(getCodeBase(), "../images/wp.gif");
bn = getImage(getCodeBase(), "../images/bn.gif");
wn = getImage(getCodeBase(), "../images/wn.gif");
br = getImage(getCodeBase(), "../images/br.gif");
wr = getImage(getCodeBase(), "../images/wr.gif");
bb = getImage(getCodeBase(), "../images/bb.gif");
wb = getImage(getCodeBase(), "../images/wb.gif");
bk = getImage(getCodeBase(), "../images/bk.gif");
wk = getImage(getCodeBase(), "../images/wk.gif");
bq = getImage(getCodeBase(), "../images/bq.gif");
wq = getImage(getCodeBase(), "../images/wq.gif");
nextButton = new Button("Next");
add(nextButton);
}
public boolean action(Event evt, Object arg) {
if (evt.target instanceof Button) {
getMove((Button) evt.target);
return true;
} else {
return false;
}
}
void getMove(Button b) {
changeBoard();
repaint();
}
public void paint(Graphics screen) {
// Draw Board
screen.drawImage(board, 0, 50, 900, 930, this);
String hi = "hi";
for(int y = 1; y < 9; y++)
{
char tempX = 'a';
for(int x = 1; x < 9; x++)
{
if(currentBoard.colorOn(tempX, y) != 'n')
{
if(currentBoard.colorOn(tempX, y) == 'b')
{
if (currentBoard.typeOn(tempX, y) == "Pawn")
{
screen.drawImage(bp, convertX(tempX), convertY(y), 100, 100, this);
}
if (currentBoard.typeOn(tempX, y) == "Rook")
{
screen.drawImage(br, convertX(tempX), convertY(y), 100, 100, this);
}
if (currentBoard.typeOn(tempX, y) == "Knight")
{
screen.drawImage(bn, convertX(tempX), convertY(y), 100, 100, this);
}
if (currentBoard.typeOn(tempX, y) == "Bishop")
{
screen.drawImage(bb, convertX(tempX), convertY(y), 100, 100, this);
}
if (currentBoard.typeOn(tempX, y) == "King")
{
screen.drawImage(bk, convertX(tempX), convertY(y), 100, 100, this);
}
if (currentBoard.typeOn(tempX, y) == "Queen")
{
screen.drawImage(bq, convertX(tempX), convertY(y), 100, 100, this);
}
}
if(currentBoard.colorOn(tempX, y) == 'w')
{
if (currentBoard.typeOn(tempX, y) == "Pawn")
{
screen.drawImage(wp, convertX(tempX), convertY(y), 100, 100, this);
}
if (currentBoard.typeOn(tempX, y) == "Rook")
{
screen.drawImage(wr, convertX(tempX), convertY(y), 100, 100, this);
}
if (currentBoard.typeOn(tempX, y) == "Knight")
{
screen.drawImage(wn, convertX(tempX), convertY(y), 100, 100, this);
}
if (currentBoard.typeOn(tempX, y) == "Bishop")
{
screen.drawImage(wb, convertX(tempX), convertY(y), 100, 100, this);
}
if (currentBoard.typeOn(tempX, y) == "King")
{
screen.drawImage(wk, convertX(tempX), convertY(y), 100, 100, this);
}
if (currentBoard.typeOn(tempX, y) == "Queen")
{
screen.drawImage(wq, convertX(tempX), convertY(y), 100, 100, this);
}
}
}
tempX++;
}
}
}
public int convertX(char a) {
return ((a-97)*(100)) + 90;
}
public int convertY(int a) {
return ((a-1)*(100)) + 90;
}
public void changeBoard(){
currentBoard.move('b',2,'b',3);
currentBoard.move('b',7,'b',5);
}
}
Thanks,kvarnerexpress

