parent
a81c0d2cdb
commit
b12c95ab88
@ -0,0 +1,106 @@
|
|||||||
|
# Created by .ignore support plugin (hsz.mobi)
|
||||||
|
### Java template
|
||||||
|
# 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*
|
||||||
|
|
||||||
|
### JetBrains template
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# Gradle and Maven with auto-import
|
||||||
|
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||||
|
# since they will be recreated, and may cause churn. Uncomment if using
|
||||||
|
# auto-import.
|
||||||
|
# .idea/artifacts
|
||||||
|
# .idea/compiler.xml
|
||||||
|
# .idea/jarRepositories.xml
|
||||||
|
# .idea/modules.xml
|
||||||
|
# .idea/*.iml
|
||||||
|
# .idea/modules
|
||||||
|
# *.iml
|
||||||
|
# *.ipr
|
||||||
|
|
||||||
|
# CMake
|
||||||
|
cmake-build-*/
|
||||||
|
|
||||||
|
# Mongo Explorer plugin
|
||||||
|
.idea/**/mongoSettings.xml
|
||||||
|
|
||||||
|
# File-based project format
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Cursive Clojure plugin
|
||||||
|
.idea/replstate.xml
|
||||||
|
|
||||||
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
|
com_crashlytics_export_strings.xml
|
||||||
|
crashlytics.properties
|
||||||
|
crashlytics-build.properties
|
||||||
|
fabric.properties
|
||||||
|
|
||||||
|
# Editor-based Rest Client
|
||||||
|
.idea/httpRequests
|
||||||
|
|
||||||
|
# Android studio 3.1+ serialized cache file
|
||||||
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|
||||||
|
.idea/.gitignore
|
||||||
|
.idea/description.html
|
||||||
|
.idea/encodings.xml
|
||||||
|
.idea/misc.xml
|
||||||
|
.idea/modules.xml
|
||||||
|
.idea/project-template.xml
|
||||||
|
.idea/vcs.xml
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="module-library">
|
||||||
|
<library name="JUnit5.4">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$MODULE_DIR$/lib/junit-jupiter-5.4.2.jar!/" />
|
||||||
|
<root url="jar://$MODULE_DIR$/lib/junit-jupiter-api-5.4.2.jar!/" />
|
||||||
|
<root url="jar://$MODULE_DIR$/lib/apiguardian-api-1.0.0.jar!/" />
|
||||||
|
<root url="jar://$MODULE_DIR$/lib/opentest4j-1.1.1.jar!/" />
|
||||||
|
<root url="jar://$MODULE_DIR$/lib/junit-platform-commons-1.4.2.jar!/" />
|
||||||
|
<root url="jar://$MODULE_DIR$/lib/junit-jupiter-params-5.4.2.jar!/" />
|
||||||
|
<root url="jar://$MODULE_DIR$/lib/junit-jupiter-engine-5.4.2.jar!/" />
|
||||||
|
<root url="jar://$MODULE_DIR$/lib/junit-platform-engine-1.4.2.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</orderEntry>
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
public class Card {
|
||||||
|
int number;
|
||||||
|
Suit suit;
|
||||||
|
|
||||||
|
public Card(int number, Suit suit) {
|
||||||
|
this.number = number;
|
||||||
|
this.suit = suit;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class CardGame {
|
||||||
|
public Player[] players;
|
||||||
|
ArrayList<Card> Pot;
|
||||||
|
Card[] draws;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param numberOfCards
|
||||||
|
* @param numberOfPlayers
|
||||||
|
*/
|
||||||
|
public CardGame(int numberOfCards, int numberOfPlayers) {
|
||||||
|
Pile deck = createDeck(10);
|
||||||
|
this.players = new Player[numberOfPlayers];
|
||||||
|
draws = new Card[numberOfPlayers];
|
||||||
|
for (int i = 0; i < numberOfPlayers; i++) {
|
||||||
|
players[i] = new Player(deck.getCardsForPlayer(numberOfPlayers));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Pile createDeck(int numberOfCards) {
|
||||||
|
Pile deck = new Pile();
|
||||||
|
for (int number = 0; number < numberOfCards * Suit.COUNT; number++) {
|
||||||
|
for (int suit = 0; suit < Suit.COUNT; suit++) {
|
||||||
|
deck.add(new Card(number + 1, new Suit(suit)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deck;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void play() {
|
||||||
|
while (noWinner()) {
|
||||||
|
round();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void round() {
|
||||||
|
for (int i = 0; i < draws.length; i++) {
|
||||||
|
if (!players[i].broke()) {
|
||||||
|
draws[i] = players[i].draw();
|
||||||
|
System.out.printf("Player %i (%i cards): %i", i, players[i].count(), draws[i].number);
|
||||||
|
Pot.add(draws[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int winner = getWinner(draws);
|
||||||
|
players[winner].addPot(draws);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getWinner(Card[] drawn) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean noWinner() {
|
||||||
|
int notBroke = 0;
|
||||||
|
for (int i = 0; i < players.length; i++) {
|
||||||
|
if (players[i].broke()) {
|
||||||
|
notBroke++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return notBroke > 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class CardGameTest {
|
||||||
|
|
||||||
|
@org.junit.jupiter.api.Test
|
||||||
|
void play() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
public class Main {
|
||||||
|
enum Suits {
|
||||||
|
CLUBS,
|
||||||
|
SPADES,
|
||||||
|
HEARTS,
|
||||||
|
DIAMONDS
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Card Game");
|
||||||
|
CardGame cardGame = new CardGame(10, 2);
|
||||||
|
cardGame.play();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
public class NoMoreCardsException extends RuntimeException {
|
||||||
|
}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class Pile {
|
||||||
|
ArrayList<Card> pile = new ArrayList<Card>();
|
||||||
|
|
||||||
|
public Boolean isEmpty() {
|
||||||
|
return pile.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void shuffle() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void takeDiscarded() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAll(Card[] cards) {
|
||||||
|
for(Card card: cards)
|
||||||
|
pile.add(card);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int count() {
|
||||||
|
return pile.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pile getCardsForPlayer(int numberOfPlayers) {
|
||||||
|
Pile cardsForPlayer = new Pile();
|
||||||
|
for (int i = 0; i < pile.size() / numberOfPlayers; i++) {
|
||||||
|
cardsForPlayer.add(pile.get(0));
|
||||||
|
pile.remove(0);
|
||||||
|
}
|
||||||
|
return cardsForPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Card card) {
|
||||||
|
pile.add(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,48 @@
|
|||||||
|
public class Player {
|
||||||
|
Pile drawPile;
|
||||||
|
Pile discardPile;
|
||||||
|
|
||||||
|
public Player(Pile drawPile) {
|
||||||
|
this.drawPile = drawPile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pile getDrawPile() {
|
||||||
|
return drawPile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pile getDiscardPile() {
|
||||||
|
return discardPile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDrawPile(Pile drawPile) {
|
||||||
|
this.drawPile = drawPile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDiscardPile(Pile discardPile) {
|
||||||
|
this.discardPile = discardPile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Card draw() throws NoMoreCardsException {
|
||||||
|
if (getDrawPile().isEmpty()) {
|
||||||
|
if (getDiscardPile().isEmpty()) {
|
||||||
|
throw new NoMoreCardsException();
|
||||||
|
}
|
||||||
|
discardPile.shuffle();
|
||||||
|
drawPile.takeDiscarded();
|
||||||
|
}
|
||||||
|
Card draw = new Card(1, new Suit(Suit.SPADES));
|
||||||
|
return draw;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean broke() {
|
||||||
|
return drawPile.isEmpty() && discardPile.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPot(Card[] draws) {
|
||||||
|
discardPile.addAll(draws);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int count() {
|
||||||
|
return drawPile.count() + discardPile.count();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
public class Suit {
|
||||||
|
int suit;
|
||||||
|
// public static Suit SPADES;
|
||||||
|
public static final int CLUBS = 0;
|
||||||
|
public static final int SPADES = 1;
|
||||||
|
public static final int HEARTS = 2;
|
||||||
|
public static final int DIAMONDS = 3;
|
||||||
|
public static final int COUNT = 4;
|
||||||
|
|
||||||
|
public Suit(int suit) {
|
||||||
|
this.suit = suit;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in new issue