Hello! I made a game “Rock,Paper,Scissors” and I’m trying to figure out how to replace these if statements in my class. I’m not interested in replacing these with switch. Any ideas?
Everything works properly. I just want to refactor my code
private void CheckForWin()
{
if (_playerOneChoice == _playerTwoChoice)
{
StartCoroutine(ShowResultTextCo(_drawText, "DRAW"));
ActivateEndRoundButtons();
}
if (_playerOneChoice == GameChoices.ROCK && _playerTwoChoice == GameChoices.SCISSORS)
{
EndRoundUpdate(ref _playerOneScore, _playerOneScoreText, "PLAYER 1 WON");
}
if (_playerOneChoice == GameChoices.SCISSORS && _playerTwoChoice == GameChoices.PAPER)
{
EndRoundUpdate(ref _playerOneScore, _playerOneScoreText, "PLAYER 1 WON");
}
if (_playerOneChoice == GameChoices.PAPER && _playerTwoChoice == GameChoices.ROCK)
{
EndRoundUpdate(ref _playerOneScore, _playerOneScoreText, "PLAYER 1 WON");
}
if (_playerOneChoice == GameChoices.ROCK && _playerTwoChoice == GameChoices.PAPER)
{
EndRoundUpdate(ref _playerTwoScore, _playerTwoScoreText, "PLAYER 2 WON");
}
if (_playerOneChoice == GameChoices.PAPER && _playerTwoChoice == GameChoices.SCISSORS)
{
EndRoundUpdate(ref _playerTwoScore, _playerTwoScoreText, "PLAYER 2 WON");
}
if (_playerOneChoice == GameChoices.SCISSORS && _playerTwoChoice == GameChoices.ROCK)
{
EndRoundUpdate(ref _playerTwoScore, _playerTwoScoreText, "PLAYER 2 WON");
}
}