Learning Java by creating a Tic-Tac-Toe game

Cole Crescas
3 min readDec 22, 2021

Starting out learning java can be a daunting task even if you have prior programming experience. Java is a fundamental language for Software Engineers and object oriented programming in general. This project will focus on a simple game of creating a GUI to display a Tic-Tac-Toe game built with a MVC architecture. Although I cannot share source code I will walk through the role of the model, view & controller and post an executable jar file.

The model is in charge of storing and manipulating the data. The model in this case would have two variables, an Enum type player and a board array of length 3x3. The models constructor will create an instance of the board and set the players turn to X. From there we will write the methods; move, getTurn, isGameOver, getWinner, getBoard, getMarkAt, validateRowCol and a toString. These methods will hold, manipulate and give data to both the controller and view. I create a read only interface of the model as well so that the view can take in a read only model as one of its fields to display data from the game to the user.

Next, the controller is the link between the model and the view. The controller will take inputs from the user & the view, handle them as valid or invalid and pass a command to the model to execute. The controller is slightly simpler and only has two methods; playGame and a private method to handle a cell click. The driver file will call the playGame method to start the view and carry out the actions of the game from there. The handle cell click method will…

--

--