• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

chess game : moving piece

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am try to make a simple 2player chess game...

problem:- when i did wrong move then it comes to its original position but then after i can't move it again...why this is happening??
also suggest some more efficient mechanism ....

]
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I speak for many here by saying that I would much better understand your problem if I could see and play with compilable code. I recommend that you create and post the smallest program possible that is compilable, runnable, demonstrates your problem, and has no extraneous code not related to the problem, an SSCCE. Please see the link for details on how to create one of these because trust me, if your SSCCE is compliant with the specs, you'll likely get a very helpful answer from someone here quickly. For instance you would likely create a very simple board that has one piece on it, that relies on graphics that are available to all from the internet.

Much luck!
 
mundva wala
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is the full code of it....

 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know if there is one or a few best ways to do this, but I would have my jpanel squares grid held in a JLayeredPane as you're doing, but would add the chess piece to the square itself, not the layered pane. If the square uses GridBagLayout and you add the piece to it without constraints, it will be added to the center of the square. Then in the mouse listener, I'd obtain the square at the mouse pressed point, see if a piece was there, place it in the JLayeredPane's DRAG_LAYER, and move it with mouse dragged , and then on mouseRelease see if the mouse Point is over a square, check if it is a valid square and if so, add the piece again to the square. If not, I'd replace it on the original square.
 
mundva wala
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you very much for giving reply
but i can't understand what you want 2 say....

if(valid)
then move
else
return to original position //can you write the code of this mechanism which is suitable for my coding???


if you can write the code for it then it will very helpful to me...

thank you
mudvawala
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can show you my MouseAdapter code. It's not well written in that it is mixing GUI with logic, and its logic is only that of a black pawn but as a first approximation, it works for me:

 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cross posted
http://forums.sun.com/thread.jspa?threadID=5444230
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
mundva, BeForthrightWhenCrossPostingToOtherSites.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic