Implementation of Assignment 1.0
Merge request reports
Activity
added 3 commits
assigned to @ziyue5
- 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()) { changed this line in version 6 of 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; changed this line in version 6 of the diff
- src/DrawTwo.java 0 → 100644
- 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; Maybe the game state shouldn't be stored in some specific card. Maybe using some protected static status variable in GameState class will make the code better.
Edited by ziyue5changed this line in version 6 of the diff
- src/GameState.java 0 → 100644
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; changed this line in version 6 of the diff
- src/GameState.java 0 → 100644
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 } - src/GameState.java 0 → 100644
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() { - src/GameState.java 0 → 100644
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() { - src/GameState.java 0 → 100644
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 - 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"}; - 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; - src/GameState.java 0 → 100644
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; changed this line in version 7 of the diff
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
Please register or sign in to reply