Skip to content
Snippets Groups Projects

Implementation of Assignment 1.0

Merged jim20 requested to merge assignment-1.0 into main

Merge request reports

Merged by jim20jim20 3 years ago (Sep 14, 2021 3:11pm UTC)

Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
src/Card.java 0 → 100644
27
28
29 public String getColor() {
30 return this.color;
31 }
32
33 public String getValue() {
34 return this.value;
35 }
36
37 /*/
38 * Checks if the card being played is valid.
39 */
40
41 public boolean validMove(Card topCard, GameState gamestate) {
42 if (this.color == topCard.color || this.value == topCard.value || this.color.toString() == "Wild" || this.color.toString() == "WildDrawFour" || this.color.toString() == gamestate.getCurrentColor()) {
  • src/Card.java 0 → 100644
    1 /*
    2 * The Card class contains the framework of how UNO cards are stored as String combinations and includes getters and setters to access attributes of a specific card
    3 */
    4 public abstract class Card {
    5
    6 protected GameState gamestate;
  • ziyue5
    ziyue5 @ziyue5 started a thread on the diff
  • src/DrawTwo.java 0 → 100644
    1 public class DrawTwo extends Card {
    2
    3 public DrawTwo(String color, String value) {
    4 super(color, value);
    5 }
    • Comment on lines +3 to +5
      Developer

      Since the color of DrawTwo class is fixed, so maybe it can be modified like super("DrawTwo", value).

    • Please register or sign in to reply
  • ziyue5
    ziyue5 @ziyue5 started a thread on the diff
  • src/DrawTwo.java 0 → 100644
    1 public class DrawTwo extends Card {
    2
    3 public DrawTwo(String color, String value) {
    4 super(color, value);
    5 }
    6
    7 /*
    8 * Updates gamestate instance variables
    9 */
    10 public void playCard(GameState gamestate, Card card) {
    11 if (validMove(card, gamestate)) {
    12 gamestate.addToDiscardPile(card);
    13 gamestate.players[gamestate.currentPlayerIndex].removeFromHand(card);
  • src/Card.java 0 → 100644
    1 /*
    2 * The Card class contains the framework of how UNO cards are stored as String combinations and includes getters and setters to access attributes of a specific card
    3 */
    4 public abstract class Card {
    5
    6 protected GameState gamestate;
  • 6 */
    7 public class GameState {
    8
    9 static boolean gameEnd;
    10 boolean drawStackedCards;
    11 int numPlayers = 0;
    12 int numStackedCards = 0;
    13 int currentPlayerIndex;
    14 Player[] players;
    15 boolean clockwise;
    16 static Player currentPlayer;
    17 static String currentColor;
    18 public ArrayList<Card> initialDeck = new ArrayList<Card> ();
    19 public ArrayList<Card> discardPile = new ArrayList<Card> ();
    20 public ArrayList<Card> playingDeck = new ArrayList<Card> ();
    21 public int playDeckIndex = 107;
  • ziyue5
    ziyue5 @ziyue5 started a thread on the diff
  • 100 initialDeck.add(new Wild(colors[4], values[13]));
    101 initialDeck.add(new WildDrawFour(colors[4], values[14]));
    102 //cardCounter+=2;
    103 }
    104 }
    105
    106 /*
    107 * shuffle algorithm from stack overflow : https://stackoverflow.com/questions/39557701/shuffle-a-deck-of-cards-in-java
    108 */
    109 public void shuffleDeck() {
    110 for (int i = 0; i < initialDeck.size(); i++) {
    111 int index = (int) (Math.random() * initialDeck.size());
    112 initialDeck.add(initialDeck.remove(index));
    113 }
    114 playingDeck = initialDeck;
    115 }
  • ziyue5
    ziyue5 @ziyue5 started a thread on the diff
  • 187 */
    188
    189 public void setNextPlayer() {
    190 if (clockwise) {
    191 currentPlayerIndex = (currentPlayerIndex + 1) % numPlayers;
    192 currentPlayer = players[currentPlayerIndex];
    193 } else {
    194 currentPlayerIndex = (currentPlayerIndex - 1) % numPlayers + numPlayers;
    195 currentPlayer = players[currentPlayerIndex];
    196 }
    197 }
    198
    199 /*
    200 * helper function to add number of stacked cards to a player's hand.
    201 */
    202 public void checkStackedCards() {
  • ziyue5
    ziyue5 @ziyue5 started a thread on the diff
  • 187 */
    188
    189 public void setNextPlayer() {
    190 if (clockwise) {
    191 currentPlayerIndex = (currentPlayerIndex + 1) % numPlayers;
    192 currentPlayer = players[currentPlayerIndex];
    193 } else {
    194 currentPlayerIndex = (currentPlayerIndex - 1) % numPlayers + numPlayers;
    195 currentPlayer = players[currentPlayerIndex];
    196 }
    197 }
    198
    199 /*
    200 * helper function to add number of stacked cards to a player's hand.
    201 */
    202 public void checkStackedCards() {
    • Developer

      Maybe we can use some static variables here to track the card number which is stacked by drawTwo or wildDrawFour card.

    • Static variables are only for information that should be shared across all instances of a class (usually only constants or sometimes a counter to count the number of instances/index them).

    • Please register or sign in to reply
  • ziyue5
    ziyue5 @ziyue5 started a thread on the diff
  • 256 drawTwo.playCard(this, card);
    257 } else if (card.getValue().toString() == "Skip") {
    258 Skip skip = (Skip) card;
    259 skip.playCard(this, card);
    260 } else if (card.getValue().toString() == "Reverse") {
    261 Reverse reverse = (Reverse) card;
    262 reverse.playCard(this, card);
    263 } else if (card.getValue().toString() == "Wild") {
    264 Wild wild = (Wild) card;
    265 wild.playCard(this, card);
    266 } else {
    267 Wild wild = (Wild) card;
    268 wild.playCard(this, card);
    269 }
    270 }
    271
    • Comment on lines +250 to +271
      Developer

      Maybe we can separate this statement into several methods into the different card subclasses to act as the specific playCard() method of this kind of card.

    • Please register or sign in to reply
  • shivenk2
    shivenk2 @shivenk2 started a thread on the diff
  • src/Card.java 0 → 100644
    1 /*
    2 * The Card class contains the framework of how UNO cards are stored as String combinations and includes getters and setters to access attributes of a specific card
    3 */
    4 public abstract class Card {
    5
    6 protected GameState gamestate;
    7 String color;
    8 String value;
    9
    10 public Card(String color, String value) {
    11 this.color = color;
    12 this.value = value;
    13 }
    14
    15
    16 public static String[] allColors = {"Red", "Blue", "Green", "Yellow", "Wild"};
  • shivenk2
    shivenk2 @shivenk2 started a thread on the diff
  • src/Card.java 0 → 100644
    1 /*
    2 * The Card class contains the framework of how UNO cards are stored as String combinations and includes getters and setters to access attributes of a specific card
    3 */
    4 public abstract class Card {
    5
    6 protected GameState gamestate;
    7 String color;
    8 String value;
  • 1 import java.util.ArrayList;
    2 import java.util.Scanner;
    3
    4 /*
    5 * The GameState Class is used to generate an Instance of the Card Game 'UNO' by utilizing the Player, Card, and Deck Classes.
    6 */
    7 public class GameState {
    8
    9 static boolean gameEnd;
    10 boolean drawStackedCards;
    11 int numPlayers = 0;
    12 int numStackedCards = 0;
    13 int currentPlayerIndex;
    14 Player[] players;
    15 boolean clockwise;
    16 static Player currentPlayer;
  • Developer

    Peer Review Report

    1-I choose Extensibility. The code attempts to address Extensibility. The author used an abstract Card class to ensure all shared functionalities of the card were included in this superclass.

    2-I choose Open Closed Principle. The code attempts to address Open Closed Principle. The author made use of the inheritance mechanism to make sure all new and special functions were in the corresponding subclasses.

    3-Not applicable

  • jim20 added 1 commit

    added 1 commit

    • 0f7a980d - addressed some peer comments

    Compare with previous version

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading