JavafxのGUIでマインスイーパーのアプリケーションを作ろうと考えています。
下に書いてあるコードは8×8の単純なGridPaneで作成し、まだ数字が出るだけで何も特別な処理は加えてません。
このコードにどのような処理を加えればマインスイーパーっぽくなると思いますか?
また、まだ練習なので、本来のゲームだと爆弾の位置はランダムのはずですが、まずは全て固定で作ってみようと思います。
なので64個のマスの中から特定のマス(10個程度)をクリックすると、ゲームが終了するような処理の方法を教えて頂けますと助かります。
よろしくお願い致します。
Java
1コード 2import javafx.application.Application; 3import javafx.scene.Scene; 4import javafx.scene.control.Button; 5import javafx.scene.layout.GridPane; 6import javafx.stage.Stage; 7 8public class MS extends Application 9{ 10 private Button bt1; 11 private Button[][] bt2 = new Button[8][8]; 12 13 public static void main(String[] args) 14 { 15 launch(args); 16 } 17 @Override 18 public void start(Stage stage) throws Exception 19 { 20 21 for(int m=0; m<bt2.length; m++){ 22 for(int c=0; c<bt2[m].length; c++){ 23 bt2[m][c] = new Button(Integer.toString(c) + Integer.toString(m)); 24 } 25 } 26 GridPane gp = new GridPane(); 27 28 for(int m=0; m<bt2.length; m++){ 29 for(int c=0; c<bt2.length; c++){ 30 gp.add(bt2[m][c], m, c); 31 } 32 } 33 34 35 Scene sc = new Scene(gp, 250, 200); 36 stage.setScene(sc); 37 stage.setTitle("マインスイーパー"); 38 stage.show(); 39 } 40}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。