Android Open Source - rock-paper-scissors Result Info






From Project

Back to project page rock-paper-scissors.

License

The source code is released under:

MIT License

If you think the Android project rock-paper-scissors listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package au.com.codeka.rps.game;
/*w  ww.  j  a va2s. com*/
/**
 * Data object for holding the result of a single match.
 */
public class ResultInfo {
    private final String matchId;
    private final Result result;
    private final String playerChoice;
    private final String otherChoice;

    public ResultInfo(String matchId, String playerChoice, String otherChoice) {
        this.matchId = matchId;
        this.playerChoice = playerChoice;
        this.otherChoice = otherChoice;

        if (playerChoice.equals(otherChoice)) {
            result = Result.Draw;
        } else if (playerChoice.equals("rock")) {
            result = otherChoice.equals("scissors") ? Result.Win : Result.Loss;
        } else if (playerChoice.equals("scissors")) {
            result = otherChoice.equals("paper") ? Result.Win : Result.Loss;
        } else { // paper
            result = otherChoice.equals("rock") ? Result.Win : Result.Loss;
        }
    }

    public Result getResult() {
        return result;
    }

    public String getPlayerChoice() {
        return playerChoice;
    }

    public String getOtherChoice() {
        return otherChoice;
    }

    public enum Result {
        Win,
        Loss,
        Draw
    }
}




Java Source Code List

au.com.codeka.rps.ApplicationTest.java
au.com.codeka.rps.DebugLog.java
au.com.codeka.rps.FindingOpponentFragment.java
au.com.codeka.rps.GameActivity.java
au.com.codeka.rps.GameFragment.java
au.com.codeka.rps.MessageListenerService.java
au.com.codeka.rps.NotificationUpdateService.java
au.com.codeka.rps.PhoneConnection.java
au.com.codeka.rps.ResultFragment.java
au.com.codeka.rps.SplashActivity.java
au.com.codeka.rps.WatchConnection.java
au.com.codeka.rps.game.AwaitingPlayerChoiceState.java
au.com.codeka.rps.game.AwaitingPlayerChoiceState.java
au.com.codeka.rps.game.AwaitingResultState.java
au.com.codeka.rps.game.AwaitingResultState.java
au.com.codeka.rps.game.DisplayingResultState.java
au.com.codeka.rps.game.DisplayingResultState.java
au.com.codeka.rps.game.FindingOpponentState.java
au.com.codeka.rps.game.FindingOpponentState.java
au.com.codeka.rps.game.GameRunningState.java
au.com.codeka.rps.game.GameRunningState.java
au.com.codeka.rps.game.MatchInfo.java
au.com.codeka.rps.game.ResultInfo.java
au.com.codeka.rps.game.StateManager.java
au.com.codeka.rps.game.StateManager.java
au.com.codeka.rps.game.State.java
au.com.codeka.rps.game.State.java