-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 178dcce
Showing
19 changed files
with
798 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Crazy Card Game | ||
|
||
Assignment documentation is here: https://courses.grainger.illinois.edu/cs126/fa2019/assignments/crazy-cardgame/ | ||
|
||
Good luck! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> | ||
<output url="file://$MODULE_DIR$/target/classes" /> | ||
<output-test url="file://$MODULE_DIR$/target/test-classes" /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | ||
<excludeFolder url="file://$MODULE_DIR$/target" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.5" level="project" /> | ||
<orderEntry type="library" name="Maven: commons-io:commons-io:2.6" level="project" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: com.github.stefanbirkner:system-rules:1.19.0" level="project" /> | ||
</component> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>uiuc126</groupId> | ||
<artifactId>crazy-cardgame</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>2.8.5</version> | ||
</dependency> | ||
<!-- https://commons.apache.org/proper/commons-io/ --> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<version>2.6</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- https://stefanbirkner.github.io/system-rules/index.html --> | ||
<dependency> | ||
<groupId>com.github.stefanbirkner</groupId> | ||
<artifactId>system-rules</artifactId> | ||
<version>1.19.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>8</source> | ||
<target>8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package cardgame; | ||
|
||
import java.util.ArrayList; | ||
import java.util.EnumSet; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/* | ||
* ======================================== | ||
* You should not need to modify this file. | ||
* ======================================== | ||
*/ | ||
|
||
/** | ||
* Represents a standard playing card from a 52 card deck. | ||
*/ | ||
public class Card { | ||
|
||
public enum Suit {DIAMONDS, HEARTS, SPADES, CLUBS} | ||
|
||
public enum Rank { | ||
ACE, | ||
TWO, | ||
THREE, | ||
FOUR, | ||
FIVE, | ||
SIX, | ||
SEVEN, | ||
EIGHT, | ||
NINE, | ||
TEN, | ||
JACK, | ||
QUEEN, | ||
KING | ||
} | ||
|
||
private static final int FACE_CARD_VALUE = 10; | ||
private static final int EIGHT_CARD_VALUE = 50; | ||
|
||
private static final int DECK_SIZE = Suit.values().length * Rank.values().length; | ||
|
||
private Suit suit; | ||
private Rank rank; | ||
|
||
public Card(Suit suit, Rank rank) { | ||
this.suit = suit; | ||
this.rank = rank; | ||
} | ||
|
||
public Suit getSuit() { | ||
return suit; | ||
} | ||
|
||
public Rank getRank() { | ||
return rank; | ||
} | ||
|
||
/** | ||
* Returns the Crazy8s point value for this card. | ||
* | ||
* @return An integer representing this card's point value | ||
*/ | ||
public int getPointValue() { | ||
if (rank.ordinal() >= Rank.JACK.ordinal()) { | ||
return FACE_CARD_VALUE; | ||
} | ||
|
||
if (rank == Rank.EIGHT) { | ||
return EIGHT_CARD_VALUE; | ||
} | ||
|
||
// Otherwise, return numeric value of card | ||
return rank.ordinal() + 1; | ||
} | ||
|
||
/** | ||
* Creates a new, unshuffled deck of standard playing cards. | ||
* | ||
* @return A list representing an unshuffled deck of cards | ||
*/ | ||
public static List<Card> getDeck() { | ||
List<Card> cardDeck = new ArrayList<>(DECK_SIZE); | ||
|
||
for (Suit suit : EnumSet.allOf(Suit.class)) { | ||
for (Rank rank : EnumSet.allOf(Rank.class)) { | ||
cardDeck.add(new Card(suit, rank)); | ||
} | ||
} | ||
|
||
return cardDeck; | ||
} | ||
|
||
// Convenience methods; you might or might not need these. | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
Card card = (Card) o; | ||
return suit == card.suit && | ||
rank == card.rank; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(suit, rank); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package cardgame; | ||
|
||
import java.util.*; | ||
|
||
import cardgame.Card.Rank; | ||
|
||
public class Play { | ||
public static void main(String[] args) { | ||
Play o = new Play(); | ||
Player1 dharshan = new Player1(); | ||
Player2 sherin = new Player2(); | ||
List<Card> deck = new ArrayList<>(); | ||
deck = Card.getDeck(); | ||
Collections.shuffle(deck); | ||
deck = o.start(deck, dharshan, sherin); | ||
o.play(deck, dharshan, sherin); | ||
} | ||
|
||
List<Card> start(List<Card> deck, Player1 dharshan, Player2 sherin) { | ||
int i; | ||
List<Card> player1 = new ArrayList<>(); | ||
List<Card> player2 = new ArrayList<>(); | ||
for (i = 0; i < 14; i++) { | ||
if (i % 2 == 0) { | ||
player2.add(deck.get(0)); | ||
} else { | ||
player1.add(deck.get(0)); | ||
} | ||
deck.remove(0); | ||
} | ||
System.out.println(); | ||
System.out.println("Card of Player1: "); | ||
for (i = 0; i < player1.size(); i++) { | ||
System.out.println(player1.get(i).getRank() + " " + player1.get(i).getSuit() + " "); | ||
} | ||
System.out.println("Card of Player2: "); | ||
for (i = 0; i < player2.size(); i++) { | ||
System.out.println(player2.get(i).getRank() + " " + player2.get(i).getSuit() + " "); | ||
} | ||
System.out.println(); | ||
dharshan.receiveInitialCards(player1); | ||
sherin.receiveInitialCards(player2); | ||
return deck; | ||
} | ||
|
||
void play(List<Card> deck, Player1 dharshan, Player2 sherin) { | ||
Play o = new Play(); | ||
int score1 = 0, i, score2 = 0; | ||
Card topCard; | ||
topCard = deck.get(0); | ||
deck.remove(0); | ||
System.out.println("Top Card : " + topCard.getRank() + " " + topCard.getSuit()); | ||
Card.Suit decCard = null; | ||
while (score1 < 200 && score2 < 200) { | ||
for (i = 0; i < 3; i++) { | ||
if (sherin.shouldDrawCard(topCard, decCard)) { | ||
if (deck.size() != 0) { | ||
sherin.receiveCard(deck.get(0)); | ||
deck.remove(0); | ||
} | ||
} else { | ||
topCard = sherin.playCard(); | ||
System.out.println("Top Card : " + topCard.getRank() + " " + topCard.getSuit()); | ||
if (topCard.getRank() == Rank.EIGHT && sherin.myCards.size() != 0) { | ||
decCard = sherin.declareSuit(); | ||
} | ||
break; | ||
} | ||
} | ||
for (i = 0; i < 3; i++) { | ||
if (dharshan.shouldDrawCard(topCard, decCard)) { | ||
if (deck.size() != 0) { | ||
dharshan.receiveCard(deck.get(0)); | ||
deck.remove(0); | ||
} | ||
} else { | ||
topCard = dharshan.playCard(); | ||
System.out.println("Top Card : " + topCard.getRank() + " " + topCard.getSuit()); | ||
if (topCard.getRank() == Rank.EIGHT && sherin.myCards.size() != 0) { | ||
decCard = dharshan.declareSuit(); | ||
} | ||
break; | ||
} | ||
} | ||
if (dharshan.myCards.size() == 0 || deck.size() == 0) { | ||
score2 += sherin.getScore(); | ||
System.out.println("Score of Player 1 : " + score2); | ||
} | ||
if (sherin.myCards.size() == 0 || deck.size() == 0) { | ||
score1 += dharshan.getScore(); | ||
System.out.println("Score of Player 2 : " + score1); | ||
} | ||
if (deck.size() == 0 && score1 < 200 && score2 < 200) { | ||
deck = Card.getDeck(); | ||
Collections.shuffle(deck); | ||
deck = o.start(deck, dharshan, sherin); | ||
} | ||
} | ||
o.results(score1, score2); | ||
} | ||
|
||
void results(int s1, int s2) { | ||
if (s1 >= 200) { | ||
System.out.println("Winnner is sherin"); | ||
} else { | ||
System.out.println("Winnner is Dharshan"); | ||
} | ||
} | ||
} |
Oops, something went wrong.