diff options
| author | mo <mo.khan@gmail.com> | 2019-06-06 20:00:50 -0600 |
|---|---|---|
| committer | mo <mo.khan@gmail.com> | 2019-06-06 20:00:50 -0600 |
| commit | 4adea5e45bac36b4c43bf2596596184cad68791b (patch) | |
| tree | 75a085665beb76193c940e3b2f9d1ecbe79cf5df /src/Q2/RockPaperScissorsLizardSpock.java | |
| parent | 205bf6a1054b11860c76a416d9d3680f5b0c9516 (diff) | |
add documentation
Diffstat (limited to 'src/Q2/RockPaperScissorsLizardSpock.java')
| -rw-r--r-- | src/Q2/RockPaperScissorsLizardSpock.java | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/src/Q2/RockPaperScissorsLizardSpock.java b/src/Q2/RockPaperScissorsLizardSpock.java index 67954d3..d077f68 100644 --- a/src/Q2/RockPaperScissorsLizardSpock.java +++ b/src/Q2/RockPaperScissorsLizardSpock.java @@ -1,3 +1,11 @@ +/** + * Assignment 2, COMP268 Class: RockPaperScissorsLizardSpock.java + * + * @description Provide a class to play the game rock, paper, scissors, lizard spock. + * @author: mo khan Student ID: 3431709 + * @date Jun 6, 2019 + * @version 1.0 + */ package Q2; import java.util.*; @@ -5,26 +13,50 @@ import java.util.*; public class RockPaperScissorsLizardSpock { private int consecutiveWins = 0; private int lastWinner; - public static final int LIZARD = 4; - public static final int PAPER = 2; + public static final int PLAYER1 = 1; public static final int PLAYER2 = 2; + + public static final int LIZARD = 4; + public static final int PAPER = 2; public static final int ROCK = 1; public static final int SCISSORS = 3; public static final int SPOCK = 5; + /** + * Returns the # of consecutive wins for the current winner. + * + * @return the # of consecutive wins for the current winner. + */ public int getConsecutiveWins() { return this.consecutiveWins; } + /** + * Returns the id of the current winner. + * See PLAYER1 and PLAYER2 constants for the possible ids. + * + * @return the id of the current winner. + */ public int getLastWinner() { return this.lastWinner; } + /** + * Returns a random integer between 1 - 5 + * + * @return a random integer between 1 - 5 + */ public int random() { return new Random().nextInt(4) + 1; } + /** + * Plays the game until a winner has 4 consecutive wins. + * + * @param player1 id of player 1 + * @param player2 id of player 2 + */ public void play(int player1, int player2) { int player1Roll = 0; int player2Roll = 0; @@ -55,6 +87,12 @@ public class RockPaperScissorsLizardSpock { } } + /** + * Converts a integer to the equivalent name. + * + * @param i the integer to convert to a name. + * @return the name for the corresponding integer value. + */ public static String convert(int i) { switch (i) { case ROCK: @@ -123,6 +161,11 @@ public class RockPaperScissorsLizardSpock { else this.puts("The winner of this round is player %d!", winner); } + /** + * The entrypoint into the console application. + * + * @param args an argument vector that represents the command line arguments + */ public static void main(String[] args) { RockPaperScissorsLizardSpock game = new RockPaperScissorsLizardSpock(); game.play(RockPaperScissorsLizardSpock.PLAYER1, RockPaperScissorsLizardSpock.PLAYER2); |
