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

Hi Ruby S.,

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, 869+6, 539+3, fill: green
rect 863+3, 100, 863, 533+2, fill: yellow
rect 0, 100+53
3+2, 863+3, 533, fill: yellow
rect 866+3, 100+533+2, 863+2, 533, fill: yellow
rect 863+3, 100+536+2, 863, 533+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

ashbb,

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

Thank you for your help.

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

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