0

Hey need to create tic tac toe but which reads from tester file - after the right direction to go from here, on how to implement it

import java.util.*;

public class TicTacToe
{
    public TicTacToe()
    {
            Scanner input = new Scanner(System.in);
                                  
            char[][] board = new char[3][3];             // Sets up game board
            final int totalturns = 9;                    // Initiaqlizes total amount of turns
            
            newBoard(board);
            print(board);
    }
    
    public static void print (String args[]) 
    {

    }
    
    private static void newBoard(char[][] board)
    {
        for (int row = 0; row < board.length; row++)
        {
            for (int col = 0; col < board[0].length; col++)
            {
                board[row][col] = '-';
            }
        }
    }
        
    private static void print(char[][] board)
    {
        for (int row = 0; row < board.length; row++)
        {
            for (int col = 0; col < board[0].length; col++)
            {
                System.out.print(board[row][col]);
            }
        }
    }      
   }
2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by DarkLightning7
0

I am not shure what you mean but here is how you read from a file

first creat a scanner for the file

Scanner [B]input[/B] = new Scanner(new File([B]Name of file here[/B]));

then read from the file

[B]input.next();[/B]

you are going to want to put the "read from file code" inside an if statement that checks wether or not there is anything left to read like this

if(input.hasNext()){

}

Edited by DarkLightning7: n/a

0

in bluejay you have a tester file, so in there is a an array to input into the gameboard

so you would have the moves already set up and say with each new row of reading i would have to implemeent that it it check if there a winner, whos go etc..


but for now just need to know how to implement the moves part

0

so you want to know how to write to your array and tell the players whos turn it is as well as print the result?

I still don't know what you mean by a tester file you will have to describe it a little. (:

Edited by DarkLightning7: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.