From f8e7e603cd090b7f8f211f0c7d5f2017445e0918 Mon Sep 17 00:00:00 2001 From: Kevin Viglucci Date: Sat, 14 Nov 2020 18:29:01 -0600 Subject: [PATCH] Add a skeleton implementation of the card game. --- .gitignore | 54 +++++++++++++++++++ .idea/.gitignore | 2 + .idea/compiler.xml | 16 ++++++ .idea/description.html | 1 + .idea/encodings.xml | 8 +++ .idea/misc.xml | 16 ++++++ .idea/modules.xml | 8 +++ .idea/project-template.xml | 3 ++ .idea/vcs.xml | 6 +++ LICENSE | 21 ++++++++ README.md | 31 +++++++++++ java-card-game.iml | 39 ++++++++++++++ pom.xml | 49 +++++++++++++++++ src/main/java/com/example/main/Main.java | 50 +++++++++++++++++ .../java/com/example/main/model/Card.java | 40 ++++++++++++++ .../java/com/example/main/model/Dealer.java | 34 ++++++++++++ .../java/com/example/main/model/Deck.java | 54 +++++++++++++++++++ .../java/com/example/main/model/Player.java | 46 ++++++++++++++++ .../java/com/example/main/model/CardTest.java | 5 ++ .../com/example/main/model/DealerTest.java | 5 ++ .../java/com/example/main/model/DeckTest.java | 5 ++ .../com/example/main/model/PlayerTest.java | 5 ++ 22 files changed, 498 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/description.html create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/project-template.xml create mode 100644 .idea/vcs.xml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 java-card-game.iml create mode 100644 pom.xml create mode 100644 src/main/java/com/example/main/Main.java create mode 100644 src/main/java/com/example/main/model/Card.java create mode 100644 src/main/java/com/example/main/model/Dealer.java create mode 100644 src/main/java/com/example/main/model/Deck.java create mode 100644 src/main/java/com/example/main/model/Player.java create mode 100644 src/test/java/com/example/main/model/CardTest.java create mode 100644 src/test/java/com/example/main/model/DealerTest.java create mode 100644 src/test/java/com/example/main/model/DeckTest.java create mode 100644 src/test/java/com/example/main/model/PlayerTest.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f58ad3d --- /dev/null +++ b/.gitignore @@ -0,0 +1,54 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +target + +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Maven +.idea/**/jarRepositories.xml \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..a023490 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/description.html b/.idea/description.html new file mode 100644 index 0000000..db5f129 --- /dev/null +++ b/.idea/description.html @@ -0,0 +1 @@ +Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..611e7fe --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b649543 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1393576 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/project-template.xml b/.idea/project-template.xml new file mode 100644 index 0000000..1f08b88 --- /dev/null +++ b/.idea/project-template.xml @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8a67587 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Kevin Viglucci + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..0a33100 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# java-card-game + +A designer gave the following design for a card game to a developer: + +> Implement the first phase of a card game in which a dealer shuffles a deck of cards and then deals a hand of 5 cards to each player. +> +> The running program should produce the below output: +> +> ``` +> Nick has the below cards in their hand: +> Ten of Diamonds +> Four of Clubs +> Queen of Hearts +> Three of Diamonds +> Nine of Diamonds +> Tommy has the below cards in their hand: +> King of Hearts +> Six of Diamonds +> Ace of Clubs +> Queen of Spades +> Two of Hearts +> ``` +> +> Additionally, all tests should pass. + +The developer has opened a pull request with their implementation of the card game. Your task is to review their pull request. + +## Branches + +- The `main` branch has the skeleton implementation of the card game. +- The `shuffle-and-deal` branch has the developer's implementation of the above design. diff --git a/java-card-game.iml b/java-card-game.iml new file mode 100644 index 0000000..6c60e5f --- /dev/null +++ b/java-card-game.iml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..828793b --- /dev/null +++ b/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + + groupId + java-card-game + 1.0.0-SNAPSHOT + jar + + + UTF-8 + + + + + org.junit.jupiter + junit-jupiter + 5.7.1 + test + + + org.assertj + assertj-core + 3.19.0 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + 11 + 11 + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M5 + + + + \ No newline at end of file diff --git a/src/main/java/com/example/main/Main.java b/src/main/java/com/example/main/Main.java new file mode 100644 index 0000000..89d99b0 --- /dev/null +++ b/src/main/java/com/example/main/Main.java @@ -0,0 +1,50 @@ +package com.example.main; + +import com.example.main.model.Card; +import com.example.main.model.Dealer; +import com.example.main.model.Deck; +import com.example.main.model.Player; + +public class Main { + + /** + * Produces the below output: + * + * Nick has the below cards in their hand: + * Ten of Diamonds + * Four of Clubs + * Queen of Hearts + * Three of Diamonds + * Nine of Diamonds + * + * Tommy has the below cards in their hand: + * King of Hearts + * Six of Diamonds + * Ace of Clubs + * Queen of Spades + * Two of Hearts + */ + public static void main(String[] args) { + Deck deck = Deck.generate(); + Dealer dealer = new Dealer(deck); + + dealer.shuffleDeck(); + + Player playerOne = new Player("Nick"); + playerOne.replaceHand(dealer.dealCards(5)); + + Player playerTwo = new Player("Tommy"); + playerTwo.replaceHand(dealer.dealCards(5)); + + printPlayersHand(playerOne); + printPlayersHand(playerTwo); + } + + private static void printPlayersHand(Player player) { + System.out.println(player.getName() + " has the below cards in their hand:"); + for (Card card : player.getHand()) { + System.out.println(" " + card.getDisplayText()); + } + System.out.print("\n"); + } +} diff --git a/src/main/java/com/example/main/model/Card.java b/src/main/java/com/example/main/model/Card.java new file mode 100644 index 0000000..93fc3b6 --- /dev/null +++ b/src/main/java/com/example/main/model/Card.java @@ -0,0 +1,40 @@ +package com.example.main.model; + +public class Card { + + public Card(String suit, String faceValue) { + + } + + /** + * Returns the suit of the card + * + * Ex: Hearts + * + * @return String + */ + public String getSuit() { + + } + + /** + * Returns the face value of the card + * + * Ex: King + * @return String + */ + public String getFaceValue() { + + } + + /** + * Returns the human readable string representation of the card. + * + * Ex: King of Hearts + * + * @return String + */ + public String getDisplayText() { + + } +} diff --git a/src/main/java/com/example/main/model/Dealer.java b/src/main/java/com/example/main/model/Dealer.java new file mode 100644 index 0000000..11c753c --- /dev/null +++ b/src/main/java/com/example/main/model/Dealer.java @@ -0,0 +1,34 @@ +package com.example.main.model; + +import java.util.List; + +public class Dealer { + + public Dealer(Deck deck) { + + } + + /** + * Shuffles the dealers deck. + */ + public void shuffleDeck() { + + } + + /** + * Retrieves the deck. + * @return Deck + */ + public Deck getDeck() { + + } + + /** + * Returns a list of cards from the dealers deck. + * @param numberOfCards the number of cards to include in the dealt cards list. + * @return List + */ + public List dealCards(int numberOfCards) { + + } +} diff --git a/src/main/java/com/example/main/model/Deck.java b/src/main/java/com/example/main/model/Deck.java new file mode 100644 index 0000000..7ae976e --- /dev/null +++ b/src/main/java/com/example/main/model/Deck.java @@ -0,0 +1,54 @@ +package com.example.main.model; + +import java.util.Stack; + +public class Deck { + + /** + * Generates a Deck. + * @return Deck + */ + public static Deck generate() { + + } + + /** + * Adds the given card to the deck. + * @return void + */ + public void addCard(Card card) { + + } + + /** + * Retrieves the next card from the Deck. + * @return + */ + public Card getNext() { + + } + + /** + * Returns the number of cards in the deck. + * @return int + */ + public int size() { + + } + + /** + * "Peeks" the top card in the deck without removing the card from the deck. + * @return Card + */ + public Card peekCard() { + + } + + /** + * Returns the cards in the deck. + * @return Stack + */ + public Stack getCards() { + + } +} diff --git a/src/main/java/com/example/main/model/Player.java b/src/main/java/com/example/main/model/Player.java new file mode 100644 index 0000000..f294af8 --- /dev/null +++ b/src/main/java/com/example/main/model/Player.java @@ -0,0 +1,46 @@ +package com.example.main.model; + +import java.util.List; + +public class Player { + + /** + * Create a player given a name. + * @param name + */ + public Player(String name) { + + } + + /** + * Adds a card to the players hand. + * @param card + */ + public void addCardToHand(Card card) { + + } + + /** + * Returns the list of cards in the players hand. + * @return + */ + public List getHand() { + + } + + /** + * Replaces the players hand with a new list of cards. + * @param newHand + */ + public void replaceHand(List newHand) { + + } + + /** + * Returns the players name; + * @return + */ + public String getName() { + + } +} diff --git a/src/test/java/com/example/main/model/CardTest.java b/src/test/java/com/example/main/model/CardTest.java new file mode 100644 index 0000000..47b2206 --- /dev/null +++ b/src/test/java/com/example/main/model/CardTest.java @@ -0,0 +1,5 @@ +package com.example.main.model; + +public class CardTest { + +} diff --git a/src/test/java/com/example/main/model/DealerTest.java b/src/test/java/com/example/main/model/DealerTest.java new file mode 100644 index 0000000..f7a3ef6 --- /dev/null +++ b/src/test/java/com/example/main/model/DealerTest.java @@ -0,0 +1,5 @@ +package com.example.main.model; + +class DealerTest { + +} diff --git a/src/test/java/com/example/main/model/DeckTest.java b/src/test/java/com/example/main/model/DeckTest.java new file mode 100644 index 0000000..f606add --- /dev/null +++ b/src/test/java/com/example/main/model/DeckTest.java @@ -0,0 +1,5 @@ +package com.example.main.model; + +class DeckTest { + +} diff --git a/src/test/java/com/example/main/model/PlayerTest.java b/src/test/java/com/example/main/model/PlayerTest.java new file mode 100644 index 0000000..66fbbfe --- /dev/null +++ b/src/test/java/com/example/main/model/PlayerTest.java @@ -0,0 +1,5 @@ +package com.example.main.model; + +class PlayerTest { + +}