示例#1
0
    def draw_sudoku(s, difficulty):
        s.solution, seeds = engine.Sudoku().get_puzzle(difficulty)

        for i in range(9):
            for j in range(9):
                cell = s.cells[i][j]
                cell.SetLabel(seeds[i][j])
                if seeds[i][j] == " ":
                    s.seeds[i][j] = False
                    cell.SetFont(s.fnormal)
                else:
                    s.seeds[i][j] = True
                    cell.SetFont(s.funder)
        s.cells[0][0].SetFocus()

        s.difficulty = difficulty
        s.best_times = engine.get_best_times()
        s.cheated = False
        s.time = [0, 0, 0]
        s.frames = 0
        s.timer.Start(40)
示例#2
0
    def __init__(s, parent, title):
        wx.Frame.__init__(
            s,
            parent,
            style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX,
            title=title,
            size=(SCREEN_XSIZE, SCREEN_YSIZE),
        )
        s.status_bar = s.CreateStatusBar()
        s.timer = wx.Timer(s)

        # Set up the top menu
        new_menu = wx.Menu()
        measy = new_menu.Append(wx.ID_ANY, "&Easy\tCtrl+E", "Start an easy sudoku")
        mmedium = new_menu.Append(wx.ID_ANY, "&Medium\tCtrl+D", "Start a medium sudoku")
        mhard = new_menu.Append(wx.ID_ANY, "&Hard\tCtrl+H", "Start a hard sudoku")
        mvhard = new_menu.Append(wx.ID_ANY, "&Very Hard\tCtrl+V", "Start a very hard sudoku")
        # minsane = new_menu.Append(wx.ID_ANY, '&Insane\tCtrl+I', 'What are you... insane?')
        other_menu = wx.Menu()
        s.mst = other_menu.Append(wx.ID_ANY, "&Show Timer\tCtrl+T", "Toggle timer visibility")
        mbt = other_menu.Append(
            wx.ID_ANY, "&Best Times\tCtrl+B", "Display your best solving times for each difficulty level"
        )
        other_menu.AppendSeparator()
        s.sas_text = [
            "an angel loses its wings",
            "a kitten gets sad",
            "the terrorists win",
            "Justin Bieber grows more powerful",
            "doves cry",
            "the bell tolls for thee",
            "eternal love becomes ephemeral",
            "the world ends in 2012",
            "Nazis march through Paris",
            "children get coal in their stockings",
            "the Empire beats the Rebels",
            "Pandora's Box gets opened",
            "you cheat yourself",
            "the Westboro Baptists celebrate",
            "Tinkerbell ceases to exist",
            "Iran gets a nuclear weapon",
            "the next sudoku is unsolvable",
        ]
        s.msas = other_menu.Append(wx.ID_ANY, "&Solve a Square\tCtrl+S", "When you cheat, " + choice(s.sas_text))
        menu_bar = wx.MenuBar()
        menu_bar.Append(new_menu, "&New")
        menu_bar.Append(other_menu, "&Other")
        s.SetMenuBar(menu_bar)

        s.FONT_SIZE = 18
        s.fnormal = wx.Font(s.FONT_SIZE, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, u"Comic Sans MS")
        s.funder = wx.Font(s.FONT_SIZE, wx.DEFAULT, wx.NORMAL, wx.NORMAL, True, u"Comic Sans MS")

        # Make and align the grid cells
        s.cells = []
        for i in range(9):
            s.cells.append([])
            for j in range(9):
                s.cells[-1].append(wx.Button(s, -1, " ", size=(BUTTON_XSIZE, BUTTON_YSIZE), name=str(i) + str(j)))
                s.cells[i][j].SetFont(s.fnormal)
        s.seeds = [[True for i in range(9)] for j in range(9)]
        s.grid = wx.GridSizer(9, 9)
        for row in s.cells:
            for cell in row:
                s.grid.Add(cell)
        s.SetSizer(s.grid)

        # Set events
        s.Bind(wx.EVT_MENU, s.click_easy, measy)
        s.Bind(wx.EVT_MENU, s.click_medium, mmedium)
        s.Bind(wx.EVT_MENU, s.click_hard, mhard)
        s.Bind(wx.EVT_MENU, s.click_vhard, mvhard)
        # s.Bind(wx.EVT_MENU, s.click_insane, minsane)
        s.Bind(wx.EVT_MENU, s.click_st, s.mst)
        s.Bind(wx.EVT_MENU, s.click_bt, mbt)
        s.Bind(wx.EVT_MENU, s.click_sas, s.msas)
        for i in range(9):
            for j in range(9):
                s.cells[i][j].Bind(wx.EVT_BUTTON, s.click_cell)
                s.cells[i][j].Bind(wx.EVT_KEY_DOWN, s.keypress_cell)
        s.Bind(wx.EVT_PAINT, s.on_paint)
        s.Bind(wx.EVT_TIMER, s.second_tick, s.timer)

        s.Show()

        s.best_times = engine.get_best_times()
        s.solution = None
        s.show_timer = False