hey everyone, I am doing a comp science lab (or re-doing) since it was due last week and me and my partners didn't finish it. the directions state:
For 1 point:
Modify this to give 3 rows of 3 squares, where the program tells which of the 9 squares is clicked and changes its color to "red".
For 2 poitns:
Add a variable that counts how many times a square is clicked. This should be a variable in class Board.java, that gets incremented each time method handleMouseClick() is called. Check this variable to see if it is even or odd. On even values, change the color of the square to "red", but on odd valued clicks, change the color of the square to "blue". For 3 points:
Check for a win! See if there are 3 of the same color in a row
so basically I have a board, and I am trying to increment it each time the user clicks on a box by one, however, I make a loop to increment it and it just loops all the way till the end of the loop. I am trying to make it where it only adds and prints the value as well as changing the color on each time the mouse is clicked. Can anyone please help? I am on step 2. Here is my Board code:
I would use an Square instead of 9 buttons. Then you can loop through it.
Also you can you divide the mouse position with the square with/height to get the column/row.
Finally I would use java.awt.Color instead of using Strings for the colors.
That will make your code easier to read and use, and reduce the error proneness.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.