java - How do I implement a JOptionpane List Option? -



java - How do I implement a JOptionpane List Option? -

github link total download

https://github.com/jamiex304/chess-game

i developing chess game , have ran problem

currently when pawn reaches end of other side of board changes white queen default

i want allow user decide changes (hence rules of chess) toying around joption pane having problem getting work can run our errors nil me in terms of chaging pieces looking help implementation,

the queen code snipet (didnt include total code here because long files found on github link if wish run file yourselfs)

if(!validmove){ int location=0; if(starty ==0){ location = startx; } else{ location = (starty*8)+startx; } string piecelocation = piecename+".png"; pieces = new jlabel( new imageicon(piecelocation) ); panels = (jpanel)chessboard.getcomponent(location); panels.add(pieces); } else{ if(success){ int location = 56 + (e.getx()/75); if (c instanceof jlabel){ container parent = c.getparent(); parent.remove(0); pieces = new jlabel( new imageicon("whitequeen.png") ); parent = (jpanel)chessboard.getcomponent(location); parent.add(pieces); } else{ container parent = (container)c; pieces = new jlabel( new imageicon("whitequeen.png") ); parent = (jpanel)chessboard.getcomponent(location); parent.add(pieces); } } else{ if (c instanceof jlabel){ container parent = c.getparent(); parent.remove(0); parent.add( chesspiece ); } else { container parent = (container)c; parent.add( chesspiece ); } chesspiece.setvisible(true); } }

if want see mean means download , run java file can see way changes white queen

i wasn't sure one. "bad question"? don't know.

a general remark: implementation bad in every way. way how messing around gui components , trying implement game logic in single class horrible. there way many individual flaws list them here reasonable effort. there much wrong give reasonable hints improvements. impossible write ai based on code, reply suggests "solve problem" not help in long run.

in general, , particularly aiming @ intention write ai:

you should have class called board represents chess board. , should not gui component, simple class, consisting of 8x8 array fields/pieces, , methods set pieces @ individual fields you should have class called piece, or maybe class called field contains representation of piece. again, should not gui component, simple class, maybe not containing more basic info (piece type, position, color...)

you should have class called move. in fact of import one. if want implement ai, you'll start minimax algorithm, , later extend alpha-beta-pruning. , both algorithms, need very basic set of operations:

you must able create move you must able evaluate board you must able undo move

so move class must contain info necessary , undo move.

(a link chess programming wiki won't help anyhow, wanted mention here)

concerning actual question: minimal modification considered necessary accomplish current goal (with code snippet universe, +1 that). should not seek write ai based on class, because not successful that.

//-------------------------------------changes queen piece , validates move---------------------------------------------- if(!validmove){ int location=0; if(starty ==0){ location = startx; } else{ location = (starty*8)+startx; } string piecelocation = piecename+".png"; pieces = new jlabel( new imageicon(piecelocation) ); panels = (jpanel)chessboard.getcomponent(location); panels.add(pieces); } else{ if(success){ if (c instanceof jlabel){ container parent = c.getparent(); parent.remove(0); string promoteto; { promoteto = (string) joptionpane.showinputdialog(null, "promote to:", "promotion", joptionpane.question_message, null, new string[]{"queen", "bishup", "knight", "rook"}, "queen"); } while (promoteto == null); string newpiece = null; int location = 0; if (piecename.contains("white")) { location = 56 + (e.getx()/75); newpiece = "white"+promoteto; } else { location = (e.getx()/75); newpiece = "black"+promoteto; } pieces = new jlabel( new imageicon(newpiece+".png") ); parent = (jpanel)chessboard.getcomponent(location); parent.add(pieces); validate(); repaint(); } } else{ if (c instanceof jlabel){ container parent = c.getparent(); parent.remove(0); parent.add( chesspiece ); } else { container parent = (container)c; parent.add( chesspiece ); } chesspiece.setvisible(true); } }

java performance swing joptionpane chess

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -