Making a Cee-lo game with Ruby Final improvement after receiving a review

Get a review

In the previous article, the whole code was finished for the time being. However, there are still many ara. That's why I got a code review at the online salon I belong to. There were quite a lot of suggestions, so I responded one by one.

List of points to be pointed out

Grammar related

Move method

Make it easier to read

Other improvements

It would be nice to be able to win or lose and move money with the + operator.

Too many! !! !!

Response to points 1: Grammar-related

Let's do it. First of all, it is related to grammar, but this could be improved rather quickly. Indentation correction was easy with VS Code. I referred to the following article.

Change the number of indented spaces in VS Code

Variable expansion is like this. If you do it like this, you can write clearly.

dice_hand = 'Normal eyes(' + uniq_value.to_s + ')'
↓
dice_hand = "Normal eyes(#{uniq_value.to_s})"

URL of the corresponding issue https://github.com/kyokucho1989/ruby-game/issues/13

Response to issues 2: Method movement, etc.

I did my best in this. First of all, it was said that it was strange for Player to judge victory or defeat and move stakes, so I created a new Game class. The Game class determines the outcome and moves the stake.

Also, I decided to do it with a class method. This is because the game class has no state. (This was also pointed out)

Response to issues 3: Make it easier to read

I also summarized the output of sentences. I created a new message.rb so that all messages can be output from it. This will make it easier to correct the text. How nice!

Response to issues 4: Others

A new module-hand-game.rb was created, and the roles and win / loss results were made constant.

module Match
  WIN  = 'win'
  LOSE = 'Lose'
  DRAW  = 'draw'
end

When referring to it, it looks like this. How nice!

if(my_hand_rank > opponent_hand_rank)
      Match::WIN 
     elsif(my_hand_rank == opponent_hand_rank)
      Match::DRAW
     else
      Match::LOSE
     end

"I hope the operator can win or lose and move money." Could not be dealt with. difficult.

in conclusion

It was fun to be able to program like this with Ruby alone. If you do various things including Rails, you tend to be discouraged due to errors in environment construction. At first, I feel that it is simply more powerful to make something only with Ruby.

I want to make teaching materials with this one day. end. The completed code is here ↓ https://github.com/kyokucho1989/ruby-game

Recommended Posts

Making a Cee-lo game with Ruby Final improvement after receiving a review
Creating a Cee-lo game with Ruby 4th Creating a game progress process
Make a typing game with ruby
With ruby ● × Game and Othello (basic review)
Ruby Learning # 22 Building a Guessing Game
Impressions of making BlackJack-cli with Ruby
The story of making a game launcher with automatic loading function [Java]
Start with a browser Ruby game programming: Introduction to Nyle-canvas (DXRuby style)