public bool canAdd(int x, int y, Piece P) { if ((GAME_ENDED) || (WAITING_PLAYERS)) { return(false); } if (BOARD.getPiece(x, y).getClass2() != NullPiece.getClass()) { return(false); } int cont_O = BOARD.contPieces(PLAYER2); int cont_X = BOARD.contPieces(PLAYER1); if (P.getPlayer() == PLAYER2) { if (cont_O == cont_X - 1) { ACTUAL_PLAYER = PLAYER1; return(true); } } else if ((P.getPlayer() == PLAYER1)) { if (cont_O == cont_X) { ACTUAL_PLAYER = PLAYER2; return(true); } } return(false); }
public bool won(int Player) { int cont_X = BOARD.contPieces(PLAYER1); int cont_O = BOARD.contPieces(PLAYER2); if (PLAYER1 == Player && cont_O == 0 && cont_X > 0) { return(true); } else if (PLAYER2 == Player && cont_X == 0 && cont_O > 0) { return(true); } if (PLAYER1 == Player && ACTUAL_PLAYER == PLAYER2) { if (cannotMove(PLAYER2)) { WINNER = PLAYER1; return(true); } } if (PLAYER2 == Player && ACTUAL_PLAYER == PLAYER1) { if (cannotMove(PLAYER1)) { WINNER = PLAYER2; return(true); } } return(false); }
public override bool add(int x, int y, int Player) { TictactoePiece P = null; if (Player == PLAYER1) { P = new TictactoePiece("+", PLAYER1); } else if (Player == PLAYER2) { P = new TictactoePiece("-", PLAYER2); } else { Console.WriteLine("Invalid player: '" + Player + "'. Players: '" + PLAYER1 + "' and '" + PLAYER2 + "'."); return(false); } if (canAdd(x, y, (Piece)P)) { if (BOARD.addPiece(x, y, (Piece)P)) { } else { Console.WriteLine("BLASFEMIA!!!"); } if ((BOARD.contPieces(new TictactoePiece("", -1)) == 9) && WINNER == -1) { DRAWN_GAME = true; GAME_ENDED = true; LAST_MESSAGE = "DRAWN GAME"; } if (gameEnded()) { if (DRAWN_GAME) { Console.WriteLine("End game. " + LAST_MESSAGE); } else { Console.WriteLine("End game. Winner: " + WINNER); } } CONT_ID++; return(true); } return(false); }
public bool won(int Player) { int cont_X = BOARD.contPieces(PLAYER1); int cont_O = BOARD.contPieces(PLAYER2); if (PLAYER1 == Player && cont_O == 0 && cont_X > 0) { return(true); } else if (PLAYER2 == Player && cont_X == 0 && cont_O > 0) { return(true); } return(false); }
public override bool add(int x, int y, int Player) { NovoJogoPiece P = null; if (Player == PLAYER1) { P = new NovoJogoPiece("X", PLAYER1, NovoJogoPiece.PECA_X); } else if (Player == PLAYER2) { P = new NovoJogoPiece("O", PLAYER2, NovoJogoPiece.PECA_O); } else { Console.WriteLine("O Jogador que esta tentando jogar nao pertence ao jogo: '" + Player + "'. Jogadores no jogo: '" + PLAYER1 + "' e '" + PLAYER2 + "'."); return(false); } if (canAdd(x, y, (Piece)P)) { if (!BOARD.addPiece(x, y, (Piece)P)) { } else { Console.WriteLine("Nao foi possivel adicionar a peca. Problema desconhecido."); } if ((BOARD.contPieces(new NovoJogoPiece("", -1, "")) == 9) && WINNER == -1) { DRAWN_GAME = true; GAME_ENDED = true; LAST_MESSAGE = "VELHA"; } if (gameEnded()) { if (DRAWN_GAME) { Console.WriteLine("Jogo encerrado. " + LAST_MESSAGE); } else { Console.WriteLine("Jogo encerrado. Vencedor: " + WINNER); } } CONT_ID++; return(true); } return(false); }