package tictactoe;

import exception.InputInvalidException;
import exception.PlacementFailedException;
import game.AbstractGame;
import game.Coordinate;

public class TicTacToe extends AbstractGame {

	private final Team[] team;
	private int currentIndex;

	public TicTacToe() {
		super(new TicTacToeBoard());

		team = new Team[2];
		team[0] = new Team(Team.TeamType.X);
		team[1] = new Team(Team.TeamType.O);

		currentIndex = 0;

	}

	@Override
	public void next() {
		Coordinate input;
		
		try {
			input = getConsole().getSquareCoordinates(this);
		} catch (InputInvalidException e) {
			errorMessage(e.toString());
			return;
		}
		System.out.println();

		try {
			getBoard().attemptPlace(team[currentIndex].getPieceType(), input);
		} catch (PlacementFailedException e) {
			errorMessage(e.toString());
			return;
		}

		printBoard();
		currentIndex = currentIndex == 0 ? 1 : 0;

	}

	@Override
	public void check() {
		char team = getBoard().gameEnd();

		if (team != ' ') {
			if (team == '_') {
				System.out.println("It's a tie!");
			} else {
				System.out.println(team + " won!");
			}

			endGame();
		}
	}
}
@@ -205,67 +205,347 @@
  %7B%0D%0A
-%0D%0A%09private final Team%5B%5D team;%0D%0A%09private int currentIndex;%0D%0A
+%09/** This Team array contains both teams involved in Tic-Tac-Toe */%0D%0A%09private final Team%5B%5D team;%0D%0A%09/** This integer keeps track of the current team's turn. */%0D%0A%09private int currentIndex;%0D%0A%0D%0A%09/**%0D%0A%09 * This constructor passes the Board of this game to the super class%0D%0A%09 * constructor and defines the instance variables of this object.%0D%0A%09 */
 %0D%0A%09p
@@ -725,32 +725,172 @@
 x = 0;%0D%0A%0D%0A%09%7D%0D%0A%0D%0A
+%09/**%0D%0A%09 * This method represents a single placement of a piece by one of the%0D%0A%09 * players in the game. Then, the current team swaps.%0D%0A%09 */%0D%0A
 %09@Override%0D%0A%09pub
@@ -929,18 +929,16 @@
 input;%0D%0A
-%09%09
 %0D%0A%09%09try 
@@ -1351,16 +1351,174 @@
 %0D%0A%09%7D%0D%0A%0D%0A
+%09/**%0D%0A%09 * This method checks if the game should end. This method asks the board if%0D%0A%09 * the game should end and gives a message if the game has ended.%0D%0A%09 */%0D%0A
 %09@Overri

update comments