• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating a Browser JavaScript Chess Game  RSS feed

 
Shion Tygon
Greenhorn
Posts: 3
Firefox Browser Java Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I am trying to do is create a simple browser-based chess game (no persistent save or LAN based functionality. Just being able to move pieces on a screen according to how the pieces are suppose to move (pawn forward and capturing diagonally for example). Currently, I can display the board and have the browser recognizing when I click somewhere on the board, but I am stuck at trying to get pieces to update their position.

Here is my test.js code:







What I am doing here is creating the pieces and testing if the piece (when clicked) is able to move to a position, highlight the possible positions, and allow to move there, but the problem is, this never happens. The highlighting is not shown and I get an error that B.get is undefined.



My get function is defined in my Board.js code:







I am defining my pieces here:



I know that is probably a lot and I am really not sure if it is understandable, but what I am trying to do again is play a very basic game of chess in a browser (I can include the html, but it is very basic). There is no saving or anything like that. It just starts with white going first followed by black, etc. where players should be able to take pieces of the other side, but not their own. I do not want to check for checkmate yet. Just dealing with piece taking and movements. Any thoughts on this as it is really baffling me.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66261
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

But yes, that's way too much code to wade through. I'd suggest setting breakpoints in the browser and checking where things aren't doing what you expect. Then you can ask more targeted questions on smaller code fragments.
 
Shion Tygon
Greenhorn
Posts: 3
Firefox Browser Java Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Welcome to the Ranch.

But yes, that's way too much code to wade through. I'd suggest setting breakpoints in the browser and checking where things aren't doing what you expect. Then you can ask more targeted questions on smaller code fragments.


Well, when I set a breakpoint, I seem to get an error that B.get is not a function. I am guessing this means that my get function is not properly detecting mouse clicks?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66261
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where? Again, too much code to wade through to try and find where you are talking about.

If you are getting a "get" is not defined errors, it means that you are referring to it out of scope. Certainly nothing's going to run correctly until such errors are gone. (Then you just to find any logic errors.)
 
Shion Tygon
Greenhorn
Posts: 3
Firefox Browser Java Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Additional info based on previous post:
This is the function that throws the error:
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66261
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First thing: X? B? I recommend you use better names and follow conventions (such as lowercase for variable names). Makes your code much easier to read.

If the B.get line (7) is throwing an error, then either B or B.get isn't defined at that point. Back-track why you think it should be and why it isn't.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!