-
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.
Merge pull request #12 from Spindler-ICS4UC-1-1819/angela
Angela
- Loading branch information
Showing
48 changed files
with
1,773 additions
and
683 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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,87 @@ | ||
package egyptianWar; | ||
|
||
/** | ||
* @author Angela Zhou | ||
* Date: Jan 2019 | ||
* Course: ICS4U | ||
* Teacher: Mrs. Spindler | ||
* Card.java | ||
*/ | ||
import javafx.scene.image.Image; | ||
|
||
public class Card { | ||
|
||
private final char value; | ||
private final char suit; | ||
|
||
public Card(String name) { | ||
value = name.charAt(0); // first char gives the name | ||
suit = name.charAt(1); // second char gives the suit | ||
} | ||
|
||
public Card() { // default constructor shows back of card | ||
this("XX"); | ||
} | ||
|
||
public Image getCardImage() { | ||
return new Image(getClass().getResource("/CARDS/" + value + suit + ".jpg").toString()); | ||
} | ||
|
||
public String toString() { | ||
|
||
String returnValue = ""; | ||
|
||
// get the name of the card for display purposes | ||
if (Character.isDigit(value)) returnValue = Character.toString(value); // card value 2 - 9 | ||
else if (value == 'T') returnValue = "10"; // card value 10 | ||
else if (value == 'J') returnValue = "Jack"; | ||
else if (value == 'Q') returnValue = "Queen"; | ||
else if (value == 'K') returnValue = "King"; | ||
else if (value == 'A') returnValue = "Ace"; | ||
|
||
switch (suit) { | ||
case 'S': returnValue += " of Spades"; break; | ||
case 'H': returnValue += " of Hearts"; break; | ||
case 'D': returnValue += " of Diamonds"; break; | ||
case 'C': returnValue += " of Clubs"; break; | ||
} | ||
|
||
return returnValue; | ||
} | ||
|
||
public int getIntValue() { | ||
|
||
int intValue = 0; | ||
|
||
// get the value of the card for comparison | ||
if (Character.isDigit(value)) { // card value 2 - 9 | ||
intValue = Character.getNumericValue(value); | ||
} else if (value == 'T') { // card value 10 | ||
intValue = 10; | ||
} else if (value == 'J') { | ||
intValue = 11; | ||
} else if (value == 'Q') { | ||
intValue = 12; | ||
} else if (value == 'K') { | ||
intValue = 13; | ||
} else if (value == 'A') { | ||
intValue = 14; | ||
} | ||
return intValue; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
// check if object is a card | ||
if (!(obj instanceof Card)) { | ||
return false; | ||
} | ||
|
||
// return the boolean value | ||
// of the comparison b/w card strings | ||
Card temp = (Card)obj; | ||
return temp.toString().equals(this.toString()); | ||
|
||
} | ||
|
||
} |
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,80 @@ | ||
package egyptianWar; | ||
|
||
/** | ||
* @author Angela Zhou | ||
* Date: Jan 2019 | ||
* Course: ICS4U | ||
* Teacher: Mrs. Spindler | ||
* Deck.java | ||
*/ | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
public class Deck { | ||
|
||
// 1st char is the name (T = 10, J = 11, Q = 12, K = 13, A = 14) | ||
// 2nd char is the suit | ||
final static private String[] CARDS = { | ||
"2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "TC", "JC", "QC", "KC", "AC", | ||
"2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "TD", "JD", "QD", "KD", "AD", | ||
"2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "TH", "JH", "QH", "KH", "AH", | ||
"2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "TS", "JS", "QS", "KS", "AS" }; | ||
|
||
private ArrayList<String> deck; | ||
|
||
private ArrayList<String> discardDeck; | ||
|
||
public Deck() { | ||
// create ArrayList from the deck | ||
deck = new ArrayList<String>(Arrays.asList(CARDS)); | ||
} | ||
|
||
/** | ||
* gets the next card from the deck | ||
* returns null if the deck is empty | ||
**/ | ||
public Card dealNextCard() { | ||
Card dealtCard; | ||
|
||
int cardsLeft = deck.size(); | ||
|
||
// select a random card from the remaining cards | ||
int newCardIndex = (int) (cardsLeft * Math.random()); | ||
|
||
// get the name of the card and make a new card from it | ||
dealtCard = new Card(deck.get(newCardIndex)); | ||
|
||
// remove it from the deck | ||
deck.remove(newCardIndex); | ||
|
||
return dealtCard; | ||
} | ||
|
||
/** | ||
* discards a card into a separate array | ||
**/ | ||
public void discardCard(String card, ArrayList<String> hand) { | ||
// remove card from hand | ||
hand.remove(card); | ||
|
||
// add the card to the discard pile | ||
discardDeck.add(card); | ||
} | ||
|
||
/** | ||
* combines all the cards to later be dealt | ||
* dealing is random; true "shuffling" is done as the cards are dealt | ||
*/ | ||
public void shuffle() { | ||
// add all the cards in the discard pile | ||
deck.addAll(discardDeck); | ||
} | ||
|
||
/** | ||
* clears the deck then adds all the cards back in | ||
*/ | ||
public void reset() { | ||
deck.clear(); | ||
deck.addAll(Arrays.asList(CARDS)); | ||
} | ||
} |
Oops, something went wrong.