Help needed drawing a Sudoku board with green shoes

Hello Team,

I am planning to write a Sudoku program just for the learning experience.
I'm first trying to draw the board using *green shoes* (which I am also
learning) as my GUI toolkit.
As most people know, the most common Sudoku board is a 9x9 array. The 9x9
array is subdivided on 3x3 square. I don't want to go into details as I
know that Sudoku is already a very well know game.

To make the game easier to follow it is customary to have some kind of
division between each 3x3 square. It could be a heavy line or some space.

My problem is that I can't find a way to do this with *green shoes*. I am
convinced that it is doable as this appears to be something simple, but I
can't find the way. I already experimented with many version of my code.
Here are the last two versions.

The first version correctly draws the board but with no apparent division
between the 3x3 squares.
The second version stacks all the buttons one after the other. I thought
that the *if else end* stmt that I added could do the trick. But it did not.

Any help will be appreciated as usual.

*FIRST VERSION

require "green_shoes"
require 'rubygems'

Shoes.app :height => 666, :width => 811, :resizable => false do
   background magenta
   title (strong("Sudoku")), :size => 26, :align=>'center'
    para " "
   para " "

   @btn = Array.new(9) {Array.new(9) {123456789}}

   (0..8).each do |r|
      stack :margin => 3 do
         flow :width => 866 do
            (0..8).each do |c|
               @btn[r][c] = button "123456789", :width => 86, :height => 50
            end # End do c
         end # flow
      end # End stack
   end # End do r
end # app

···

*

*SECOND VERSION

*
require "green_shoes"
require 'rubygems'

Shoes.app :height => 666, :width => 811, :resizable => false do

   background magenta
   title (strong("Sudoku")), :size => 26, :align=>'center'
    para " "
   para " "

   @btn = Array.new(9) {Array.new(9) {123456789}}

   (0..8).each do |r|
      stack :margin => 3 do
         (0..8).each do |c|
            if c == 3 or c == 6
               flow :width => 866, :margin => 3 do
                  @btn[r][c] = button "123456789", :width => 86, :height =>
50
               end
            else
               flow :width => 866 do
                  @btn[r][c] = button "123456789", :width => 86, :height =>
50
               end
            end # if
         end # End do c
      end # End stack
   end # End do r
end # app

Thank you

--
Ruby Student

Hi Ruby Student,

I'm not sure this is the solution you are looking for. But try it out. :wink:

require "green_shoes"
require 'rubygems'

Shoes.app :height => 666, :width => 811, :resizable => false do
   background magenta
   title (strong("Sudoku")), :size => 26, :align=>'center'
    para " "
   para " "

   @btn = Array.new(9) {Array.new(9) {123456789}}

   nostroke
   rect 0, 100, 86*9+6, 53*9+3, fill: green
   rect 86*3+3, 100, 86*3, 53*3+2, fill: yellow
   rect 0, 100+53*3+2, 86*3+3, 53*3, fill: yellow
   rect 86*6+3, 100+53*3+2, 86*3+2, 53*3, fill: yellow
   rect 86*3+3, 100+53*6+2, 86*3, 53*3+1, fill: yellow

   (0..8).each do |r|
      stack :margin => 3 do
         flow :width => 866 do
            (0..8).each do |c|
               @btn[r][c] = button "123456789", :width => 86, :height => 50
            end # End do c
         end # flow
      end # End stack
   end # End do r
end # app

Regards,
ashbb

hi ruby student -

  i thought i had 'translated' my shoes sudoku over to green shoes, but
i guess i never did... anyway, maybe this will be of some help even
though it uses red shoes -

shoes on!

- j

···

--
Posted via http://www.ruby-forum.com/.

ashbb,

That is a nice "trick" indeed. Hey, it does the job.

Thank you for your help.

···

On Mon, Jul 1, 2013 at 8:58 AM, ashbb <ashbbb@gmail.com> wrote:

Hi Ruby Student,

I'm not sure this is the solution you are looking for. But try it out. :wink:

require "green_shoes"
require 'rubygems'

Shoes.app :height => 666, :width => 811, :resizable => false do
   background magenta
   title (strong("Sudoku")), :size => 26, :align=>'center'
    para " "
   para " "

   @btn = Array.new(9) {Array.new(9) {123456789}}

   nostroke
   rect 0, 100, 86*9+6, 53*9+3, fill: green
   rect 86*3+3, 100, 86*3, 53*3+2, fill: yellow
   rect 0, 100+53*3+2, 86*3+3, 53*3, fill: yellow
   rect 86*6+3, 100+53*3+2, 86*3+2, 53*3, fill: yellow
   rect 86*3+3, 100+53*6+2, 86*3, 53*3+1, fill: yellow

   (0..8).each do |r|
      stack :margin => 3 do
         flow :width => 866 do
            (0..8).each do |c|
               @btn[r][c] = button "123456789", :width => 86, :height => 50
            end # End do c
         end # flow
      end # End stack
   end # End do r
end # app

Regards,
ashbb

--
Ruby Student

Jake,

I looked and copied your Sudoku and it is very interesting. There are new
things there that I never used or new existed such as

*class_eval*. Your code has been educational to me.

Thank you for sharing

···

On Tue, Jul 2, 2013 at 12:58 PM, jake kaiden <lists@ruby-forum.com> wrote:

hi ruby student -

  i thought i had 'translated' my shoes sudoku over to green shoes, but
i guess i never did... anyway, maybe this will be of some help even
though it uses red shoes -

shoes-stuff/shoes3_sudoku.rb at master · lljk/shoes-stuff · GitHub

shoes on!

- j

--
Posted via http://www.ruby-forum.com/\.

--
Ruby Student