The purpose of this lab two-fold. First, it will give students practice with 2D arrays. At least as importantly, though, no starter code has been provided, so students will need to start from scratch and think a little bit more about how to organize their code from the ground up. Therefore, this lab will worth 4 points instead of 2, and it will span 2 weeks.
Students will write a program that simulates a game of Tic-Tac-Toe. The Tic-Tac-Toe game is played on a 3x3 grid with two players who take turns. The first player marks moves with an X, and the second player marks moves with an O. The first player to form a horizontal, vertical, or diagonal sequence of three marks wins the game. Your program should do the following in order:
- Draw the game board
- As the user for the (zero-indexed) coordinates of the next mark, and record the appropriate mark at those coordinates
- Change the players after every successful move
- End the game and declare the winner once that happens, or declare that there has been a draw (i.e. the board has filled up with no winner)
Slight variations on the input/output prompts are fine, but it should be clear to the user where they are in the game and what they need to input next.
Welcome to Tic-Tac-Toe!
- - - - - - - - -
|Player X Give Coordinates: 2, 2|
- - - - - - - - X
|Player O Give Coordinates: 1,1|
- - - - O - - - X
This back and forth should continue until someone wins or until there is a tie.
You should have at least the five methods below in your code. You may create other methods to help you, but you need to have at least these
- Create and initialize the board. You should definitely be returning a 2D array of some sort here.
- Make the current user's move
- Determine if there is a winner
- Determine if there is a tie
- Put everything together and play the game (this could possibly happen in a main, but for style, try not to have a sprawling main)
Grading (Out of 4)
Points will be awarded in the following categories
- Board generation/printing (1 point)
- Play Loop (1 Points)
- Win/Tie Detection (1 Point)
- Style/Code Organization (1 Point)
- Extra Credit (+1 Point): Changeable Board size; that is, prompt the user at the beginning for an odd number N and use this to generate an NxN grid on which to play. For instance, you should be able to play on a 7x7 grid.
What To Submit
You must submit a .zip file of your NetBeans project to Canvas. Click here to review instructions for how to do this.