Re: Coding gnome-sudoku



On Fri, 2016-07-29 at 15:50 +0200, Igor Lopez wrote:
I would like to get the first unsolved board to display when I do a
"quick
click"
and if I do a "long click" I would like to get up a list showing all
current games
on disk (both solved and unsolved) with the solved ones in different
font
and being
able to click on one of the games in the list (either unsolved or
solved)
and play/replay
that board.

I would recommend against making different types of clicks perform
different actions on the button. That will be really confusing to
users.

1)  The board generation is run by a Worker which eventually ends up
at:
          puzzle = QQwing.generate_puzzle ((int) category);   // in
sudoku-generator.vala
     So when the first run is performed for a number of boards how do
I get
new boards when
     I need to fill up the list?

Currently there's no saved state, we just generate a bunch of boards,
add them to a list, and return them. You probably don't want to modify
the SudokuGenerator as the code there is tricky. The public interface
is pretty easy to use, though, so I would use that to get new boards
when you want them:

SudokuGenerator.generate_boards_async.begin (num_boards, difficulty, (obj, res) => {
        try {
            var boards = SudokuGenerator.generate_boards_async.end (res);
            // Do something with your boards
        } catch (Error e) {
            // ThreadError or IOError, unlikely
        }
    });

Then store the boards you get from that in some other list somewhere
and call it again whenever you want to get some new boards to add to
your list.

If you haven't worked with async functions before: the implementation
is a bit tricky but they're easy to use. The begin function returns
immediately, you pass to it a GAsyncReadyCallback that will be executed
sometime in the future when it completes. Usually easiest to use a
lambda for this, if the implementation is small. Inside that callback,
you pass the GAsyncResult res to the end function, and out pops your
result. If the async function throws an exception (generate_boards can
throw two types of exceptions), it will be thrown from the end
function.

Michael


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]