This project will require you to create a 3 by 3 Tic-Tac-Toe game using the given starter code.The purpose of this project is to demonstrate a working knowledge of Object Oriented Programming.This...




This project will require you to create a 3 by 3 Tic-Tac-Toe game using the given starter code.




The purpose of this project is to demonstrate a working knowledge of Object Oriented Programming.







This project is designed to be a take-home part of exam #2. You are not to discuss or share code with anyone, including CSMC or tutors. You may use the book, but no other outside materials.









TicTacToe Game




In the starter code, you are given an interface TicTacToe, and interface IBoard and an abstract class APlayer with all the needed methods. Your task is to implement the TTTGame using the provided starter code. Put all your new code in the same package alongside the starter code. You are also given a class DriverMain with a main method that will allow you to test your game. The starter code only shows the necessary public methods. You may add any additional private/protected/public members you deem necessary.




A single move consists of two numbers, specifying the row and column of the intended move position. Board positions for these moves are numbered from 0. For example, to mark X in the upper left cell, the user would enter "0 0" at the first prompt. To mark O in the upper right cell on the second move, the user would enter "0 2". To quit a game in progress, the user can enter q or Q at any time.




The game state is the output of the TTTGame’s toString() method, followed by a carriage return (\n). The move prompt is







"Enter a move for " + game.getTurn().toString() + ":\n"







(where game is an instance of your TTTGame).




You have two APlayer type, "Human Player" and "ComputerPlayer". The "ComputerPlayer" select move using random number generator.







int r = (int) (Math.random() * range); which range is 3







You also have a Box class. You will have to implement your 3 by 3 Board class using the IBoard interface. Your Board class contains an array of 9 boxes.







boxes = new Box[boardColSize * boardRowSize];







If a non-integer value is entered, it should be rejected with an error message. If an invalid move is entered, namely, two valid integers, but the proposed move was deemed invalid by the game, the program should give an error message. The message text is up to you, but should end with a carriage return.




At the end of the game, the program should output, in order on separate lines:




A final game state







"Game is over!" followed by "X wins." or "O wins." or "Tie game." depending on the outcome







If the user quits, the controller should output







"Game quit! Ending game state:\n" + game.toString() + "\n"







and end the playGame() method.








Testing




We have supplied you with some basic JUnit tests as part of the starter code. Use these to verify that your implementation is correct. Write additional tests of your own.




Notes to Keep in Mind




You will likely need a while() loop; be aware that you can use the break statement to break out of a loop prematurely (before the loop condition is false). Avoid duplicating code as much as possible. Consider using non-public methods as means of creating reusable pieces of functionality. Be sure to use access modifiers, private and public, as well as final, appropriately. Include comments for your classes and constructors as appropriate.Your grade will be determined by your code style (70%) and correctness (30%).








Note: Indentations use 3 spaces.


Apr 10, 2023
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here