Page 1 of 2
Sliding Tile Puzze
Posted: Tue Feb 09, 2016 11:12 am
by martinvicanek
This is my little vacation Ruby excercise.

Download only if you need to kill time and have absolutely nothing else to do.
Re: Sliding Tile Puzze
Posted: Tue Feb 09, 2016 12:00 pm
by billv
Crashed FS on load..3.06 (Pebble)...twice.....What version is it built with?
Re: Sliding Tile Puzze
Posted: Tue Feb 09, 2016 12:26 pm
by adamszabo
Very nice! I remember I had a game like this when I was a kid

works fine in 3.0.8
Re: Sliding Tile Puzze
Posted: Tue Feb 09, 2016 2:36 pm
by martinvicanek
Sorry, billv. I am using 3.0.8. I have a suspicion what might have caused the crash in an earlier version. Try the updated fsm in the original post.
Re: Sliding Tile Puzze
Posted: Tue Feb 09, 2016 8:21 pm
by RJHollins
Nice 3-d frame !
won't even begin to start playing the game for obvious reasons

Re: Sliding Tile Puzze
Posted: Tue Feb 09, 2016 8:49 pm
by tulamide
This version runs with 3.0.6
Well done!
There are a few things to optimize, but not that much. The pens, brushes and colors are assigned to variables, which makes it easier to select the correct ones. But it also allows you to define them in the initializion method instead of the draw method, where they are defined on each draw call. By defining them just once, the garbage collector has much less work to do, which means less cpu usage.
The condition of an if clause always resolves to true or false, so it is valid to write
Code: Select all
if @mybool
#do something if @mybool is set to true
end
Once again you use indentation (which is more important than people might think). If you now could also get rid of the old-school-behavior of using as less spaces as possible, your code would be perfect!
Code: Select all
a=(b*c)/d-e^^f #old way
a = (b * c) / d - e^^f #better readable
Re: Sliding Tile Puzze
Posted: Tue Feb 09, 2016 10:34 pm
by billv
Thanks Martin...yeh, all good now on 3.06.
Nice work.
Re: Sliding Tile Puzze
Posted: Wed Feb 10, 2016 12:10 am
by martinvicanek
tulamide wrote:The pens, brushes and colors [...] define them in the initializion method instead of the draw method, where they are defined on each draw call.
Fair enough, and you made this point earlier. We really need this facepalm emoticon.
tulamide wrote:If you now could also get rid of the old-school-behavior of using as less spaces as possible, your code would be perfect!
Code: Select all
a=(b*c)/d-e^^f #old way
a = (b * c) / d - e^^f #better readable
I use spaces around "+" and "-", but not around "*" or "/" as they have stronger binding. For me it is easier to see that
is a three term expression. At least we agree that the exponent should not be detached from its base. (a ^ 2 - ouch!).

Re: Sliding Tile Puzze
Posted: Wed Feb 10, 2016 12:50 am
by tulamide
martinvicanek wrote:I use spaces around "+" and "-", but not around "*" or "/" as they have stronger binding. For me it is easier to see that
is a three term expression. At least we agree that the exponent should not be detached from its base. (a ^ 2 - ouch!).

It's not so much about personal preference. Pretty much all programming languages, at least the ones I know, have style guides. This is to agree on a common way to write code, so that it is easily interchangeable while all programmers recognize the code fast and easy. Ruby has such a style guide as well, and it says:
Use spaces around operators, after commas, colons and semicolons, around { and before }.
Code: Select all
sum = 1 + 2
a, b = 1, 2
1 > 2 ? true : false; puts "Hi"
[1, 2, 3].each { |e| puts e }
Here are two versions of the style guide (they are the same, but I don't know which one will be updated more regularly (probably the second link):
https://github.com/styleguide/rubyhttps://github.com/airbnb/rubyBut we are in the same boat. There are some things that I still need to get used to (like using parantheses with methods and indenting when only as deep as case) and even some that I don't agree to (the style guide tells me that "and", "or" and "not" are banned and I should use &&, || and ! instead. I disagree extremely on this, because Ruby's goal is to be readable as easy as possible. Using strange signs instead of clear words doesn't help towards that goal)
The more we get used to the style guide, the easier it is for us to work on shared projects. That's why I pointed to it so strong

Re: Sliding Tile Puzze
Posted: Wed Feb 10, 2016 3:23 am
by RJHollins
We all learn from these posts.
Thank-you Gentlemen
