Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path=""/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path=""/>
</classpath>
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/Card$1.class
/Card.class
/ComputerPlayer.class
/CreateDeck.class
/Deck.class
/Driver.class
/GUI$1.class
/GUI$2.class
/GUI.class
/Game.class
/Hand.class
/Player.class
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>CardGame</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
78 changes: 0 additions & 78 deletions Card.java

This file was deleted.

15 changes: 15 additions & 0 deletions CardGame/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/Player.class
/Hand.class
/GUI.class
/GUI$1.class
/GUI$2.class
/Game.class
/Driver.class
/Deck.class
/CreateDeck.class
/ComputerPlayer.class
/Card$1.class
/Card.class
/DeckDealer.class
/Suit.class
/Rank.class
41 changes: 41 additions & 0 deletions CardGame/Card.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* author : alex Torres
* this class is the card class that will hold the suit, value and image of the card.
* this class contains a comparator that will compare the values of 2 cards
*
*/
package CardGame;

import java.util.Comparator;

import javax.swing.ImageIcon;

public class Card {
private final Suit suit;
private final Rank rank;
private final ImageIcon cardImage;
public Card(Suit suit, Rank rank, ImageIcon image) {
this.suit = suit;
this.rank = rank;
this.cardImage = image;
}
public Suit getSuit() {
return suit;
}
public Rank getRank() {
return rank;
}
public ImageIcon getImage() {
return cardImage;
}
public static Comparator<Card> compareByValue = new Comparator<Card>() {
@Override
public int compare(Card o1, Card o2) {
return o1.getRank().getValue() - o2.getRank().getValue();
}
};
@Override
public String toString() {
return rank + " of " + suit + "\n";
}
}
1 change: 1 addition & 0 deletions ComputerPlayer.java → CardGame/ComputerPlayer.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package CardGame;
import java.util.Random;

/*
Expand Down
38 changes: 38 additions & 0 deletions CardGame/CreateDeck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* author Kenji Lor
* this class will create all 53 cards
* the cards will then be put into a deck.
*/
package CardGame;

import javax.swing.ImageIcon;

//this class has a static method that will return a deck of 53 cards
public class CreateDeck {
public static Deck fullDeck() {
Deck deck = new Deck();

// Agregar cartas para cada palo
addSuitToDeck(deck, Card.hearts, "H");
addSuitToDeck(deck, Card.diamonds, "D");
addSuitToDeck(deck, Card.spade, "S");
addSuitToDeck(deck, Card.club, "C");

// Agregar Joker
deck.addCard(new Card("joker", Card.joker, new ImageIcon("FolderOfCards/joker.png")));

return deck;
}

private static void addSuitToDeck(Deck deck, String suit, String suitAbbreviation) {
String[] rankNames = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
int[] ranks = {Card.ace, Card.two, Card.three, Card.four, Card.five, Card.six,
Card.seven, Card.eight, Card.nine, Card.ten, Card.jack, Card.queen, Card.king};

for (int i = 0; i < ranks.length; i++) {
String fileName = "FolderOfCards/" + rankNames[i] + suitAbbreviation + ".png";
deck.addCard(new Card(suit, ranks[i], new ImageIcon(fileName)));
}
}

}
33 changes: 33 additions & 0 deletions CardGame/Deck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Author: alex torres
* this class will store a deck of cards. this class has an array list that will store a deck of cards.
*/
package CardGame;

import java.util.ArrayList;
import java.util.Collections;

public class Deck {
private ArrayList<Card> deck;

public Deck() {
deck = new ArrayList<Card>(53);
}

public void addCard(Card card) {
deck.add(card);
}

public void shuffleDeck() {
Collections.shuffle(deck);
}

public ArrayList<Card> getDeck() {
return deck;
}

@Override
public String toString() {
return deck.toString();
}
}
22 changes: 22 additions & 0 deletions CardGame/DeckDealer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package CardGame;

import java.util.ArrayList;

public class DeckDealer {

public ArrayList<Card> dealFirstHalf(Deck deck) {
ArrayList<Card> firstHalf = new ArrayList<>();
for (int i = 0; i < 26; i++) {
firstHalf.add(deck.getDeck().get(i));
}
return firstHalf;
}

public ArrayList<Card> dealSecondHalf(Deck deck) {
ArrayList<Card> secondHalf = new ArrayList<>();
for (int i = 26; i < 53; i++) {
secondHalf.add(deck.getDeck().get(i));
}
return secondHalf;
}
}
1 change: 1 addition & 0 deletions Driver.java → CardGame/Driver.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package CardGame;
import java.util.Scanner;

//author alex torres
Expand Down
4 changes: 3 additions & 1 deletion GUI.java → CardGame/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* author chris Lara-Betancourt
*
*/
package CardGame;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;
Expand Down Expand Up @@ -111,7 +113,7 @@ public void actionPerformed(ActionEvent e) {
}

public static void main (String[] args) {
Gui g = new GUI();
GUI g = new GUI();

}

Expand Down
16 changes: 10 additions & 6 deletions Game.java → CardGame/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* this is the games class that will run the game. this class will create the deck, player, and hand. this class
* will also will run each step of the game
*/
package CardGame;

public class Game {

//deck of cards
Expand Down Expand Up @@ -38,12 +40,14 @@ public void gameSetup() {
//shuffle deck
deck.shuffleDeck();

//create hands
//hand for player. half the deck is delt
playerHand = new Hand( deck.dealFirstHalf());

//hand for computer player. second half is delt
computerHand = new Hand( deck.dealSecondhalf());
// Instancia de DeckDealer para manejar la distribución del mazo
DeckDealer dealer = new DeckDealer();

// Crear la mano del jugador usando la primera mitad del mazo
playerHand = new Hand(dealer.dealFirstHalf(deck));

// Crear la mano del jugador de computadora usando la segunda mitad del mazo
computerHand = new Hand(dealer.dealSecondHalf(deck));

//add hand to players

Expand Down
1 change: 1 addition & 0 deletions Hand.java → CardGame/Hand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* this class is the hand class that will hold the cards of each player
* this class has array list that will hold all the card
*/
package CardGame;

import java.util.ArrayList;
import java.util.Collections;
Expand Down
2 changes: 2 additions & 0 deletions Player.java → CardGame/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* author: alex torres
* this class is the player class. this player class has a hand that will store cards.
*/
package CardGame;

public class Player {
//hand of player that will holds the cards
private Hand hand;
Expand Down
29 changes: 29 additions & 0 deletions CardGame/Rank.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package CardGame;

public enum Rank {
ACE(1),
TWO(2),
THREE(3),
FOUR(4),
FIVE(5),
SIX(6),
SEVEN(7),
EIGHT(8),
NINE(9),
TEN(10),
JACK(11),
QUEEN(12),
KING(13),
JOKER(14);
private final int value;
Rank(int value) {
this.value = value;
}
public int getValue() {
return value;
}
@Override
public String toString() {
return String.valueOf(value);
}
}
19 changes: 19 additions & 0 deletions CardGame/Suit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package CardGame;

public enum Suit {
HEARTS("hearts"),
DIAMONDS("diamonds"),
SPADES("spades"),
CLUBS("clubs");

private final String name;

Suit(String name) {
this.name = name;
}

@Override
public String toString() {
return name;
}
}
Loading