//Called when field was clicked public void FieldWasClicked(Field field) { //Checking if state isn't empty if (field.State != Field.StateOfField.EMPTY) { return; } //Setting up field state based on current player turn field.State = this.currentTurn == turn.firstPlayerTurn ? firstPlayerMarker : secondPlayerMarker; //Checking if someone won gameResoult currentGameReoult = someoneWon(); //End when somebody won or is dead-heat if (currentGameReoult != gameResoult.nobodyWon) { endGame(currentGameReoult); } if (currentTurn == turn.firstPlayerTurn) { this.currentTurn = turn.secondPlayerTurn; this.crossCurrentTurnRepresentation.enabled = false; this.circleCurrentTurnRepresentation.enabled = true; } else { this.currentTurn = turn.firstPlayerTurn; this.crossCurrentTurnRepresentation.enabled = true; this.circleCurrentTurnRepresentation.enabled = false; } }
public void FieldWasClicked(Field field) { if (field.State != Field.StateOfField.EMPTY) { return; } field.State = this.currentTurn == turn.firstPlayerTurn ? firstPlayerMarker : secondPlayerMarker; gameResoult currentGameReoult = someoneWon(); if (currentGameReoult != gameResoult.nobodyWon) { endGame(currentGameReoult); } if (currentTurn == turn.firstPlayerTurn) { this.currentTurn = turn.secondPlayerTurn; yourMoveObject.SetActive(false); ComputerMove(); } else { this.currentTurn = turn.firstPlayerTurn; yourMoveObject.SetActive(true); } }
private void endGame(gameResoult currentGameReoult) { Debug.Log("endGame"); if (currentGameReoult == gameResoult.somebodyWon) { Debug.Log("somebodyWon"); string winnerName = currentTurn == turn.firstPlayerTurn ? "First Player" : "Second Player"; StatementsManager.Instance.ShowStatement(winnerName + " won", "Restart Game", this.RestartGame); } else if (currentGameReoult == gameResoult.deadHeat) { Debug.Log("dead-heat"); StatementsManager.Instance.ShowStatement("Dead-heat! Nobody won!", "Restart Game", this.RestartGame); } }
private void endGame(gameResoult currentGameReoult) { Debug.Log("endGame"); if (currentGameReoult == gameResoult.somebodyWon) { Debug.Log("somebodyWon"); string winnerName = currentTurn == turn.firstPlayerTurn ? "First Player" : "Second Player"; MenuController.won++; } else if (currentGameReoult == gameResoult.deadHeat) { MenuController.lose++; Debug.Log("dead-heat"); } RestartGame(); }