Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

Sliding Tile Puzze

Post any examples or modules that you want to share here

Sliding Tile Puzze

Postby martinvicanek » Tue Feb 09, 2016 11:12 am

This is my little vacation Ruby excercise. :) Download only if you need to kill time and have absolutely nothing else to do.
Attachments
slidingTilePuzzle.fsm
(959.1 KiB) Downloaded 1122 times
Last edited by martinvicanek on Tue Feb 09, 2016 2:33 pm, edited 1 time in total.
User avatar
martinvicanek
 
Posts: 1334
Joined: Sat Jun 22, 2013 8:28 pm

Re: Sliding Tile Puzze

Postby billv » Tue Feb 09, 2016 12:00 pm

Crashed FS on load..3.06 (Pebble)...twice.....What version is it built with?
billv
 
Posts: 1158
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Re: Sliding Tile Puzze

Postby adamszabo » Tue Feb 09, 2016 12:26 pm

Very nice! I remember I had a game like this when I was a kid :)
works fine in 3.0.8
adamszabo
 
Posts: 667
Joined: Sun Jul 11, 2010 7:21 am

Re: Sliding Tile Puzze

Postby martinvicanek » Tue Feb 09, 2016 2:36 pm

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.
User avatar
martinvicanek
 
Posts: 1334
Joined: Sat Jun 22, 2013 8:28 pm

Re: Sliding Tile Puzze

Postby RJHollins » Tue Feb 09, 2016 8:21 pm

Nice 3-d frame !

won't even begin to start playing the game for obvious reasons :lol:
RJHollins
 
Posts: 1571
Joined: Thu Mar 08, 2012 7:58 pm

Re: Sliding Tile Puzze

Postby tulamide » Tue Feb 09, 2016 8:49 pm

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
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Sliding Tile Puzze

Postby billv » Tue Feb 09, 2016 10:34 pm

Thanks Martin...yeh, all good now on 3.06.
Nice work.
billv
 
Posts: 1158
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Re: Sliding Tile Puzze

Postby martinvicanek » Wed Feb 10, 2016 12:10 am

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. :lol:
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
Code: Select all
a^2 + 2*a*b + b^2
is a three term expression. At least we agree that the exponent should not be detached from its base. (a ^ 2 - ouch!). :mrgreen:
User avatar
martinvicanek
 
Posts: 1334
Joined: Sat Jun 22, 2013 8:28 pm

Re: Sliding Tile Puzze

Postby tulamide » Wed Feb 10, 2016 12:50 am

martinvicanek wrote:I use spaces around "+" and "-", but not around "*" or "/" as they have stronger binding. For me it is easier to see that
Code: Select all
a^2 + 2*a*b + b^2
is a three term expression. At least we agree that the exponent should not be detached from its base. (a ^ 2 - ouch!). :mrgreen:


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/ruby
https://github.com/airbnb/ruby

But 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 :)
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Sliding Tile Puzze

Postby RJHollins » Wed Feb 10, 2016 3:23 am

We all learn from these posts.

Thank-you Gentlemen 8-)
RJHollins
 
Posts: 1571
Joined: Thu Mar 08, 2012 7:58 pm

Next

Return to User Examples

Who is online

Users browsing this forum: No registered users and 29 guests