Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Game {
- public static void main(String[]args){
- System.out.println("Welcome to Tyer's version of Tic Tac Toe.");
- System.out.println("You will be represented by the letter x.");
- Input();
- }
- public static void Input(){
- int score = 0;
- while(score < 7){
- System.out.print("What row would you like to go in: ");
- Scanner rowReader = new Scanner(System.in);//row reader
- int row = Integer.parseInt(rowReader.nextLine());
- System.out.print("What column would you like to go in: ");
- Scanner columnReader = new Scanner(System.in);//column reader
- int column = Integer.parseInt(columnReader.nextLine());
- String[][] cell = new String[3][3]; //initialize array
- for(int i = 0; i < cell.length; i++) {
- for(int j = 0; j < cell[i].length; j++) {
- cell[i][j] = " ";
- }
- }
- cell[row - 1][column - 1] = "X";
- String newLine = System.getProperty("line.separator");
- String board = (" " + cell[0][0] + " | " + cell[0][1] + " | " + cell[0][2] + " " + newLine +
- "--- --- ---" + newLine +
- " " + cell[1][0] + " | " + cell[1][1] + " | " + cell[1][2] + " " + newLine +
- "--- --- ---" + newLine +
- " " + cell[2][0] + " | " + cell[2][1] + " | " + cell[2][2] + " " + newLine);
- System.out.print(board);
- if (0 > row && row > 4 && 0 > column && column > 4){
- System.out.println("Sorry, your input value was invalid.");
- }
- score++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment