|
|
|
|
![]() ![]() |
Nov 4 2005, 11:49 AM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 407 Joined: 13-December 04 Member No.: 2,696 |
I have an assignment that is due tomorrow that I am struggling with. I want to be able to click the next button in this applet, and then repaint all the graphics. Board contains an array with all of the chess pieces on a board, and when the button is clicked I want to be able to get the next move, but for now I just wanted to call a function to move one piece just so I know it's working. Here is my applet code, I could post all the other files, but I am almost positive they all work correctly, and I am just having trouble with the applet.
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); } } Thanks,kvarnerexpress |
|
|
|
Nov 25 2005, 01:27 PM
Post
#2
|
|
|
Member [Level 1] ![]() ![]() ![]() ![]() Group: Members Posts: 58 Joined: 22-October 05 Member No.: 13,216 |
I suppose your assignment is passed by now, and I hope you found an answer to your question. I would be interested in the chess game if you could send me the projects files. I'm just starting to learn java myself,and this probally has not a thing to do with your question, but I was noticing that the applet source code only contains one import statment that doesnt seem right.
|
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 12th October 2008 - 11:36 AM |