Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

you will complete Javadoc + contracts for GameBoard. GameBoard.java This class will represent the game board itself. All attributes of the class must be private

you will complete Javadoc + contracts for GameBoard.

GameBoard.java This class will represent the game board itself. All attributes of the class must be private unless they are static AND final. Your game board should be a 2-dimensional array of characters where position [0][0] would be the bottom left of the board and [8][6] would be the top right of the board. Each position will have a single blank space character (' ') until a player plays on that position. At that point, the character will change to either X or O to represent that player. A constructor with no parameters should be included. This class cannot interact with the users by asking for input or printing output to the screen. The following methods must be publicly available. Also include a constructor with no parameters. They must have the exact names, parameters, and return types listed. I have provided contracts for some, but not all of the methods. You must include the provided contracts as well as write contracts for the remaining methods. You must provide Javadoc comments for each method. public boolean checkIfFree(int c) { //returns true if the column can accept another token; false otherwise. } public void placeToken(char p, int c) { //places the character p in column c. The token will be placed in the lowest available row in column c. }

public boolean checkForWin(int c) { //this function will check to see if the last token placed in column c resulted in the player winning the game. If so it will return true, otherwise false. //Note: this is not checking the entire board for a win, it is just checking if the last token placed results in a win. //You may call other methods to complete this method } public boolean checkTie() { //this function will check to see if the game has resulted in a tie. A game is tied if there are no free board positions remaining. You do not need to check for any potential wins because we can assume that the players were checking for win conditions as they played the game. It will return true if the game is tied and false otherwise. } public boolean checkHorizWin(BoardPosition pos, char p) { //checks to see if the last token placed (which was placed in position pos by player p) resulted in 5 in a row horizontally. Returns true if it does, otherwise false } public boolean checkVertWin(BoardPosition pos, char p) { //checks to see if the last token placed (which was placed in position pos by player p) resulted in 5 in a row vertically. Returns true if it does, otherwise false } public boolean checkDiagWin(BoardPosition pos, char p) { //checks to see if the last token placed (which was placed in position pos by player p) resulted in 5 in a row diagonally. Returns true if it does, otherwise false //Note: there are two diagonals to check } public char whatsAtPos(BoardPosition pos) { //returns what is in the GameBoard at position pos //If no marker is there, it returns a blank space char. }

public boolean isPlayerAtPos(BoardPosition pos, char player) { //returns true if the player is at pos; otherwise, it returns false //Note: this method will be implemented very similarly to whatsAtPos, but it's asking a different question. We only know they will be similar because we know GameBoard will contain a 2D array. If the data structure were to change in the future, these two methods could be radically different. } Additionally, you must override the toString() method inherited from the Object class. This will return one string that shows the entire game board. You will then be able to call it in your GameScreen.java file to print it to the screen. It should be formatted as follows: |0|1|2|3|4|5|6| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |X| | | | | |X| |O| | This way, it will be easy to see the board's layout. Again, this class does not print to the screen; it just produces one string that contains the entire board that will be easy to print. You should not add any other methods to this class. For this part of the assignment, you will need to include the following in your project report: - A UML class diagram for GameBoard - A UML activity diagram for each method in GameBoard Additionally, you will submit a code file for GameBoard called GameBoard.java. This code file will just be an outline for the eventual code file. It should include the signature, Javadoc comments, and contracts for all methods and invariants for the class, but you do not need to write the code for each method yet. Because of this, your code will not compile yet.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students also viewed these Databases questions

Question

Q.No.1 Explain Large scale map ? Q.No.2 Explain small scale map ?

Answered: 1 week ago