#Naming
Naming
Good naming is hard to get right, however it's worth taking the extra time because it makes your code a lot easier to follow. This applies to all elements of your program, albeit classes, methods, variables etc. GUI
is a very generic title for a class. What does it really represent, TicTacToeFrame
? You have a similar issue with some of your method names. Looking at your BoardButton
class, it's got three properties 'Sign', 'State' and 'Value'. On their own, they mean nothing to me. It's not really obvious which property might represent the 'X' or 'O'. It could be Value
, it could be Sign
. The process of coming up with a good name that encapsulates the responsibility can also help to flag up when an element is responsible for too much.
#main
main
In your main, you're doing things like setting the title and size on your GUI. This seems like it should really have been done in the GUI constructor. The GUI knows it's a TicTacToe game and is pretty tied to it, why does main have to tell it?
#Gui or Game
Gui or Game
You've implemented your entire game within your GUI class. This means that if you were to decide that you wanted to implement a console version / a web version, you'd be starting again. It's generally a good idea to try and break your application into different layers. A good starting split would be to separate the display logic (show the board, let users pick where they want to play, provide a means to feedback the winner), and the game logic (maintain internal board structure, expose methods to make a move, the actual logic that checks for a win).
You could then break these layers down further is required (it could make sense for example to have a scoreboard class to keep track of the running scores).
Having this separation has several benefits. It means that if you decide to plug in a different front end, you just have to worry about the front end. The mechanics of the game could be reused. It also means that if you want to, you can write untit tests for the logic to validate different scenarios.
#Winner validation
Winner validation
Your winner validation is straight forward and can be called at any time. This isn't bad, however you're probably making more checks than you need to. When you place an individual piece, you only actually need to check rows/columns/diagonals that the piece is on. If you place it in column 1, then it won't have impacted column 3.
#Naming
Good naming is hard to get right, however it's worth taking the extra time because it makes your code a lot easier to follow. This applies to all elements of your program, albeit classes, methods, variables etc. GUI
is a very generic title for a class. What does it really represent, TicTacToeFrame
? You have a similar issue with some of your method names. Looking at your BoardButton
class, it's got three properties 'Sign', 'State' and 'Value'. On their own, they mean nothing to me. It's not really obvious which property might represent the 'X' or 'O'. It could be Value
, it could be Sign
. The process of coming up with a good name that encapsulates the responsibility can also help to flag up when an element is responsible for too much.
#main
In your main, you're doing things like setting the title and size on your GUI. This seems like it should really have been done in the GUI constructor. The GUI knows it's a TicTacToe game and is pretty tied to it, why does main have to tell it?
#Gui or Game
You've implemented your entire game within your GUI class. This means that if you were to decide that you wanted to implement a console version / a web version, you'd be starting again. It's generally a good idea to try and break your application into different layers. A good starting split would be to separate the display logic (show the board, let users pick where they want to play, provide a means to feedback the winner), and the game logic (maintain internal board structure, expose methods to make a move, the actual logic that checks for a win).
You could then break these layers down further is required (it could make sense for example to have a scoreboard class to keep track of the running scores).
Having this separation has several benefits. It means that if you decide to plug in a different front end, you just have to worry about the front end. The mechanics of the game could be reused. It also means that if you want to, you can write untit tests for the logic to validate different scenarios.
#Winner validation
Your winner validation is straight forward and can be called at any time. This isn't bad, however you're probably making more checks than you need to. When you place an individual piece, you only actually need to check rows/columns/diagonals that the piece is on. If you place it in column 1, then it won't have impacted column 3.
Naming
Good naming is hard to get right, however it's worth taking the extra time because it makes your code a lot easier to follow. This applies to all elements of your program, albeit classes, methods, variables etc. GUI
is a very generic title for a class. What does it really represent, TicTacToeFrame
? You have a similar issue with some of your method names. Looking at your BoardButton
class, it's got three properties 'Sign', 'State' and 'Value'. On their own, they mean nothing to me. It's not really obvious which property might represent the 'X' or 'O'. It could be Value
, it could be Sign
. The process of coming up with a good name that encapsulates the responsibility can also help to flag up when an element is responsible for too much.
main
In your main, you're doing things like setting the title and size on your GUI. This seems like it should really have been done in the GUI constructor. The GUI knows it's a TicTacToe game and is pretty tied to it, why does main have to tell it?
Gui or Game
You've implemented your entire game within your GUI class. This means that if you were to decide that you wanted to implement a console version / a web version, you'd be starting again. It's generally a good idea to try and break your application into different layers. A good starting split would be to separate the display logic (show the board, let users pick where they want to play, provide a means to feedback the winner), and the game logic (maintain internal board structure, expose methods to make a move, the actual logic that checks for a win).
You could then break these layers down further is required (it could make sense for example to have a scoreboard class to keep track of the running scores).
Having this separation has several benefits. It means that if you decide to plug in a different front end, you just have to worry about the front end. The mechanics of the game could be reused. It also means that if you want to, you can write untit tests for the logic to validate different scenarios.
Winner validation
Your winner validation is straight forward and can be called at any time. This isn't bad, however you're probably making more checks than you need to. When you place an individual piece, you only actually need to check rows/columns/diagonals that the piece is on. If you place it in column 1, then it won't have impacted column 3.
#Naming
Good naming is hard to get right, however it's worth taking the extra time because it makes your code a lot easier to follow. This applies to all elements of your program, albeit classes, methods, variables etc. GUI
is a very generic title for a class. What does it really represent, TicTacToeFrame
? You have a similar issue with some of your method names. Looking at your BoardButton
class, it's got three properties 'Sign', 'State' and 'Value'. On their own, they mean nothing to me. It's not really obvious which property might represent the 'X' or 'O'. It could be Value
, it could be Sign
. The process of coming up with a good name that encapsulates the responsibility can also help to flag up when an element is responsible for too much.
#main
In your main, you're doing things like setting the title and size on your GUI. This seems like it should really have been done in the GUI constructor. The GUI knows it's a TicTacToe game and is pretty tied to it, why does main have to tell it?
#Gui or Game
You've implemented your entire game within your GUI class. This means that if you were to decide that you wanted to implement a console version / a web version, you'd be starting again. It's generally a good idea to try and break your application into different layers. A good starting split would be to separate the display logic (show the board, let users pick where they want to play, provide a means to feedback the winner), and the game logic (maintain internal board structure, expose methods to make a move, the actual logic that checks for a win).
You could then break these layers down further is required (it could make sense for example to have a scoreboard class to keep track of the running scores).
Having this separation has several benefits. It means that if you decide to plug in a different front end, you just have to worry about the front end. The mechanics of the game could be reused. It also means that if you want to, you can write untit tests for the logic to validate different scenarios.
#Winner validation
Your winner validation is straight forward and can be called at any time. This isn't bad, however you're probably making more checks than you need to. When you place an individual piece, you only actually need to check rows/columns/diagonals that the piece is on. If you place it in column 1, then it won't have impacted column 3.