Question: how would i go about starting this project a program that will implement a console based Tic Tac Toe program that allows two users to

how would i go about starting this project a program that will implement a console based Tic Tac Toe program that allows two users to play the Tic

Tac Toe game and then prompts them to play again.

how to i create java class that isn't a java main class

1. Create Net-beans project called TicTacToe.

2. Now create java class called SafeInput. (This is not a java main class!) Put a copy

of your input methods from the previous labs in this class. For Tic Tac Toe you will

need:

public static int getRangedInt(Scanner console, String prompt, int low,

int high)

public static boolean getYNConfirm(Scanner console, String prompt)

3. Notes:

Make sure the methods are public so they can be used from outside of the file

they are in.

To use the methods within your java main file you reference them by the

filename:

int rowMove = SafeInput.getRangedInt(...);

int colMove = SafeInput.getRangedInt(...);

that is part one this is part two but i am unsure how i would even go about starting this lab.

java main class

1. Now create java main class called TicTacToe. This file will have all the main logic

for the game.

2. As described in class, you will create series of helper methods which are only useful

for the Tic Tac Toe game. (As opposed to the more general input methods that you

can reuse in many programs.) All these methods will be private static and as we

have seen they go within the class but not within main().

3. Although it is possible to pass the board[][] array to the helper methods, because they

are specific to the program we will declare the board array and any other variables

that the helper methods need as class level variables so they are directly accessible by

the helper methods. (Otherwise we would have to pass the array to each of the

functions which is messy.)

4. So, within the class, before main() declare the board array and the constants that

define it:

private static final int ROW = 3;

private static final int COL = 3;

private static String board [][] = new String[ROW][COL];

Be sure to consistently use ROW and COL not the magic number 3!

5. The helper methods will all go in the main file in the class and after the main()

method. You will have to develop your own methods but several that we have

already identified in class that you will need are:

private static void clearBoard() // sets all the board elements to a space

private static void display() // shows the Tic Tac Toe game

private static boolean isValidMove(int row, int col) // returns true if there is

a space at the given proposed move coordinates

private static boolean isWin(String player) // checks to see if there is a win

state on the current board for the specified player (X or O) This method in

turn calls three additional methods that break down the 3 kinds of wins that

are possible.

private static boolean isColWin(String player) // checks for a col win for

specified player

private static boolean isRowWin(String player) // checks for a row win for

the specified player

private static boolean isDiagnalWin(String player) // checks for a diagonal

win for the specified player

private static boolean isTie() // checks for a tie condition: all spaces on the

board are filled OR there is an X and an O in every win vector (i.e. all

possible 8 wins are blocked by having both and X and an O in them.)

6. Create pseudo code outline for the program using java comments and then code the

game.

Your program should:

Clear the board and set the player to X (since X always moves first)

get the coordinates for the move which should be 1 - 3 for the row and col

convert the player move to the array indices which are 0 - 2 by subtracting 1

loop until the converted player coordinates are a valid move

if appropriate check for a win or a tie (i.e. if it is possible for a win or a tie at

this point in the game, check for it.)

If there is a win or tie announce it and then prompt the players to play again.

Toggle the player (i.e. X becomes O, O becomes X)

this is the info they have given me to get started i don't understand most of could you help me make sense of how to start and what i need to do once that is done. - thank you

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!