Javaguiプログラミングを学ぼうとしていたとき、私は小さなゲームGojiを書きました。
現在、スタンドアロンバージョンのみが実装されており、すべてが単純に作成されています。ご質問がある場合は、アドバイスをお願いします。
ここのチェスボードとチェスのピースは写真ではなく、すべてがJavaのグラフィックを使用して描かれています。
ソースコードはgithubに送信されました。ここをクリックしてGitHubソースコード
Gozi Chessカテゴリの次のリスト:
java.awt.borderlayout; Import java.awt.color; Import java.awt.container; Import java.awt.graphics; Import java.awt.event.mousevent; Import java.awt.event.mouseListener; Import Java.util.util.javax.swing; Import Javax.swing.swing.swing.swing javax.swing.joptionpane;パブリッククラス5inarow拡張jframeはmouselistener {vector v = new vector(); //各ステップのすべてのチェス情報vector white = new vector(); //ホワイトチェス情報ベクトルブラック= new Vector(); //ブラックチェス情報ブールB; //白い旗またはブラックチェスintホワイトカウント、ブラックカウントの審査に使用されます。 //後悔の数を計算しますint w = 25; //間隔サイズint px = 100、py = 100; //ボードのサイズint pxw = px + w、pyw = py + w; int width = w * 16、height = w * 16; int vline = width + px; //垂直線の長さint hline = height + py; //水平線の長さ/***建設方法*/public Fiveinarow(){super( "stand-alone goji"); this.setDefaultCloseoperation(jframe.exit_on_close); // close button container con = this.getContentPane(); con.setlayout(new borderlayout()); this.addmouseListener(this); //リスナーを追加this.setsize(600、600); // form size this.setbackground(color.orange); this.setVisible(true); }/***チェスボードとチェスのピースを描く* @param e*/public void paint(graphics g){g.clearrect(0、0、this.getWidth()、this.getheight()); //アートボードG.setcolor(color.black); G.DrawString( "Stand-Alone Gozi Mini Game、右クリックしてChessを後悔し、Welcome To Welcome"、180、70); for(int i = 0; i <15; i ++){g.drawline(pxw+i*w、py、pxw+i*w、hline); //各水平および垂直線g.drawline(px、pyw+i*w、vline、pyw+i*w); } for(int x = 0; x <v.size(); x ++){string str =(string)v.get(x); string tmp [] = str.split( " - "); int a = integer.parseint(tmp [0]); int b = integer.parseint(tmp [1]); a = a * w + px; b = b * w + py; if(x%2 == 0){g.setcolor(color.white); } else {g.setcolor(color.black); } g.fillarc(aw/2、bw/2、w、w、0、360); }} @Override public void mouseclicked(mouseEvent e){if(e.getButton()== e.button1){int x = e.getx(); int y = e.gety(); x =(x -x%w) +(x%w> w / 2?w:0); y =(y -y%w) +(y%w> w / 2?w:0); x =(x -px) / w; y =(y -py) / w; if(x> = 0 && y> = 0 && x <= 16 && y <= 16){if(v.contains(x+" - "+y)){system.out.println( "すでにチェスがあります!"); } else {v.add(x+" - "+y); this.repaint(); if(v.size()%2 == 0){black.add(x+" - "+y); this.victory(x、y、black); // system.out.println( "black chess"); } else {white.add(x+" - "+y); this.victory(x、y、white); // system.out.println( "white chess"); } // system.out.println(e.getx()+" - "+e.gety()); }} else {// system.out.println(e.getx()+" - "+e.gety()+"|"+x+" - "+y+"/tは境界を超えます"); }} if(e.getButton()== e.button3){//チェスを右クリックする方法// system.out.println( "右クリックチェス - チェス"); if(v.isempty()){joptionpane.showmessagedialog(これ、後悔するチェスはありません "); } else {if(v.size()%2 == 0){//チェスを後悔している白いチェスなのか、チェスブラックカウント++を後悔している黒チェスであるかを判断します。 if(blackcount> 3){joptionpane.showmessagedialog(これ、「ブラックチェスは3つのステップを後悔している」); } else {v.remove(v.lastelement()); this.repaint(); }} else {whitecount ++; if(whitecount> 3){joptionpane.showmessagedialog(これ、「ブラックチェスは3つのステップを後悔している」); } else {v.remove(v.lastelement()); this.repaint(); }}}}}}} / ** *勝利を判断する方法 * @param x * @param y * @param contains * / private void victory(int x、int y、vector contains){int cv = 0; //垂直方向のチェスピースの数int ch = 0; //水平チェスピースの数int ci1 = 0; //斜面方向のチェスピースの数1 int ci2 = 0; //勾配方向のチェス片の数2 //水平方向のチェスピースの数を計算します(int i = 1; i <5; i ++){if(contabl.contains((x+i)+" - "+y)){ch ++; } else {break; }} for(int i = 1; i <5; i ++){if(contal.contains((xi)+" - "+y)){ch ++; } else {break; }} //(int i = 1; i <5; i ++){if(contal.contains(x+" - "+(y+i))){cv ++; } else {break; }} for(int i = 1; i <5; i ++){if(contal.contains(x+" - "+(yi))){cv ++; } else {break; }} //(int i = 1; i <5; i ++){if(cantaber.contains((x+i)+" - "+(y+i))){ci1 ++; } else {break; }} for(int i = 1; i <5; i ++){if(contal.contains((xi)+" - "+(yi))){ci1 ++; } else {break; }} //(int i = 1; i <5; i ++){if(cantable.contains((x+i)+" - "+(yi))){ci2 ++; } else {break; }} for(int i = 1; i <5; i ++){if(contal.contains((x+i)+" - "+(yi)){ci2 ++; } else {break; }} for(int i = 1; i <5; i ++){if(contal.contains((xi)+" - "+(y+i))){ci2 ++; } else {break; }} if(ch> = 4 || cv> = 4 || ci1> = 4 || ci2> = 4){system.out.println(v.size()+"step"); if(v.size()%2 == 0){// joptionpane.showmessageialog(null、 "black")を獲得するのが黒か白かを判断します。 } else {joptionpane.showmessageialog(null、 "white"); } this.v.clear(); this.black.clear(); this.white.clear(); this.repaint(); }} @Override public void mouseentered(mousevent e){// todo auto-fide method stub} @override public void mouseexited(MouseEvent e){// todo auto-enerated method stub} @Override public void mousepresse MousePressed(MouseEvent e){// Todo auto-denerated method stub} @override public void mousereleased(mousevent e){// todo auto-enerated method stub}}}PS:Gojiの別のオンラインバージョンを書く予定ですが、残念ながらJavaのインターネットについてはあまり知りません。それを完了し続け、個人的な学習結果をテストする前に、しばらく勉強しなければなりません。
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。