BenASavage / Mastermind

0 stars 0 forks source link

Refactor Code Class for reusability #3

Open BCoons05 opened 4 years ago

BCoons05 commented 4 years ago

We should make it so that we can alter the length of the secret code. We should be able to send the length of the code as a argument instead of having it hard coded within the class. I know it is silly, because the rules of the game are that the code is 4 colors, but in reality you would want to do it this way in a real program.

I will work on this later, but that's all for today.

BCoons05 commented 4 years ago

This is pretty tough. Imagine a situation where your company wants to add an option where you allow the user to select how many guesses and the length of the code. With the current set up this wouldn't be possible. You would want to program in a way that allows you to change one variable and it would change the whole game from there.

I am still working on it

BCoons05 commented 4 years ago

here is an example of why I want to change things. Currently you generate a code like this:

this.colors = new Color[]{Color.getRandomColor(), Color.getRandomColor(), Color.getRandomColor(), Color.getRandomColor()};

this is fine, but imagine if you, or the professor, or your boss decided that they wanted to add the ability for the user to select how long the code is, this would not be possible with this code. Things like this change all the time in a production environment.

BCoons05 commented 4 years ago

Got most of this fixed. There is only one place where you would need to change the length of the code or the number of guesses. Plus there is a setter that would need to change. Not using it now, but it is there.

As far as refactoring, may want to split Code.getFeedback up. Should probably have separate methods for white pegs and black pegs. I will think about it and possibly update before we turn it in.