Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String move (int square) {
- String whosTurn = getToMove();
- if(square == 1)
- {
- if(positions[0][0] == "X" || positions[0][0] == "O" )
- {
- throw new IllegalArgumentException();
- }
- positions[0][0] = whosTurn;
- }
- else if(square == 2 )
- {
- if(positions[0][1] == "X" || positions[0][1] == "O" )
- {
- throw new IllegalArgumentException();
- }
- positions[0][1] = whosTurn;
- }
- else if(square == 3)
- {
- if(positions[0][2] == "X" || positions[0][2] == "O" )
- {
- throw new IllegalArgumentException();
- }
- positions[0][2] = whosTurn;
- }
- else if(square == 4)
- {
- if(positions[1][0] == "X" || positions[1][0] == "O" )
- {
- throw new IllegalArgumentException();
- }
- positions[1][0] = whosTurn;
- }
- else if(square == 5)
- {
- if(positions[1][1] == "X" || positions[1][1] == "O" )
- {
- throw new IllegalArgumentException();
- }
- positions[1][1] = whosTurn;
- }
- else if(square == 6)
- {
- if(positions[1][2] == "X" || positions[1][2] == "O" )
- {
- throw new IllegalArgumentException();
- }
- positions[1][2] = whosTurn;
- }
- else if(square == 7)
- {
- if(positions[2][0] == "X" || positions[2][0] == "O" )
- {
- throw new IllegalArgumentException();
- }
- positions[2][0] = whosTurn;
- }
- else if(square == 8)
- {
- if(positions[2][1] == "X" || positions[2][1] == "O" )
- {
- throw new IllegalArgumentException();
- }
- positions[2][1] = whosTurn;
- }
- else if(square == 9)
- {
- if(positions[2][2] == "X" || positions[2][2] == "O" )
- {
- throw new IllegalArgumentException();
- }
- positions[2][2] = whosTurn;
- }
- if (isWon() == true || isDrawn() == true)
- {
- throw new IllegalArgumentException();
- }
- if (square < 1 || square > 9)
- {
- throw new IllegalArgumentException();
- }
- count++;
- // whosTurn = getToMove();
- isWon();
- isDrawn();
- return whosTurn;
- }
Add Comment
Please, Sign In to add comment