96编辑器旗下产品
找图
终身
ID:0
到期时间:永久
退出登录
您的位置:首页 > 百科管理 > 详情

扫雷制作素材-怎么用vb做扫雷程序

原创:找图网 2023-07-08 15:19:30
  • 需要一个扫雷源代码JAVA编写的急,要能运行的了的要是好用给20分

  • 呵,我刚好有一个,花了半天时间才20分唉。

    package ;

    import ;

    import .*;

    import ;

    import .*;

    /**

    *

    * @author ss

    *

    */

    public class Winmine extends JFrame implements ActionListener {

    private static final long serialVersionUID = 1L;

    GridLayout gridLayout;

    JButton[] btn;

    JPanel pMain;

    JMenuBar jMenuBar;

    JMenu game;

    JMenuItem start;

    int width, height;

    Random random;

    int[] mine;

    public Winmine(int width, int height) {

    random = new Random();

    = width;

    = height;

    jMenuBar = new JMenuBar();

    game = new JMenu("游戏");

    start = new JMenuItem("开始");

    (this);

    (game);

    (start);

    (jMenuBar);

    gridLayout = new GridLayout(width, height);

    pMain = new JPanel();

    (gridLayout);

    btn = new JButton[width * height];

    for (int i = 0; i < width * height; i++) {

    btn[i] = new JButton();

    btn[i].addActionListener(this);

    (btn[i]);

    }

    produceMine(width, height);

    ().add(pMain);

    (width * 50, height * 40);

    (true);

    (_ON_CLOSE);

    }

    public void actionPerformed(ActionEvent event) {

    try {

    JMenuItem jMenuItem = (JMenuItem) ();

    ();

    produceMine(width, height);

    replay();

    return;

    } catch (Exception e) {

    }

    JButton button = (JButton) ();

    for (int i = 0; i < width * height; i++) {

    if (button == btn[i]) {

    if (!checkMine(i)) {

    (this, "对不起,你点到地雷啦!");

    loseGame();

    } else {

    int num = getMineQoh(i);

    btn[i].setText(num + "");

    btn[i].setEnabled(false);

    if (num == 0) {

    clickBtn(i);

    }

    isWinGame();

    break;

    }

    }

    }

    }

    // 输了

    public void loseGame() {

    for (int i = 0; i < ; i++) {

    btn[mine[i]].setText("*");

    }

    for (int i = 0; i < ; i++) {

    btn[i].setEnabled(false);

    }

    }

    // 重新开始新游戏

    public void replay() {

    for (int i = 0; i < ; i++) {

    btn[i].setText("");

    btn[i].setEnabled(true);

    }

    }

    // 是否获胜

    public void isWinGame() {

    int qoh = 0;

    for (int i = 0; i < ; i++) {

    if (!btn[i].isEnabled()) {

    qoh++;

    }

    }

    if (qoh == width * height - ) {

    (this, "恭喜您赢了!");

    }

    }

    // 如果得到点击铵钮附近地雷数为0的话

    public void clickBtn(int index) {

    int[] around = getIndex(index);

    for (int i = 0; i < ; i++) {

    btn[around[i]].doClick();

    }

    }

    // 得到点击铵钮附近的地雷数

    public int getMineQoh(int index) {

    int num = 0;

    int[] around = getIndex(index);

    for (int i = 0; i < ; i++) {

    for (int j = 0; j < ; j++) {

    if (around[i] == mine[j]) {

    num++;

    continue;

    }

    }

    }

    return num;

    }

    // 得到点击铵钮附近的索引号

    public int[] getIndex(int index) {

    int[] left = new int[height - 2];

    for (int i = 0; i < ; i++) {

    left[i] = (i + 1) * width;

    }

    int[] right = new int[height - 2];

    for (int i = 0; i < ; i++) {

    right[i] = (i + 2) * width - 1;

    }

    int[] top = new int[width - 2];

    for (int i = 0; i < ; i++) {

    top[i] = i + 1;

    }

    int[] floor = new int[width - 2];

    for (int i = 0; i < ; i++) {

    floor[i] = width * (height - 1) + i + 1;

    }

    int[] around = new int[3];

    if (index == 0) {

    around[0] = 1;

    around[1] = width;

    around[2] = width + 1;

    } else if (index == width - 1) {

    around[0] = width - 2;

    around[1] = 2 * width - 2;

    around[2] = 2 * width - 1;

    } else if (index == (height - 1) * width) {

    around[0] = (height - 2) * width;

    around[1] = (height - 2) * width + 1;

    around[2] = (height - 1) * width + 1;

    } else if (index == height * width - 1) {

    around[0] = (height - 1) * width - 2;

    around[1] = (height - 1) * width - 1;

    around[2] = height * width - 2;

    } else {

    around = new int[5];

    for (int i = 0; i < ; i++) {

    try {

    if (index == top[i]) {

    around[0] = top[i] - 1;

    around[1] = top[i] + 1;

    around[2] = top[i] + width - 1;

    around[3] = top[i] + width;

    around[4] = top[i] + width + 1;

    return around;

    } else if (index == floor[i]) {

    around[0] = floor[i] - width - 1;

    around[1] = floor[i] - width;

    around[2] = floor[i] - width + 1;

    around[3] = floor[i] - 1;

    around[4] = floor[i] + 1;

    return around;

    } else if (index == left[i]) {

    around[0] = left[i] - width;

    around[1] = left[i] - width + 1;

    around[2] = left[i] + 1;

    around[3] = left[i] + width;

    around[4] = left[i] + width + 1;

    return around;

    } else if (index == right[i]) {

    around[0] = right[i] - width - 1;

    around[1] = right[i] - width;

    around[2] = right[i] - 1;

    around[3] = right[i] + width - 1;

    around[4] = right[i] + width;

    return around;

    }

    } catch (Exception e) {

    }

    }

    around = new int[8];

    around[0] = index - width - 1;

    around[1] = index - width;

    around[2] = index - width + 1;

    around[3] = index - 1;

    around[4] = index + 1;

    around[5] = index + width - 1;

    around[6] = index + width;

    around[7] = index + width + 1;

    }

    return around;

    }

    // 检查点到的铵钮是否是地雷

    public boolean checkMine(int btnIndex) {

    return checkNum(btnIndex, mine);

    }

    // 得到不重复数字的方法

    public boolean checkNum(int num, int[] arrayNum) {

    for (int i = 0; i < ; i++) {

    if (arrayNum[i] == num) {

    return false;

    }

    }

    return true;

    }

    // 生成地雷的方法

    public void produceMine(int width, int height) {

    int qoh = width * height / 5;

    int index;

    mine = new int[qoh];

    for (int i = 0; i < qoh; i++) {

    index = (width * height);

    if (checkNum(index, mine)) {

    mine[i] = index;

    } else {

    i--;

    }

    }

    }

    public static void main(String[] args) {

    new Winmine(16, 16);

    }

    }

    感觉还行

  • 扫雷的逻辑是怎样的(程序制作

  • 可以实现:

    (1) 定义一个雷区结构体,存放当前雷区有无雷,周边有几个雷区有雷,用户标识有雷标志;

    踩开标志;

    (2) 定义一个二维 雷区 数组,描述 雷场;

    (3) 定义二个变量,保存当前 排雷的 区域(行,列);其它变量(计时,计分,计雷数等)根据需要定义;

    (4) 初始化,生成雷场;雷区显示方式为未排雷;

    (5) 循环

    显示雷场;

    扫描用户输入(用KBHIT);

    如果是光标键,改变当前排雷区域;如果是回车键,设定当前雷场踩开标志;(无雷->踩开同时周边无雷区域一并踩开,有雷->结束);如果是空格, 标识有雷或取消标识;

    如果未排开雷区数等于总雷数,游戏结束,显示用户成绩;

    (6)根据用户选择,到(4)重新开始 或退出程序。

    如果用图形界面,初学者可以VB,想一步到位就用VC;装个Visual Studio 6 或 2010 就行。

  • 怎么用vb做扫雷程序

  • 先说一个 扫雷的吧,,没办法给你

    源程序

    ,

    就给你说制作过程吧,

    打开VB6.0

    在窗体的上半部分,用pictureBOX控件画一定的区域用来模仿WINDOWS那样的,里面显示雷数,时间,以及开始,,并且命名为picture1

    在画好后,在picture1里 放4个控件,text1,text2,commandbutton(按钮),timer1.并且给这4个控件属性定义属性值:text1和text2的BackColor属性为黑色,ForeColor为红色,FONT属性改为小二号。text1 的text属性为10,text2的text属性为0

    按钮控件的名称属性改为C1,Caption属性改为开始。FONT属性改为小二号

    Timer1 属性 Enabled 为 False, Interval为1000

    再Picture1的下面再用Picturebox控件画一定的区域做为雷区。将这个控件的名称属性改为P ,AutoRedraw属性改为True

    然后再把控件P(雷区)里 放一个按钮(数组)控件,其属性:名称改为C,Caption为空

    (怎么建数组控件?就是在该控件上点右键选择复制,在空白区选择粘贴,系统会提示你是否建立数组控件,你选是就OK了) 它变成数组控件后,两个控件名称一样都是C 但是会有一个C(0)和C(1) 你把(1)的删除就行了,在C(0)控件的属性style改为1,

    做完以上的,,只需要把以下代码复制到代码区即刻运行

    最新文章 更多
    最新素材 更多
    公司介绍 网站地图 图片资讯
    Copyright © 2010-2022 山东找图网络科技有限公司  鲁ICP备18007836号-3  邮箱:15653358549@163.com