Suggestions for Game Logic branch
majovanilla opened this issue · 0 comments
Great work guys!! We found these suggestions that could make your game perform in a better way. Good luck!
-
Avoid using nested whiles. You could do the same with an if-else statement on lines 9-21 using a method to check the option.
-
If you use a method to check the name of the user name it also saves you the two equal loops in lines 25-50.
-
The last if-else statement on line 86 could be refactored to just one if-else and change the variable of p1 or p2 to change the turns (L.89 & L.98) or create a method for that.
-
I think the problem that stops your game after 5 moves is in the way you use the winner method. You use it to check for the winner (lines 77-78) but then you assign the value true (L80). The method itself should throw true or false, so you shouldn't do it manually.
-
Also, remember that one method should do one thing. It's ok to create multiple methods to check on the winner (e.g. L79-81)
-
Try to move all the logic to the game_logic file and just call methods, gets and puts on the main file. It will make your code cleaner.