• 大小: 515KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-06-23
  • 语言: Java
  • 标签: 数独  JAVA  生成  唯一解  

资源简介

自己用GUI写的一个数独小游戏。。可选择难度,生成一个只有唯一解的数独。。可显示答案,玩家也可以自己做题。代码+算法全在里面

资源截图

代码片段和文件信息


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.LineBorder;
import java.util.Random;
/**
 *
 * @author 晓之篷
 */
@SuppressWarnings(“serial“)
public class Sudoku extends Jframe{
    object[] fivelevel={12345};
    object level=JOptionPane.showInputDialog(null “1.初级--2.低级--3.中级--4高级--5.骨灰级“ “请选择难度“ JOptionPane.QUESTION_MESSAGE nullfivelevel fivelevel[2]);
    private IndexButton[][] button=new IndexButton[9][9];
    private JButton check=new JButton(“检查“);  //检查正确是否
    private JButton displayanswer=new JButton(“显示答案“);  //列出答案
    private JButton hideanswer=new JButton(“隐藏答案“);  //隐藏答案
    private CSSudoku cssudoku=new CSSudoku((int)(level));   //创建和解答数独
    private int[][] shudu=cssudoku.MySudoku();   //把创建的数独赋值给shudu[][]
    public Sudoku() {
        JPanel pbutton=new JPanel();
        pbutton.setLayout(new GridLayout(1155));
        pbutton.add(check);
        pbutton.add(displayanswer);
        pbutton.add(hideanswer);
        hideanswer.setEnabled(false);
        add(new SudokuPanel(shudu)BorderLayout.CENTER);
        add(pbuttonBorderLayout.SOUTH);
         for(int i=0;i<9;i++){       //给每个按钮增加监听事件
                for(int j=0;j<9;j++){
                    button[i][j].addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        IndexButton b=(IndexButton) e.getSource();
                        UpdateButton(b.geti()b.getj());
                    }
                });  
                }
         }
        check.addActionListener(new ActionListener() {   //给check增加监听事件
            @Override
            public void actionPerformed(ActionEvent e) {
                if(CSSudoku.test(shudu)==1){  //检查结果正确
                    JOptionPane.showMessageDialog(null “正确“ “检查结果“ JOptionPane.INFORMATION_MESSAGE);
                }
                else{
                    JOptionPane.showMessageDialog(null “有错误“ “检查结果“ JOptionPane.INFORMATION_MESSAGE);
                }
            }
        });
        displayanswer.addActionListener(new ActionListener() {   //显示答案的监听事件
            @Override
            public void actionPerformed(ActionEvent e) {
                int[][] result=new int[9][9];
                for(int i=0;i<9;i++){
                    for(int j=0;j<9;j++) {
                        result[i][j]=shudu[i][j];
                    }         
                }
                if(cssudoku.SolveSudoku(result)){   //得到答案
                     result=cssudoku.ResultSudoku();
                     for(int i=0;i<9;i++){         
                        for(int j=0;j<9;j++){
                            if(button[i][j].getBackground()==Color.WHITE||button[i][j].getBackground()==Color.RED){     //将玩家已经输入值的按钮设置成不可操作
                               button[i][j].setEnabled(false); 
                            }
                     

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件         75  2012-04-03 16:56  Sudoku\build\built-jar.properties

     文件          0  2012-04-03 16:56  Sudoku\build\classes\.netbeans_automatic_build

     文件          0  2012-04-03 16:56  Sudoku\build\classes\.netbeans_update_resources

     文件       7135  2012-04-03 16:56  Sudoku\build\classes\CSSudoku.class

     文件        677  2012-04-03 16:56  Sudoku\build\classes\IndexButton.class

     文件        870  2012-04-03 16:56  Sudoku\build\classes\Sudoku$1.class

     文件        961  2012-04-03 16:56  Sudoku\build\classes\Sudoku$2.class

     文件       1927  2012-04-03 16:56  Sudoku\build\classes\Sudoku$3.class

     文件       1380  2012-04-03 16:56  Sudoku\build\classes\Sudoku$4.class

     文件       1314  2012-04-03 16:56  Sudoku\build\classes\Sudoku$5.class

     文件       2000  2012-04-03 16:56  Sudoku\build\classes\Sudoku$SudokuPanel.class

     文件       3851  2012-04-03 16:56  Sudoku\build\classes\Sudoku.class

     文件         31  2012-04-03 16:56  Sudoku\build\classes\Sudoku.rs

     文件       3713  2012-04-03 16:23  Sudoku\build.xml

     文件       1322  2012-04-03 16:56  Sudoku\dist\README.TXT

     文件      20761  2012-04-03 16:56  Sudoku\dist\Sudoku.jar

     文件         85  2012-04-03 16:23  Sudoku\manifest.mf

     文件      56944  2012-04-03 16:30  Sudoku\nbproject\build-impl.xml

     文件        475  2012-04-03 16:30  Sudoku\nbproject\genfiles.properties

     文件        103  2012-04-03 16:27  Sudoku\nbproject\private\private.properties

     文件        211  2012-04-03 16:56  Sudoku\nbproject\private\private.xml

     文件       2318  2012-04-03 16:32  Sudoku\nbproject\project.properties

     文件        514  2012-04-03 16:30  Sudoku\nbproject\project.xml

     文件      20301  2012-04-03 16:52  Sudoku\src\Sudoku.java

     目录          0  2012-04-03 16:56  Sudoku\build\generated-sources\ap-source-output

     目录          0  2012-04-03 16:56  Sudoku\build\classes

     目录          0  2012-04-03 16:56  Sudoku\build\empty

     目录          0  2012-04-03 16:56  Sudoku\build\generated-sources

     目录          0  2012-04-03 16:19  Sudoku\nbproject\configs

     目录          0  2012-04-03 16:56  Sudoku\nbproject\private

............此处省略9个文件信息

评论

共有 条评论