• 大小: 12KB
    文件类型: .java
    金币: 2
    下载: 1 次
    发布日期: 2021-11-24
  • 语言: Java
  • 标签: java  

资源简介

简易版扫雷程序代码 public class MineSweeperGame2 extends Application { Cell[][] cell; int totalMines=0; int markBomb=0; //总的地雷数量,简单会有10个,一般会有40个,困难99个 int showMines=10; String s=String.valueOf(showMines); Label tips=new Label("Game is running!"); Label showMineNum=new Label("mines: "+s); public void start(Stage primaryStage){ Stage startStage=new Stage(); //选择按钮的界面 Button startButton=new Button("RESTART"); Button chooseeasy=new Button(" EASY (10mines)"); Button choosenormal=new Button("NORMAL(40mines)"); Button choosehard=new Button(" HARD(99mines)"); BorderPane primaryPane=new BorderPane(); HBox startPane=new HBox(15); StackPane topButtonPane=new StackPane(startButton); StackPane topButtonPane2=new StackPane(showMineNum); StackPane buttomPane=new StackPane(tips); HBox topPane=new HBox(50); topPane.getChildren().addAll(topButtonPane,topButtonPane2); primaryPane.setTop(topPane); tips.setStyle("-fx-border-color:red;-fx-background-color:white;"); showMineNum.setStyle("-fx-border-color:black"); primaryPane.setBottom(buttomPane); buttomPane.setPadding(new Insets(15,15,15,15)); topPane.setPadding(new Insets(15,15,15,15)); startPane.setPadding(new Insets(15,15,15,15)); startPane.getChildren().add(chooseeasy); startPane.getChildren().add(choosenormal);

资源截图

代码片段和文件信息


import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Text;
import javafx.scene.layout.Pane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.input.MouseButton;

public class MineSweeperGame2 extends Application {
Cell[][] cell;
int totalMines=0;
int markBomb=0;                           //总的地雷数量,简单会有10个,一般会有40个困难99个
int showMines=10;
String s=String.valueOf(showMines);
Label tips=new Label(“Game is running!“);
Label showMineNum=new Label(“mines: “+s);
public void start(Stage primaryStage){
Stage startStage=new Stage();                 //选择按钮的界面

Button startButton=new Button(“RESTART“);
Button chooseeasy=new Button(“ EASY (10mines)“);
Button choosenormal=new Button(“NORMAL(40mines)“);
Button choosehard=new Button(“ HARD(99mines)“);

BorderPane primaryPane=new BorderPane();
HBox startPane=new HBox(15);
StackPane topButtonPane=new StackPane(startButton);
StackPane topButtonPane2=new StackPane(showMineNum);
StackPane buttomPane=new StackPane(tips);
HBox topPane=new HBox(50);
topPane.getChildren().addAll(topButtonPanetopButtonPane2);

primaryPane.setTop(topPane);
tips.setstyle(“-fx-border-color:red;-fx-background-color:white;“);
showMineNum.setstyle(“-fx-border-color:black“);
primaryPane.setBottom(buttomPane);

buttomPane.setPadding(new Insets(15151515));
topPane.setPadding(new Insets(15151515));
startPane.setPadding(new Insets(15151515));
startPane.getChildren().add(chooseeasy);
startPane.getChildren().add(choosenormal);
startPane.getChildren().add(choosehard);

startButton.setOnAction(e->{ 
startStage.show();
tips.setText(“Game is running!!!“);               //界面下方提示语
});

chooseeasy.setOnAction(e->{                           //简单按钮实现9*9的游戏面板,设计成11*11是为了让后面的功能容易实现
GridPane minePane1=new GridPane();
showMines=10;
s=String.valueOf(showMines);
showMineNum.setText(“mines: “+s);
cell=new Cell[11][11];
for(int i=0;i<11;i++){
for(int j=0;j<11;j++){
cell[i][j]=new Cell(ij);
cell[i][j].getChildren().add(cell[i][j].text);   //每一个地雷格子需要有一个控制显示的text
}
}
for(int i=1;i<10;i++){
for(int j=1;j<10;j++){
cell[i][j].isUsed=true;
minePane1.add(cell[i][j] i-1 j-1);   //显示输出除了最外围一圈的格子
}
}
createGameBoard(cell);
primaryPane.setCenter(minePane1);
startStage.close();
primaryStage.show();

});
choosenormal.setOnAction(e->{                     //普通按钮实现16*16的游戏面板,设计成18*18是为了让后面的功能容易实现
GridPane minePane2=new GridPane();
showMines=40;
s=String.valueOf(showMines);
showMineNum.setText(“mines: “+s);
cell=new Cell[18][18];
for(int i

评论

共有 条评论