I'm learning Ruby, i just done a small RubyGame to apply what i learned.
Can you review the project ? Im looking for best-practice, refactoring keeping the 3 classes usage.
Well the code is readable and all that even if it seems quite long for a
simple guess a number between X and Y type game. But presentation logic is
always a handful
Anyhow just two little points.
The Core class is used to create the @player instance variable. 'Core' is a
pretty meaningless name, conveys nothing, less than even 'Utils'. It should
probably be called Player as that is what it is. Likewise the UserInterface
class is actually the game isn't it. Again the name is misleading.
In the UserInterface class the game loop is the play method which has a
loop with an explicit exit condition "result != 'a winner'". However there
is another exit, when getting the users input the program can bail if the
user inputs 'quit'.
To be honest I would have ask() pass back the 'quit' and handle things a
little differently. Have the loop allow the user to quit normally, one
point of control. Having an explicit flow control, the while loop, but
hiding other flow control in another function, which is not even directly
called in the loop, is a very bad habit.
The set_name function uses ask so if the user input 'quit' as the name then
ask would bail the whole application, the "try_a_name == 'Quit'" part of
set_name is never going to be called.
The executable should be under a bin or exe folder. Bundled documentation
explains that in great detail.
Also you should convert that code into a gem.
See rubygems guides for documentation.
···
On Tue, 13 Dec 2016 at 10:29, Nathan Guilty <ruby@e-solutions.re> wrote:
Hi,
I'm learning Ruby, i just done a small RubyGame to apply what i learned.
Can you review the project ? Im looking for best-practice, refactoring
The scoreboard works, you need to beat the best time not "tries number"
/Nathan
···
Le 2016-12-14 02:12, Micky Scandal a écrit :
very nice! as mentioned before it seems like this could be made with a
lot less code (although I understand this is a learning excersize),
also does the scoreboard work right? I'm pretty sure i beat the 3rd
highest score and my name didn't end up in the scoreboard. otherwise,
very nice work!