#8. Fixing up a little

Hey! So as i said in probably 5th post blog , I’m gonna write in English in this post. Well ,  let’s start..

 

OK, so in last post #7 about plans i said i have to fix some things to work better:

  1. When i run game dot shows up without random time, just show up instantly
  2. When game is finished, until score screen is show up we have to wait random time

Let’s start with 1st ‘bug’. So dot was created in GameDotService in init() method. Init() method was also reacts on player touch, change screen when game is finished …. Yeah too much in one method. So i decided to refactor it. First what i saw was that first dot which was created, was created without any timer. So i decided to move all code in init() method to some another and slowly work out on that code. I created some working method and moved that code right there. Then i notice i should create different method for spawning dot and for react on click, so I did. In spawn method i created timer and inside this timer dots are created. Also in those method i have another method which react on click. OK it starting to be really boring what i’m saying so to the point… IN SHORT: I destroy one BIG method which is really BAD practice to do that and i create a few small methods which are doing same job. Actually they doing more. I was surprised that, when I started game after all those refactoring 2nd problem was fixed. I analyzed why and that’s of course because timer is working now only on dot creating section.

 

Important NOTE for me and all of You: create smaller but more methods, so You can more easy modify something in that or You can more easy find something wrong in that code!

Okay, that’s all on today, I’m hope all of You understood what i wrote in that post and at least got my mind. As almost always i want to add some pictures, so here u have code before and after refactoring. Of course if u want to see actual, and maybe help me a little on that u can visit my Github. See you in Thursday! 🙂

 

 

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *